Front page|Spectrum - Spectral Analysis in Python (0.5.2)

4.4. Windowing

In spectral analysis, it is common practice to multiply the input data by a tapering window.

Many windows are implemented and available in the window module as well as utilities to plot the window in time and frequency domains. Some windows that have been implemented are:

spectrum.window.window_bartlett(N) Bartlett window (wrapping of numpy.bartlett) also known as Fejer
spectrum.window.window_blackman(N[, alpha]) Blackman window
spectrum.window.window_gaussian(N[, alpha]) Gaussian window
spectrum.window.window_hamming(N) Hamming window
spectrum.window.window_hann(N) Hann window (or Hanning). (wrapping of numpy.bartlett)
spectrum.window.window_kaiser(N[, beta, method]) Kaiser window
spectrum.window.window_lanczos(N) Lanczos window also known as sinc window.
spectrum.window.window_nuttall(N) Nuttall tapering window
spectrum.window.window_tukey(N[, r]) Tukey tapering window (or cosine-tapered window)

See window module for a full list of windows. Note also that the waveform provides additional waveforms/windows.

4.4.1. Window object

There is a class Window that ease the manipulation of the tapering windows. It works as follows:

from spectrum.window import Window
N = 64
w = Window(N, 'hamming')

[hires.png, pdf]


where N is the length of the desired window, and “hamming” is the name. There are a lot of different windows, some of them require arguments. For example, the blackman window require an alpha argument:

w = Window(64, 'blackman', alpha=1)

From the object, you can easily access to the window data ( and frequency (w.frequencies), as well as quantities such as the equivalent noise band width:

>>> from spectrum.window import Window
>>> N = 64
>>> w = Window(N, 'rectangular')
>>> w.enbw

To have a list of valid names, omit the name. It should raise an error with the list of valid names. Alternatively, type:


Finally, when a window require arguments, you need to know their names (e.g., in the blackman example above, the alpha parameter is required).

The only way to get this information is to look at the function window_<name> (e.g. window_blackman) and type:


4.4.2. Simple window function call

You can explore the module to get the window function. For instance, if you look for the Hamming window, you should find a function called window_hamming(). You can look at it as follows:

from spectrum.window import window_hamming
from pylab import plot

N = 64
w = window_hamming(N)

[hires.png, pdf]


4.4.3. Window Visualisation

If you want to have a quick look at the window shape and its frequency behaviour, you can use the window_visu():

from spectrum.window import window_visu
N = 64
window_visu(N, 'hamming')

[hires.png, pdf]


4.4.4. Window Factory

If you do not want the object approach, you may want to use the Factory function called create_window() (the Window class relies on this function). The previous Hamming window can be called using:

from spectrum.window import create_window
from pylab import plot

N = 64
w = create_window(N, 'hamming')

[hires.png, pdf]