pyroomacoustics.windows module

Window Functions

This is a collection of many popular window functions used in signal processing.

A few options are provided to correctly construct the required window function. The flag keyword argument can take the following values.

asymmetric

This way, many of the functions will sum to one when their left part is added to their right part. This is useful for overlapped transforms such as the STFT.

symmetric

With this flag, the window is perfectly symmetric. This might be more suitable for analysis tasks.

mdct

Available for only some of the windows. The window is modified to satisfy the perfect reconstruction condition of the MDCT transform.

Often, we would like to get the full window function, but on some occasions, it is useful to get only the left (or right) part. This can be indicated via the keyword argument length that can take values full (default), left, or right.

pyroomacoustics.windows.bart(N, flag='asymmetric', length='full')

The Bartlett window function

\[w[n] = 2 / (M-1) ((M-1)/2 - |n - (M-1)/2|) , n=0,\ldots,N-1\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.bart_hann(N, flag='asymmetric', length='full')

The modified Bartlett–Hann window function

\[w[n] = 0.62 - 0.48|(n/M-0.5)| + 0.38 \cos(2\pi(n/M-0.5)), n=0,\ldots,N-1\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.blackman(N, flag='asymmetric', length='full')

The Blackman window function

\[w[n] = 0.42 - 0.5\cos(2\pi n/(M-1)) + 0.08\cos(4\pi n/(M-1)), n = 0, \ldots, M-1\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.blackman_harris(N, flag='asymmetric', length='full')

The Hann window function

\[w[n] = a_0 - a_1 \cos(2\pi n/M) + a_2 \cos(4\pi n/M) + a_3 \cos(6\pi n/M), n=0,\ldots,N-1\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.bohman(N, flag='asymmetric', length='full')

The Bohman window function

\[w[n] = (1-|x|) \cos(\pi |x|) + \pi / |x| \sin(\pi |x|), -1\leq x\leq 1\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.cosine(N, flag='asymmetric', length='full')

The cosine window function

\[w[n] = \cos(\pi (n/M - 0.5))^2\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.flattop(N, flag='asymmetric', length='full')

The flat top weighted window function

\[w[n] = a_0 - a_1 \cos(2\pi n/M) + a_2 \cos(4\pi n/M) + a_3 \cos(6\pi n/M) + a_4 \cos(8\pi n/M), n=0,\ldots,N-1\]

where

\[a0 = 0.21557895 a1 = 0.41663158 a2 = 0.277263158 a3 = 0.083578947 a4 = 0.006947368\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.gaussian(N, std, flag='asymmetric', length='full')

The flat top weighted window function

\[w[n] = e^{ -\frac{1}{2}\left(\frac{n}{\sigma}\right)^2 }\]
Parameters:
  • N (int) – the window length

  • std (float) – the standard deviation

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.hamming(N, flag='asymmetric', length='full')

The Hamming window function

\[w[n] = 0.54 - 0.46 \cos(2 \pi n / M), n=0,\ldots,N-1\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.hann(N, flag='asymmetric', length='full')

The Hann window function

\[w[n] = 0.5 (1 - \cos(2 \pi n / M)), n=0,\ldots,N-1\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.kaiser(N, beta, flag='asymmetric', length='full')

The Kaiser window function

\[w[n] = I_0\left( \beta \sqrt{1-\frac{4n^2}{(M-1)^2}} \right)/I_0(\beta)\]

with

\[\quad -\frac{M-1}{2} \leq n \leq \frac{M-1}{2},\]

where \(I_0\) is the modified zeroth-order Bessel function.

Parameters:
  • N (int) – the window length

  • beta (float) – Shape parameter, determines trade-off between main-lobe width and side lobe level. As beta gets large, the window narrows.

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed

pyroomacoustics.windows.rect(N)

The rectangular window

\[w[n] = 1, n=0,\ldots,N-1\]
Parameters:

N (int) – the window length

pyroomacoustics.windows.triang(N, flag='asymmetric', length='full')

The triangular window function

\[w[n] = 1 - | 2 n / M - 1 |, n=0,\ldots,N-1\]
Parameters:
  • N (int) – the window length

  • flag (string, optional) –

    Possible values

    • asymmetric: asymmetric windows are used for overlapping transforms (\(M=N\))

    • symmetric: the window is symmetric (\(M=N-1\))

    • mdct: impose MDCT condition on the window (\(M=N-1\) and \(w[n]^2 + w[n+N/2]^2=1\))

  • length (string, optional) –

    Possible values

    • full: the full length window is computed

    • right: the right half of the window is computed

    • left: the left half of the window is computed