scipy.signal.windows.

lanczos#

scipy.signal.windows.lanczos(M, *, sym=True)[源代码]#

返回兰索斯窗,也称为 sinc 窗。

参数:
Mint

输出窗口中的点数。如果为零,则返回空数组。当为负数时会抛出异常。

symbool, 可选

当为 True(默认值)时,生成一个对称窗口,用于滤波器设计。当为 False 时,生成一个周期性窗口,用于频谱分析。

返回:
wndarray

窗口,最大值归一化为 1(但如果 M 为偶数且 sym 为 True,则不会出现值 1)。

说明

兰索斯窗定义为

\[w(n) = sinc \left( \frac{2n}{M - 1} - 1 \right)\]

其中

\[sinc(x) = \frac{\sin(\pi x)}{\pi x}\]

兰索斯窗减少了吉布斯振荡,并且广泛用于过滤气候时间序列,在物理和频谱域中具有良好的特性。

在 1.10 版本中添加。

参考文献

[1]

Lanczos, C., and Teichmann, T. (1957). Applied analysis. Physics Today, 10, 44.

[2]

Duchon C. E. (1979) Lanczos Filtering in One and Two Dimensions. Journal of Applied Meteorology, Vol 18, pp 1016-1022.

[3]

Thomson, R. E. and Emery, W. J. (2014) Data Analysis Methods in Physical Oceanography (Third Edition), Elsevier, pp 593-637.

[4]

Wikipedia, “Window function”, http://en.wikipedia.org/wiki/Window_function

示例

绘制窗口

>>> import numpy as np
>>> from scipy.signal.windows import lanczos
>>> from scipy.fft import fft, fftshift
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1)
>>> window = lanczos(51)
>>> ax.plot(window)
>>> ax.set_title("Lanczos window")
>>> ax.set_ylabel("Amplitude")
>>> ax.set_xlabel("Sample")
>>> fig.tight_layout()
>>> plt.show()
../../_images/scipy-signal-windows-lanczos-1_00_00.png

及其频率响应

>>> fig, ax = plt.subplots(1)
>>> A = fft(window, 2048) / (len(window)/2.0)
>>> freq = np.linspace(-0.5, 0.5, len(A))
>>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
>>> ax.plot(freq, response)
>>> ax.set_xlim(-0.5, 0.5)
>>> ax.set_ylim(-120, 0)
>>> ax.set_title("Frequency response of the lanczos window")
>>> ax.set_ylabel("Normalized magnitude [dB]")
>>> ax.set_xlabel("Normalized frequency [cycles per sample]")
>>> fig.tight_layout()
>>> plt.show()
../../_images/scipy-signal-windows-lanczos-1_01_00.png