dspp
Digital Signal Processing library for C++
 All Classes Namespaces Functions Variables Groups Pages
Functions
dspp::window Namespace Reference

Window functions (also known as an apodization functions or tapering functions). More...

Functions

template<class T >
T & rect (T &&w, bool symm=true)
 
template<class T >
T & triang (T &&w, bool symm=true)
 
template<class T >
T & bartlett (T &&w, bool symm=true)
 
template<class T >
T & hann (T &&w, bool symm=true)
 
template<class T >
T & welch (T &&w, bool symm=true)
 
template<class T >
T & parzen (T &&w, bool symm=true)
 
template<class T >
T & bohman (T &&w, bool symm=true)
 
template<class T >
T & chebyshev (T &&w, typename T::value_type a=100)
 
template<class T >
T & blackman (T &&w, bool symm=true)
 
template<class T >
T & nuttall (T &&w, bool symm=true)
 
template<class T >
T & blackmannuttall (T &&w, bool symm=true)
 
template<class T >
T & blackmanharris (T &&w, bool symm=true)
 
template<class T >
T & flattop (T &&w, bool symm=true)
 
template<class T >
T & barthann (T &&w, bool symm=true)
 
template<class T >
T & hamming (T &&w, bool symm=true)
 
template<class T >
T & kaiser (T &&w, typename T::value_type beta=10, bool symm=true)
 
template<class T >
T & gaussian (T &&w, typename T::value_type a=2.5, bool symm=true)
 

Detailed Description

Window functions (also known as an apodization functions or tapering functions).

A window function is a mathematical function that is zero-valued outside of an interval. Typical applications include the design of finite impulse response (FIR) filters and controlling spectral leakage in Fourier analysis. When a discrete-time series is multiplied against the coefficients of a window function everything outside the interval is zero-valued. This gives the appearance of "looking through a window".

N represents the number of samples in a discrete-time window function \(w(n),\space 0 \le n \le N-1\). When N is an odd number, non-flat windows have a singular maximum point. When N is even, they have a double maximum.

For spectral analysis, window functions are often required to be an even length but still need a single maximum value. This is accomplished by deleting the right-most coefficient. The dspp window functions can do this automatically when the symm parameter is false. For example, a window of size() 1024 with symm false will be computed as if N is 1025.

Function Prototype

#include <dspp/window.hpp>

Window functions have the same prototype.

Return values
T&A reference to the container that was windowed.
Parameters
wA container of data for application of the window. To get the window coefficients supply a container full of 1s. The container must provide a forward iterator, T::value_type, and size().
symmTrue generates a symmetric window for filter design.
False generates a periodic window for spectral analysis.

Some windows are generated with sine or FFT functions. If performance is important then use a stored copy of the coefficients instead of generating the window every time.

// Obtaining window coefficients
auto w = dspp::window::hann(std::vector<float>(32,1));

For creating FIR filters you can apply the window to an existing container.

// Applying window to an existing container
std::array<double, 128> filter = some_fir_filter();

Function Documentation

template<class T >
T& dspp::window::rect ( T &&  w,
bool  symm = true 
)

\[ w(n)=1 \qquad 0 \leq n \leq N-1 \]

window_rect.png
template<class T >
T& dspp::window::triang ( T &&  w,
bool  symm = true 
)

\[ w(n)=1-\begin{cases} \left|\frac{n-\frac{N-1}{2}}{\frac{N}{2}}\right| & \text{if $N$ is even} \\ \left|\frac{n-\frac{N-1}{2}}{\frac{N+1}{2}}\right| & \text{if $N$ is odd} \end{cases} \qquad 0 \leq n \leq N-1 \]

window_triang.png
template<class T >
T& dspp::window::bartlett ( T &&  w,
bool  symm = true 
)

\[ w(n) = 1- \left|\frac{n-\frac{N-1}{2}}{\frac{N-1}{2}}\right| \qquad 0 \leq n \leq N-1 \]

window_bartlett.png
template<class T >
T& dspp::window::hann ( T &&  w,
bool  symm = true 
)

\[ w(n) = 0.5 - 0.5 \cos\left(\frac{2\pi{n}}{N-1}\right) \qquad 0 \leq n \leq N-1 \]

window_hann.png
template<class T >
T& dspp::window::welch ( T &&  w,
bool  symm = true 
)

\[ w(n)=1 - \left(\frac{n-\frac{N-1}{2}}{\frac{N+1}{2}}\right)^2 \qquad 0 \leq n \leq N-1 \]

window_welch.png
template<class T >
T& dspp::window::parzen ( T &&  w,
bool  symm = true 
)

\[ w(n)=\begin{cases} 1 - 6\left(\frac{|n|}{N/2}\right)^2 + 6\left(\frac{|n|}{N/2}\right)^3 & 0 \leq |n| \leq N/4 \\ 2\left(1-\frac{|n|}{N/2}\right)^3 & N/4 \lt |n| \le N/2 \end{cases} \qquad -\frac{N-1}{2} \leq n \leq \frac{N-1}{2} \]

