numpy.bartlett

numpy.bartlett(M)[源代码]

返回巴特利特窗口。

巴特利特窗与三角形窗非常相似,只是端点为零。它通常用于信号处理,使信号逐渐变细,而不会在频域产生太多的纹波。

参数
M利息

输出窗口中的点数。如果小于或等于零,则返回空数组。

返回
out数组

三角形窗口,最大值归一化为1(只有当样本数为奇数时才显示值1),第一个和最后一个样本等于零。

笔记

Bartlett窗口定义为

System Message: WARNING/2 (w(n)=\frac{2}{M-1}\左()

latex exited with error [stdout] This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2019/dev/Debian) (preloaded format=latex) restricted \write18 enabled. entering extended mode (./math.tex LaTeX2e <2018-12-01> (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls Document Class: article 2018/09/03 v1.4i Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo)) (/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/share/texlive/texmf-dist/tex/latex/amscls/amsthm.sty) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty)) (/usr/share/texlive/texmf-dist/tex/latex/anyfontsize/anyfontsize.sty) (/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) (./math.aux) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Undefined control sequence. <argument> ...gin {split}w(n)=\frac {2}{M-1}\� ��(\end {split} l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Package inputenc Error: Invalid UTF-8 byte "B7. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Package inputenc Error: Invalid UTF-8 byte "A6. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Package inputenc Error: Unicode character ( (U+FF08) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Package inputenc Error: Unicode character ) (U+FF09) (inputenc) not set up for use with LaTeX. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Undefined control sequence. <argument> ...gin {split}w(n)=\frac {2}{M-1}\� ��(\end {split} l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Package inputenc Error: Invalid UTF-8 byte "B7. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} ! Package inputenc Error: Invalid UTF-8 byte "A6. See the inputenc package documentation for explanation. Type H <return> for immediate help. ... l.14 ...lit}w(n)=\frac{2}{M-1}\左(\end{split} [1] (./math.aux) ) (see the transcript file for additional information) Output written on math.dvi (1 page, 392 bytes). Transcript written on math.log.

对bartlett窗口的大多数引用来自信号处理文献,在那里它被用作平滑值的许多窗口函数之一。注意,与此窗口的卷积产生线性插值。它也被称为变迹(意思是“消除脚”,即在采样信号的开始和结束处平滑不连续)或渐缩函数。巴特利特的傅立叶变换是两个sinc函数的乘积。注意Kanasewich的精彩讨论。

工具书类

1

M.S.Bartlett,“周期图分析和连续光谱”,Biometrika 37,1-16,1950年。

2

E.R.Kanasewich,“地球物理学中的时序分析”,阿尔伯塔大学出版社,1975年,第109-110页。

3

A.V.Oppenheim和R.W.Schafer,“离散时间信号处理”,普伦蒂斯·霍尔,1999年,第468-471页。

4

维基百科,“窗口函数”,https://en.wikipedia.org/wiki/window_function

5

W.H.Press、B.P.Flannery、S.A.Teukolsky和W.T.Vetterling,“数字食谱”,剑桥大学出版社,1986年,第429页。

实例

>>> import matplotlib.pyplot as plt
>>> np.bartlett(12)
array([ 0.        ,  0.18181818,  0.36363636,  0.54545455,  0.72727273, # may vary
        0.90909091,  0.90909091,  0.72727273,  0.54545455,  0.36363636,
        0.18181818,  0.        ])

绘制窗口及其频率响应(需要scipy和matplotlib):

>>> from numpy.fft import fft, fftshift
>>> window = np.bartlett(51)
>>> plt.plot(window)
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.title("Bartlett window")
Text(0.5, 1.0, 'Bartlett window')
>>> plt.ylabel("Amplitude")
Text(0, 0.5, 'Amplitude')
>>> plt.xlabel("Sample")
Text(0.5, 0, 'Sample')
>>> plt.show()
../../_images/numpy-bartlett-1_00_00.png
>>> plt.figure()
<Figure size 640x480 with 0 Axes>
>>> A = fft(window, 2048) / 25.5
>>> mag = np.abs(fftshift(A))
>>> freq = np.linspace(-0.5, 0.5, len(A))
>>> with np.errstate(divide='ignore', invalid='ignore'):
...     response = 20 * np.log10(mag)
...
>>> response = np.clip(response, -100, 100)
>>> plt.plot(freq, response)
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.title("Frequency response of Bartlett window")
Text(0.5, 1.0, 'Frequency response of Bartlett window')
>>> plt.ylabel("Magnitude [dB]")
Text(0, 0.5, 'Magnitude [dB]')
>>> plt.xlabel("Normalized frequency [cycles per sample]")
Text(0.5, 0, 'Normalized frequency [cycles per sample]')
>>> _ = plt.axis('tight')
>>> plt.show()
../../_images/numpy-bartlett-1_01_00.png