### Added an example of Lanczos weights

parent 319c42f0
lanczos_wgts.py 0 → 100644
 """ 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__ = "BSD-3.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()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment