Hann function

Hann function (left), and its frequency response (right)

The Hann function of length ${\displaystyle L,}$ used to perform Hann smoothing,[1] is named after the Austrian meteorologist Julius von Hann, is a window function given by:

${\displaystyle w_{0}(x)\triangleq \left\{{\begin{array}{ccl}{\tfrac {1}{2}}\left(1+\cos \left({\frac {2\pi x}{L}}\right)\right)=\cos ^{2}\left({\frac {\pi x}{L}}\right),\quad &\left|x\right|\leq L/2\\0,\quad &\left|x\right|>L/2\end{array}}\right\}.}$   [2]

For digital signal processing, the function can be sampled symmetrically as:

{\displaystyle \left.{\begin{aligned}w[n]=w_{0}\left({\tfrac {L}{N}}(n-N/2)\right)&={\tfrac {1}{2}}\left[1-\cos \left({\tfrac {2\pi n}{N}}\right)\right]\\&=\sin ^{2}\left({\tfrac {\pi n}{N}}\right)\end{aligned}}\right\},\quad 0\leq n\leq N,}

where the length of the window is ${\displaystyle N+1,}$ and N can be even or odd. (see Window function#Hann and Hamming windows) It is also known as the raised cosine window, Hann filter, von Hann window, etc.[3][4]

Fourier transform

Top: 16 sample DFT-even Hann window. Bottom: Its discrete-time Fourier transform (DTFT) and the 3 non-zero values of its discrete Fourier transform (DFT).

The Hann window is a linear combination of modulated rectangular windows:

${\displaystyle \mathrm {rect} (x/L)\quad {\stackrel {\text{Fourier transform}}{\longleftrightarrow }}\quad L\cdot \mathrm {sinc} (Lf)={\frac {\sin(\pi Lf)}{\pi f}}.}$

Using Euler's formula to expand the cosine term, we can write:

${\displaystyle w_{0}(x)={\tfrac {1}{2}}\mathrm {rect} (x/L)+{\tfrac {1}{4}}e^{i2\pi x/L}\mathrm {rect} (x/L)+{\tfrac {1}{4}}e^{-i2\pi x/L}\mathrm {rect} (x/L),}$

whose Fourier transform is just:

${\displaystyle W_{0}(f)={\tfrac {1}{2}}{\frac {\sin(\pi Lf)}{\pi f}}+{\tfrac {1}{4}}{\frac {\sin(\pi L(f-1/L))}{\pi (f-1/L)}}+{\tfrac {1}{4}}{\frac {\sin(\pi L(f+1/L))}{\pi (f+1/L)}}.}$

Discrete transforms

The Discrete-time Fourier transform (DTFT) of the N+1 length, time-shifted sequence is defined by a Fourier series, which also has a 3-term equivalent that is derived similarly to the Fourier transform derivation:

{\displaystyle {\begin{aligned}{\mathcal {F}}\{w[n]\}&\triangleq \sum _{n=0}^{N}w[n]\cdot e^{-i2\pi fn}\\&=e^{-i\pi fN}\left[{\tfrac {1}{2}}{\frac {\sin(\pi (N+1)f)}{\sin(\pi f)}}+{\tfrac {1}{4}}{\frac {\sin(\pi (N+1)(f-{\tfrac {1}{N}}))}{\sin(\pi (f-{\tfrac {1}{N}}))}}+{\tfrac {1}{4}}{\frac {\sin(\pi (N+1)(f+{\tfrac {1}{N}}))}{\sin(\pi (f+{\tfrac {1}{N}}))}}\right].\end{aligned}}}

For even values of N, the truncated sequence ${\displaystyle \{w[n],\ 0\leq n\leq N-1\}}$ is a DFT-even (aka periodic) Hann window. Since the truncated sample has value zero, it is clear from the Fourier series definition that the DTFTs are equivalent. However, the approach followed above results in a significantly different-looking, but equivalent, 3-term expression:

${\displaystyle {\mathcal {F}}\{w[n]\}=e^{-i\pi f(N-1)}\left[{\tfrac {1}{2}}{\frac {\sin(\pi Nf)}{\sin(\pi f)}}+{\tfrac {1}{4}}e^{-i\pi /N}{\frac {\sin(\pi N(f-{\tfrac {1}{N}}))}{\sin(\pi (f-{\tfrac {1}{N}}))}}+{\tfrac {1}{4}}e^{i\pi /N}{\frac {\sin(\pi N(f+{\tfrac {1}{N}}))}{\sin(\pi (f+{\tfrac {1}{N}}))}}\right].}$

An N-length DFT of the window function samples the DTFT at frequencies ${\displaystyle f=k/N,}$ for integer values of ${\displaystyle k.}$ From the expression immediately above, it is easy to see that only 3 of the N DFT coefficients are non-zero. And from the other expression, it is apparent that all are real-valued. These properties are appealing for real-time applications that require both windowed and non-windowed (rectangularly windowed) transforms, because the windowed transforms can be efficiently derived from the non-windowed transforms by convolution.[5]

Name

The function is named in honour of von Hann, who used the three-term weighted average smoothing technique on meteorological data.[6][3] However, the erroneous[2] "Hanning" function is also heard of on occasion, derived from the paper in which it was named, where the term "hanning a signal" was used to mean applying the Hann window to it.[7][8] The confusion arose from the similar Hamming function, named after Richard Hamming.