Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wtlib
WindEnergyToolbox
Commits
e6316b1f
Commit
e6316b1f
authored
8 years ago
by
Mads M. Pedersen
Browse files
Options
Downloads
Patches
Plain Diff
added cy_filters.pyx + setup.py thing
parent
db573e63
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
setup.py
+2
-1
2 additions, 1 deletion
setup.py
wetb/signal_tools/filters/cy_filters.pyx
+59
-0
59 additions, 0 deletions
wetb/signal_tools/filters/cy_filters.pyx
with
61 additions
and
1 deletion
setup.py
+
2
−
1
View file @
e6316b1f
...
@@ -26,7 +26,8 @@ from Cython.Distutils import build_ext
...
@@ -26,7 +26,8 @@ from Cython.Distutils import build_ext
def
setup_package
():
def
setup_package
():
ex_info
=
[(
'
wetb.fatigue_tools.rainflowcounting
'
,
[
'
pair_range
'
,
'
peak_trough
'
,
'
rainflowcount_astm
'
])]
ex_info
=
[(
'
wetb.fatigue_tools.rainflowcounting
'
,
[
'
pair_range
'
,
'
peak_trough
'
,
'
rainflowcount_astm
'
]),
(
'
wetb.signal_tools.filters
'
,
[
'
cy_filters
'
])]
extlist
=
[
Extension
(
'
%s.%s
'
%
(
module
,
n
),
extlist
=
[
Extension
(
'
%s.%s
'
%
(
module
,
n
),
[
os
.
path
.
join
(
module
.
replace
(
"
.
"
,
"
/
"
),
n
)
+
'
.pyx
'
],
[
os
.
path
.
join
(
module
.
replace
(
"
.
"
,
"
/
"
),
n
)
+
'
.pyx
'
],
include_dirs
=
[
np
.
get_include
()])
for
module
,
names
in
ex_info
for
n
in
names
]
include_dirs
=
[
np
.
get_include
()])
for
module
,
names
in
ex_info
for
n
in
names
]
...
...
This diff is collapsed.
Click to expand it.
wetb/signal_tools/filters/cy_filters.pyx
0 → 100644
+
59
−
0
View file @
e6316b1f
import
cython
import
numpy
as
np
cimport
numpy
as
np
'''
Created on 29/05/2013
@author: Mads M. Pedersen (mmpe@dtu.dk)
'''
import
cython
import
numpy
as
np
cimport
numpy
as
np
@cython.ccall
@cython.locals
(
alpha
=
cython
.
float
,
i
=
cython
.
int
)
cpdef
cy_low_pass_filter
(
np
.
ndarray
[
double
,
ndim
=
1
]
inp
,
double
delta_t
,
double
tau
):
cdef
np
.
ndarray
[
double
,
ndim
=
1
]
output
output
=
np
.
empty_like
(
inp
,
dtype
=
np
.
float
)
output
[
0
]
=
inp
[
0
]
alpha
=
delta_t
/
(
tau
+
delta_t
)
for
i
in
range
(
1
,
inp
.
shape
[
0
]):
output
[
i
]
=
output
[
i
-
1
]
+
alpha
*
(
inp
[
i
]
-
output
[
i
-
1
])
# Same as output[i] = alpha*inp[i]+(1-alpha)*output[i-1]
return
output
cpdef
cy_dynamic_low_pass_filter
(
np
.
ndarray
[
double
,
ndim
=
1
]
inp
,
double
delta_t
,
np
.
ndarray
[
double
,
ndim
=
1
]
tau
,
int
method
):
cdef
np
.
ndarray
[
double
,
ndim
=
1
]
output
,
alpha
cdef
int
i
output
=
np
.
empty_like
(
inp
,
dtype
=
np
.
float
)
output
[
0
]
=
inp
[
0
]
if
method
==
1
:
alpha
=
delta_t
/
(
tau
+
delta_t
)
for
i
in
range
(
1
,
inp
.
shape
[
0
]):
output
[
i
]
=
output
[
i
-
1
]
+
alpha
[
i
]
*
(
inp
[
i
]
-
output
[
i
-
1
])
# Same as output[i] = alpha*inp[i]+(1-alpha)*output[i-1]
elif
method
==
2
:
for
i
in
range
(
1
,
inp
.
shape
[
0
]):
output
[
i
]
=
(
delta_t
*
(
inp
[
i
]
+
inp
[
i
-
1
]
-
output
[
i
-
1
])
+
2
*
tau
[
i
]
*
output
[
i
-
1
])
/
(
delta_t
+
2
*
tau
[
i
])
elif
method
==
3
:
for
i
in
range
(
1
,
inp
.
shape
[
0
]):
output
[
i
]
=
output
[
i
-
1
]
*
np
.
exp
(
-
delta_t
/
tau
[
i
])
+
inp
[
i
]
*
(
1
-
np
.
exp
(
-
delta_t
/
tau
[
i
]))
return
output
@cython.ccall
@cython.locals
(
alpha
=
cython
.
float
,
i
=
cython
.
int
)
cpdef
cy_high_pass_filter
(
np
.
ndarray
[
double
,
ndim
=
1
]
inp
,
double
delta_t
,
double
tau
):
cdef
np
.
ndarray
[
double
,
ndim
=
1
]
output
output
=
np
.
empty_like
(
inp
,
dtype
=
np
.
float
)
output
[
0
]
=
inp
[
0
]
alpha
=
tau
/
(
tau
+
delta_t
)
for
i
in
range
(
1
,
inp
.
shape
[
0
]):
output
[
i
]
=
alpha
*
(
output
[
i
-
1
]
+
inp
[
i
]
-
inp
[
i
-
1
])
return
output
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment