Window Functions

Window functions taper finite signal blocks before FFT processing to prevent spectral leakage — the spreading of energy into neighbouring frequency bins caused by discontinuities at block edges.

Window comparison

Window

Edge values

Sidelobe level

Main lobe width

Rectangular

1.0

Highest

Narrowest

Hanning

0.0

Low

Medium

Hamming

0.08

Lower first sidelobe

Medium

Blackman

0.0

Lowest

Widest

Kaiser

configurable

configurable (via beta)

configurable (via beta)

Hanning is an effective default. Blackman excels when minimising leakage takes priority over frequency resolution. Kaiser is the most flexible — its beta parameter lets you dial in exact sidelobe/main-lobe trade-offs.

pyminidsp.hann_window(n)[source]

Generate a Hanning (Hann) window of length n.

Generate a Hanning (Hann) window:

\[w[n] = 0.5\bigl(1 - \cos(2\pi n / (N-1))\bigr)\]

Tapers to zero at both ends and is the default for FFT analysis.

Parameters:

n (int)

Return type:

ndarray[tuple[Any, …], dtype[float64]]

pyminidsp.hamming_window(n)[source]

Generate a Hamming window of length n.

Generate a Hamming window:

\[w[n] = 0.54 - 0.46 \cos(2\pi n / (N-1))\]

Similar to Hanning, but with a lower first sidelobe.

Parameters:

n (int)

Return type:

ndarray[tuple[Any, …], dtype[float64]]

pyminidsp.blackman_window(n)[source]

Generate a Blackman window of length n.

Generate a Blackman window:

\[w[n] = 0.42 - 0.5\cos(2\pi n/(N-1)) + 0.08\cos(4\pi n/(N-1))\]

Much lower sidelobes than Hanning/Hamming, with a wider main lobe.

Parameters:

n (int)

Return type:

ndarray[tuple[Any, …], dtype[float64]]

pyminidsp.rect_window(n)[source]

Generate a rectangular window of length n (all ones).

Generate a rectangular window (all ones). Useful as a baseline reference — equivalent to no tapering.

Parameters:

n (int)

Return type:

ndarray[tuple[Any, …], dtype[float64]]

pyminidsp.kaiser_window(n, beta)[source]

Generate a Kaiser window of length n with shape parameter beta.

Unlike other window functions, Kaiser windows require a beta parameter that controls the trade-off between main-lobe width and side-lobe level. Higher beta gives lower sidelobes but a wider main lobe.

Parameters:
  • n (int) – Window length.

  • beta (float) – Shape parameter (typical values: 5-14).

Returns:

numpy array of length n.

Return type:

ndarray[tuple[Any, …], dtype[float64]]

Generate a Kaiser window of length n with shape parameter beta.

Unlike the other window functions, Kaiser windows take a beta parameter that controls the trade-off between main-lobe width and side-lobe level:

  • beta ≈ 5: similar to Hamming

  • beta ≈ 8.6: similar to Blackman

  • beta ≈ 14: very high sidelobe suppression

\[w[n] = \frac{I_0\!\left(\beta\sqrt{1 - \left(\frac{2n}{N-1} - 1\right)^2}\right)}{I_0(\beta)}\]
Parameters:
  • n (int) – Window length.

  • beta (float) – Shape parameter.

Returns:

Array of length n.

Return type:

ndarray[tuple[Any, …], dtype[float64]]