Window function: Difference between revisions

Content deleted Content added
linkages
Bender the Bot (talk | contribs)
 
(8 intermediate revisions by 7 users not shown)
Line 10:
 
== Applications ==
Window functions are used in spectral [[frequency spectrum#spectral analysis|analysis]]/modification/[[Overlap–add method#resynthesis|resynthesis]],<ref name=OLA/> the design of [[finite impulse response]] filters, merging multiscale and multidimensional datasets,<ref>{{Cite journal |last1=Ajala |first1=R. |last2=Persaud |first2=P. |title=Ground-Motion Evaluation of Hybrid Seismic Velocity Models |journal=The Seismic Record|date=2022 |volume=2 |issue=3 |pages=186–196 |doi=10.1785/0320220022 |s2cid=251504921 |doi-access=free |bibcode=2022SeisR...2..186A }}</ref><ref>{{Cite journal |last1=Ajala |first1=R. |last2=Persaud |first2=P. |title=Effect of Merging Multiscale Models on Seismic Wavefield Predictions Near the Southern San Andreas Fault |url=https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2021JB021915 |journal=Journal of Geophysical Research: Solid Earth |date=2021 |language=en |volume=126 |issue=10 |doi=10.1029/2021JB021915 |bibcode=2021JGRB..12621915A |s2cid=239654900 |issn=2169-9313|url-access=subscription }}</ref> as well as [[beamforming]] and [[Antenna (radio)|antenna]] design.
 
[[File:Spectral_leakage_caused_by_%22windowing%22.svg|thumb|400px|Figure 2: Windowing a sinusoid causes spectral leakage. The same amount of leakage occurs whether there are an integer (blue) or non-integer (red) number of cycles within the window (rows 1 and 2). When the sinusoid is sampled and windowed, its [[discrete-time Fourier transform]] (DTFT) also exhibits the same leakage pattern (rows 3 and 4). But when the DTFT is only sparsely sampled, at a certain interval, it is possible (depending on your point of view) to: (1) avoid the leakage, or (2) create the illusion of no leakage. For the case of the blue DTFT, those samples are the outputs of the [[discrete Fourier transform]] (DFT). The red DTFT has the same interval of zero-crossings, but the DFT samples fall in-between them, and the leakage is revealed.]]
Line 122:
 
:<math>w[n]=1 - \left(\frac{n-\frac{N}{2}}{\frac{N}{2}}\right)^2,\quad 0\le n \le N.</math><ref name=Welch1967/>
Alternatively, it can be written as two factors, as in a [[beta distribution]]:
:<math>w[n]= \left(1 + \frac{n-\frac{N}{2}}{\frac{N}{2}}\right) \left(1 - \frac{n-\frac{N}{2}}{\frac{N}{2}}\right),\quad 0\le n \le N.</math>
 
The defining [[quadratic polynomial]] reaches a value of zero at the samples just outside the span of the window.
Line 129 ⟶ 131:
{{clear}}
 
=== SineRaised-cosine windowwindows ===
[[File:Window function and frequency response - Cosine.svg|thumb|480px|right|Sine window]]
 
Windows in the form of a cosine function offset by a constant, such as the popular Hamming and Hann windows, are sometimes called raised-cosine windows. The Hann window is particularly like the [[raised cosine distribution]], which goes smoothly to zero at its ends.
:<math>w[n] = \sin\left(\frac{\pi n}{N}\right) = \cos\left(\frac{\pi n}{N} - \frac{\pi}{2}\right),\quad 0\le n \le N.</math>
 
The raised-cosine windows have the form:
The corresponding <math>w_0(n)\,</math> function is a cosine without the {{pi}}/2 phase offset. So the ''sine window''<ref name=Bosi/> is sometimes also called ''cosine window''.<ref name=Harris/> As it represents half a cycle of a sinusoidal function, it is also known variably as ''half-sine window''<ref name=Kido/> or ''half-cosine window''.<ref name=Landisman/>
:<math>w[n] = a_0 - (1-a_0) \cdot \cos\left( \tfrac{2 \pi n}{N} \right),\quad 0\le n \le N,</math>
or alternatively as their zero-phase versions:
:<math>
\begin{align}
w_0(n)\ &= w\left[ n+\tfrac{N}{2}\right]\\
&= a_0 + (1-a_0)\cdot \cos \left ( \tfrac{2\pi n}{N} \right),\quad -\tfrac{N}{2} \le n \le \tfrac{N}{2}.
\end{align}
</math>
 
==== Hann window====
The [[autocorrelation]] of a sine window produces a function known as the Bohman window.<ref name=MWbohman/>
{{Main|Hann function}}
[[File:Window function and its Fourier transform – Hann (n = 0...N).svg|thumb|480px|right|Hann window]]
 
Setting <math>a_0 = 0.5</math> produces a '''Hann window''':
==== Power-of-sine/cosine windows ====
:<math>w[n] = 0.5\; \left[1 - \cos \left ( \frac{2 \pi n}{N} \right) \right] = \sin^2 \left ( \frac{\pi n}{N} \right),</math><ref name=MWhann/>
[[File:Power-of-sine windows.png|thumb|440px|Power-of-sine window functions (left) and their spectra in dB (right), for powers 0, 0.25, 0.5, 1, 2, 4]]
named after [[Julius von Hann]], and sometimes referred to as ''Hanning'', which derived from the verb "to Hann".{{Citation needed|date=June 2025}} It is also known as the '''raised cosine''', because of its similarity to a [[raised-cosine distribution]].
 
This function is a member of both the [[#Cosine-sum windows|cosine-sum]] and [[#Power-of-sine/cosine_windows|power-of-sine]] families. Unlike the [[#Hann and Hamming windows|Hamming window]], the end points of the Hann window just touch zero. The resulting [[Spectral leakage|side-lobes]] roll off at about 18&nbsp;dB per octave.<ref name=JOShann/>
These window functions have the form:<ref name=PowCos/>
 
==== Hamming window ====
:<math>w[n] = \sin^\alpha\left(\frac{\pi n}{N}\right) = \cos^\alpha\left(\frac{\pi n}{N} - \frac{\pi}{2}\right),\quad 0\le n \le N.</math>
[[File:Window function and frequency response - Hamming (alpha = 0.53836, n = 0...N).svg|thumb|480px|right|Hamming window, ''a''<sub>0</sub>&nbsp;=&nbsp;0.53836 and ''a''<sub>1</sub>&nbsp;=&nbsp;0.46164. The original Hamming window would have ''a''<sub>0</sub>&nbsp;=&nbsp;0.54 and ''a''<sub>1</sub>&nbsp;=&nbsp;0.46.]]
 
Setting <math>a_0</math> to approximately 0.54, or more precisely 25/46, produces the '''Hamming window''', proposed by [[Richard W.&nbsp;Hamming]]. This choice places a zero crossing at frequency 5{{pi}}/(''N''&nbsp;−&nbsp;1), which cancels the first sidelobe of the Hann window, giving it a height of about one-fifth that of the Hann window.<ref name=Harris/><ref name=Enochson/><ref name=JOSHamming/>
The [[#Rectangular window|rectangular window]] ({{math|1=''α''&nbsp;=&nbsp;0}}), the [[#Sine window|sine window]] ({{math|1=''α''&nbsp;=&nbsp;1}}), and the [[#Hann and Hamming windows|Hann window]] ({{math|1=''α''&nbsp;=&nbsp;2}}) are members of this family.
The Hamming window is often called the '''Hamming blip''' when used for [[pulse shaping]].<ref name=sunar/><ref name=sunar2/><ref name=SRD/>
 
Approximation of the coefficients to two decimal places substantially lowers the level of sidelobes,<ref name=Harris/> to a nearly equiripple condition.<ref name=JOSHamming/> In the equiripple sense, the optimal values for the coefficients are ''a''<sub>0</sub>&nbsp;=&nbsp;0.53836 and ''a''<sub>1</sub>&nbsp;=&nbsp;0.46164.<ref name=JOSHamming/><ref name=Nuttall/>
For even-integer values of {{mvar|α}} these functions can also be expressed in cosine-sum form:
 
: <math>w[n]=a_0 - a_1 \cos \left ( \frac{2 \pi n}{N} \right)+ a_2 \cos \left ( \frac{4 \pi n}{N} \right)- a_3 \cos \left ( \frac{6 \pi n}{N} \right)+ a_4 \cos \left ( \frac{8 \pi n}{N} \right)- ...</math>
: <math>\begin{array}{l|llll}
\hline
\alpha & a_0 & a_1 & a_2 & a_3 & a_4 \\
\hline
0 & 1 \\
2 & 0.5 & 0.5 \\
4 & 0.375 & 0.5 & 0.125 \\
6 & 0.3125 & 0.46875 & 0.1875 & 0.03125 \\
8 & 0.2734375 & 0.4375 & 0.21875 & 0.0625 & 7.8125\times10^{-3} \\
\hline
\end{array}</math>
 
=== Cosine-sum windows ===
This family, which generalizes the [[#Raised-cosine windows|raised-cosine windows]], is also known as ''[generalized cosine windows.<ref>{{cite web | url = https://www.mathworks.com/help/signal/ug/generalized-cosine-windows.html generalized| cosinetitle windows]''.= xxx }}</ref>
 
{{Equation box 1
Line 175 ⟶ 176:
 
In most cases, including the examples below, all coefficients ''a''<sub>''k''</sub>&nbsp;≥&nbsp;0. These windows have only 2''K''&nbsp;+&nbsp;1 non-zero ''N''-point DFT coefficients.
 
==== Hann and Hamming windows{{anchor|Hamming window}} ====
{{Main|Hann function}}
[[File:Window function and its Fourier transform – Hann (n = 0...N).svg|thumb|480px|right|Hann window]]
[[File:Window function and frequency response - Hamming (alpha = 0.53836, n = 0...N).svg|thumb|480px|right|Hamming window, ''a''<sub>0</sub>&nbsp;=&nbsp;0.53836 and ''a''<sub>1</sub>&nbsp;=&nbsp;0.46164. The original Hamming window would have ''a''<sub>0</sub>&nbsp;=&nbsp;0.54 and ''a''<sub>1</sub>&nbsp;=&nbsp;0.46.]]
 
The customary cosine-sum windows for case ''K''&nbsp;=&nbsp;1 have the form
 
:<math>w[n] = a_0 - \underbrace{(1-a_0)}_{a_1}\cdot \cos\left( \tfrac{2 \pi n}{N} \right),\quad 0\le n \le N,</math>
 
which is easily (and often) confused with its zero-phase version:
 
:<math>
\begin{align}
w_0(n)\ &= w\left[ n+\tfrac{N}{2}\right]\\
&= a_0 + a_1\cdot \cos \left ( \tfrac{2\pi n}{N} \right),\quad -\tfrac{N}{2} \le n \le \tfrac{N}{2}.
\end{align}
</math>
 
Setting <math>a_0 = 0.5</math> produces a '''Hann window''':
 
:<math>w[n] = 0.5\; \left[1 - \cos \left ( \frac{2 \pi n}{N} \right) \right] = \sin^2 \left ( \frac{\pi n}{N} \right),</math><ref name=MWhann/>
 
named after [[Julius von Hann]], and sometimes erroneously referred to as ''Hanning'', presumably due to its linguistic and formulaic similarities to the Hamming window. It is also known as '''raised cosine''', because the zero-phase version, <math>w_0(n),</math> is one lobe of an elevated cosine function.
 
This function is a member of both the [[#Cosine-sum windows|cosine-sum]] and [[#Power-of-sine/cosine_windows|power-of-sine]] families. Unlike the [[#Hann and Hamming windows|Hamming window]], the end points of the Hann window just touch zero. The resulting [[Spectral leakage|side-lobes]] roll off at about 18&nbsp;dB per octave.<ref name=JOShann/>
 
Setting <math>a_0</math> to approximately 0.54, or more precisely 25/46, produces the '''Hamming window''', proposed by [[Richard W.&nbsp;Hamming]]. This choice places a zero crossing at frequency 5{{pi}}/(''N''&nbsp;−&nbsp;1), which cancels the first sidelobe of the Hann window, giving it a height of about one-fifth that of the Hann window.<ref name=Harris/><ref name=Enochson/><ref name=JOSHamming/>
The Hamming window is often called the '''Hamming blip''' when used for [[pulse shaping]].<ref name=sunar/><ref name=sunar2/><ref name=SRD/>
 
Approximation of the coefficients to two decimal places substantially lowers the level of sidelobes,<ref name=Harris/> to a nearly equiripple condition.<ref name=JOSHamming/> In the equiripple sense, the optimal values for the coefficients are ''a''<sub>0</sub>&nbsp;=&nbsp;0.53836 and ''a''<sub>1</sub>&nbsp;=&nbsp;0.46164.<ref name=JOSHamming/><ref name=Nuttall/>
 
==== Blackman window ====
Line 239 ⟶ 209:
[[File:Window function and frequency response - Blackman-Harris.svg|thumb|480px|right|Blackman–Harris window]]
 
A generalization of the Hamming family, produced by adding more shifted sinccosine functions, meant to minimize side-lobe levels<ref name=JOSBlack/><ref name=JOSBlack3/>
 
:<math>w[n]=a_0 - a_1 \cos \left ( \frac{2 \pi n}{N} \right)+ a_2 \cos \left ( \frac{4 \pi n}{N} \right)- a_3 \cos \left ( \frac{6 \pi n}{N} \right)</math>
Line 270 ⟶ 240:
Rife–Vincent windows<ref name=Rife/> are customarily scaled for unity average value, instead of unity peak value. The coefficient values below, applied to {{EquationNote|Eq.1}}, reflect that custom.
 
Class I, Order 1 (''K'' = 1): <math>a_0=1;\quad a_1=1</math> Functionally equivalent to the [[#Hann and Hamming windows|Hann window]] and power of sine ({{math|1=''α''&nbsp;=&nbsp;2}}).
 
Class I, Order 2 (''K'' = 2): <math>a_0=1;\quad a_1=\tfrac{4}{3};\quad a_2=\tfrac{1}{3}</math> Functionally equivalent to the power of sine ({{math|1=''α''&nbsp;=&nbsp;4}}).
 
Class I is defined by minimizing the high-order sidelobe amplitude. Coefficients for orders up to K=4 are tabulated.<ref name=Andria/>
Line 280 ⟶ 250:
Class III is a compromise for which order ''K''&nbsp;=&nbsp;2 resembles the {{slink|#Blackman window}}.<ref name=Andria/><ref name=Schoukens/>
 
{{clear}}
 
=== Sine window ===
[[File:Window function and frequency response - Cosine.svg|thumb|480px|right|Sine window]]
 
:<math>w[n] = \sin\left(\frac{\pi n}{N}\right) = \cos\left(\frac{\pi n}{N} - \frac{\pi}{2}\right),\quad 0\le n \le N.</math>
 
The corresponding <math>w_0(n)\,</math> function is a cosine without the {{pi}}/2 phase offset. So the ''sine window''<ref name=Bosi/> is sometimes also called ''cosine window''.<ref name=Harris/> As it represents half a cycle of a sinusoidal function, it is also known variably as ''half-sine window''<ref name=Kido/> or ''half-cosine window''.<ref name=Landisman/>
 
The [[autocorrelation]] of a sine window produces a function known as the Bohman window.<ref name=MWbohman/>
 
==== Power-of-sine/cosine windows ====
[[File:Power-of-sine windows.png|thumb|440px|Power-of-sine window functions (left) and their spectra in dB (right), for powers 0, 0.25, 0.5, 1, 2, 4]]
 
These window functions have the form:<ref name=PowCos/>
 
:<math>w[n] = \sin^\alpha\left(\frac{\pi n}{N}\right) = \cos^\alpha\left(\frac{\pi n}{N} - \frac{\pi}{2}\right),\quad 0\le n \le N.</math>
 
The [[#Rectangular window|rectangular window]] ({{math|1=''α''&nbsp;=&nbsp;0}}), the [[#Sine window|sine window]] ({{math|1=''α''&nbsp;=&nbsp;1}}), and the [[#Hann and Hamming windows|Hann window]] ({{math|1=''α''&nbsp;=&nbsp;2}}) are members of this family.
 
For even-integer values of {{mvar|α}} these functions can also be expressed in cosine-sum form:
 
: <math>w[n]=a_0 - a_1 \cos \left ( \frac{2 \pi n}{N} \right)+ a_2 \cos \left ( \frac{4 \pi n}{N} \right)- a_3 \cos \left ( \frac{6 \pi n}{N} \right)+ a_4 \cos \left ( \frac{8 \pi n}{N} \right)- ...</math>
: <math>\begin{array}{l|llll}
\hline
\alpha & a_0 & a_1 & a_2 & a_3 & a_4 \\
\hline
0 & 1 \\
2 & 0.5 & 0.5 \\
4 & 0.375 & 0.5 & 0.125 \\
6 & 0.3125 & 0.46875 & 0.1875 & 0.03125 \\
8 & 0.2734375 & 0.4375 & 0.21875 & 0.0625 & 7.8125\times10^{-3} \\
\hline
\end{array}</math>
{{clear}}
 
Line 366 ⟶ 370:
==== DPSS or Slepian window ====
 
The DPSS (discrete prolate spheroidal sequence) or [[Slepian function]], taper, or window [[Spectral concentration problem|maximizes the energy concentration in the main lobe]],<ref name=Slepian/> and is used in [[multitaper]] spectral analysis, which averages out noise in the spectrum and reduces information loss at the edges of the window.
 
The main lobe ends at a frequency bin given by the parameter ''α''.<ref name=KaiserDPSS/>
Line 459 ⟶ 463:
where <math>C^{\mu}_{N}</math> is the [[Ultraspherical polynomial]] of degree N, and <math>x_0</math> and <math>\mu</math> control the side-lobe patterns.<ref name=Deczky/>
 
Certain specific values of <math>\mu</math> yield other well-known windows: <math>\mu=0</math> and <math>\mu=1</math> give the Dolph–Chebyshev and [[Tapio Saramäki|Saramäki]] windows respectively.<ref name=Kabal/> See [httphttps://octave.sourceforge.net/signal/function/ultrwin.html here] for illustration of Ultraspherical windows with varied parametrization.
{{clear}}