0

I am performing a spectrogram using the function matplotlib.mlab.specgram see link. One of its arguments is the window function and the default one is the hanning window.

The signal to which I am applying the function is longer than the size of the block into which the signal is divided, that is the single slice of the spectrogram (I use NFFT = 512).

Here my question and my problem: I would like to change the window function from the default one -hanning_window()- to window_none(). One of the argument of matplotlib.mlab.specgram is indeed window to change the window function. But if I simply write among the arguments of the specgram function window=matplotlib.mlab.window_none() an error occurs since I am not specifying the array to which the window function must be applied. How can I specify this argument given the fact that the window function must be applied to several arrays of size NFFT and not to a single array, i.e. each block of length NFFT in which the signal is divided?

tacaswell
  • 84,579
  • 22
  • 210
  • 199
SirC
  • 2,101
  • 4
  • 19
  • 24
  • As a side note, this section of mlab just got a major overhaul. – tacaswell Feb 12 '14 at 03:05
  • As suggested by @Bonlenfum the right way to change the default window function is simply `window=matplotlib.mlab.window_none` and not `window=matplotlib.mlab.window_none()`. Thanks – SirC Feb 12 '14 at 10:30

1 Answers1

1

From the docs you linked:

matplotlib.mlab.specgram(x, NFFT=256, Fs=2, detrend=, window=, noverlap=128, pad_to=None, sides='default', scale_by_freq=None)

[...]

window: callable or ndarray

Since it asks for window to be a callable (something like a function handle; see What is a "callable" in Python?), it wants a function, and not the results of a function. So give it

window=matplotlib.mlab.window_none, window=matplotlib.mlab.window_none, 
    <other args here as necessary>)

and it will use the (non-)windowing function.

Community
  • 1
  • 1
Bonlenfum
  • 19,101
  • 2
  • 53
  • 56