window_parzen.png
template<class T >
T& dspp::window::bohman ( T &&  w,
bool  symm = true 
)

\[ w(n) = (1-|n|)cos(\pi\left|n\right|)+\frac{1}{\pi}sin(\pi\left|n\right|) \qquad -1 \leq n \leq 1 \]

window_bohman.png
template<class T >
T& dspp::window::chebyshev ( T &&  w,
typename T::value_type  a = 100 
)

\[ W(n) = \frac {\cos\{N \cos^{-1}[\beta \cos(\frac{\pi k}{N})]\}} {\cosh[N \cosh^{-1}(\beta)]} \qquad \beta = \cosh \left [\frac{1}{N} \cosh^{-1}(10^\frac{a}{20}) \right ] \qquad -1 \leq n \leq 1 \]

window_chebyshev.png
template<class T >
T& dspp::window::blackman ( T &&  w,
bool  symm = true 
)

\[ w(n) = 0.42 - 0.5 \cos\left(\frac{2\pi n}{N-1}\right) + 0.08 \cos\left(\frac{4\pi n}{N-1}\right) \qquad 0 \leq n \leq N-1 \]

window_blackman.png
template<class T >
T& dspp::window::nuttall ( T &&  w,
bool  symm = true 
)

\[ w(n)=a_0 - a_1 \cos \left ( \frac{2 \pi n}{N-1} \right)+ a_2 \cos \left ( \frac{4 \pi n}{N-1} \right)- a_3 \cos \left ( \frac{6 \pi n}{N-1} \right) \qquad 0 \leq n \leq N-1 \\ a_0=0.355768;\quad a_1=0.487396;\quad a_2=0.144232;\quad a_3=0.012604 \]

window_nuttall.png
template<class T >
T& dspp::window::blackmannuttall ( T &&  w,
bool  symm = true 
)

\[ w(n)=a_0 - a_1 \cos \left ( \frac{2 \pi n}{N-1} \right)+ a_2 \cos \left ( \frac{4 \pi n}{N-1} \right)- a_3 \cos \left ( \frac{6 \pi n}{N-1} \right) \qquad 0 \leq n \leq N-1 \\ a_0=0.3635819;\quad a_1=0.4891775;\quad a_2=0.1365995;\quad a_3=0.0106411 \]

window_blackmannuttall.png
template<class T >
T& dspp::window::blackmanharris ( T &&  w,
bool  symm = true 
)

\[ w(n)=a_0 - a_1 \cos \left ( \frac{2 \pi n}{N-1} \right)+ a_2 \cos \left ( \frac{4 \pi n}{N-1} \right)- a_3 \cos \left ( \frac{6 \pi n}{N-1} \right) \qquad 0 \leq n \leq N-1 \\ a_0=0.35875;\quad a_1=0.48829;\quad a_2=0.14128;\quad a_3=0.01168 \]

window_blackmanharris.png
template<class T >
T& dspp::window::flattop ( T &&  w,
bool  symm = true 
)

\[ w(n)=a_0 - a_1 \cos \left ( \frac{2 \pi n}{N-1} \right)+ a_2 \cos \left ( \frac{4 \pi n}{N-1} \right)- a_3 \cos \left ( \frac{6 \pi n}{N-1} \right) + a_4 \cos \left ( \frac{8 \pi n}{N-1} \right) \qquad 0 \leq n \leq N-1 \\ a_0=0.21557895;\quad a_1=0.41663158;\quad a_2=0.277263158;\quad a_3=0.083578947;\quad a_4=0.006947368 \]

window_flattop.png
template<class T >
T& dspp::window::barthann ( T &&  w,
bool  symm = true 
)

\[ w(n)=0.62 - 0.48 \left |\frac{n}{N-1}-\frac{1}{2} \right| - 0.38 \cos \left (\frac{2 \pi n}{N-1}\right ) \qquad 0 \leq n \leq N-1 \]

window_barthann.png
template<class T >
T& dspp::window::hamming ( T &&  w,
bool  symm = true 
)

\[ w(n) = 0.54 - 0.46 \cos\left(\frac{2\pi{n}}{M-1}\right) \qquad 0 \leq n \leq N-1 \]

window_hamming.png
template<class T >
T& dspp::window::kaiser ( T &&  w,
typename T::value_type  beta = 10,
bool  symm = true 
)

\[ w(n) = \frac{I_0\left( \beta \sqrt{1-\frac{4n^2}{(N-1)^2}} \right)} {I_0(\beta)} \qquad 0 \leq n \leq N-1 \]

window_kaiser.png
template<class T >
T& dspp::window::gaussian ( T &&  w,
typename T::value_type  a = 2.5,
bool  symm = true 
)

\[ w(n) = e^{ -\frac{1}{2}\left(\alpha\frac{n}{N/2}\right)^2 } \qquad -\frac{N-1}{2} \leq n \leq \frac{N-1}{2} \]

window_gaussian.png