Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Carl Schreck
pyexamples
Commits
d1892677
Commit
d1892677
authored
Jun 15, 2020
by
Carl Schreck
Browse files
Added an example of Lanczos weights
parent
319c42f0
Changes
1
Hide whitespace changes
Inline
Sidebyside
lanczos_wgts.py
0 → 100644
View file @
d1892677
""" Draw a set of Lanczos Weights based on
https://scitools.org.uk/iris/docs/v1.2/examples/graphics/SOI_filtering.html
"""
__author__
=
"Carl Schreck"
__email__
=
"cjschrec@ncsu.edu"
__copyright__
=
"Copyright 2020, North Carolina State University"
__license__
=
"BSD3.0"
import
numpy
as
np
import
matplotlib.pyplot
as
plt
def
low_pass_weights
(
window
,
cutoff
):
"""Calculate weights for a low pass Lanczos filter.
Args:
window: int
The length of the filter window.
cutoff: float
The cutoff frequency in inverse time steps.
"""
order
=
((
window

1
)
//
2
)
+
1
nwts
=
2
*
order
+
1
w
=
np
.
zeros
([
nwts
])
n
=
nwts
//
2
w
[
n
]
=
2
*
cutoff
k
=
np
.
arange
(
1.
,
n
)
sigma
=
np
.
sin
(
np
.
pi
*
k
/
n
)
*
n
/
(
np
.
pi
*
k
)
firstfactor
=
np
.
sin
(
2.
*
np
.
pi
*
cutoff
*
k
)
/
(
np
.
pi
*
k
)
w
[
n

1
:
0
:

1
]
=
firstfactor
*
sigma
w
[
n
+
1
:

1
]
=
firstfactor
*
sigma
return
w
[
1
:

1
]
y
=
low_pass_weights
(
window
=
41
,
cutoff
=
0.10
)
x
=
np
.
arange
(

20
,
21
)
plt
.
plot
(
x
,
y
)
plt
.
savefig
(
'figures/lanczos_wgts.png'
)
plt
.
show
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment