How to use specgram() window function?

I want to use kaiser window that’s part of numpy for drawing spectrogram

specgram(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,

       window=mlab.window_hanning, noverlap=128,

       cmap=None, xextent=None, pad_to=None, sides='default',

       scale_by_freq=None, **kwargs)

window: callable or ndarray

A function or a vector of length NFFT. To create window

vectors see :func:window_hanning, :func:window_none,

:func:numpy.blackman, :func:numpy.hamming,

:func:numpy.bartlett, :func:scipy.signal,

:func:scipy.signal.get_window, etc. The default is

:func:window_hanning. If a function is passed as the

argument, it must take a data segment as an argument and

return the windowed version of the segment.

So I tried:

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=kaiser, noverlap=2)

TypeError: kaiser() takes exactly 2 arguments (1 given)

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=kaiser(x, 8), noverlap=2)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=blackman, noverlap=2)

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Can someone help?

Thanks

Does the following solve your problem ?
NFFT = 1024
win = kaiser(NFFT,8) # 8 is the shpe parameter of the window
Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=win, noverlap=2)

···

Le lundi 19 septembre 2011 à 19:54 +0200, Klonuo Umom a écrit :

I want to use kaiser window that's part of numpy for drawing spectrogram

specgram(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
           window=mlab.window_hanning, noverlap=128,
           cmap=None, xextent=None, pad_to=None, sides='default',
           scale_by_freq=None, **kwargs)

*window*: callable or ndarray
    A function or a vector of length *NFFT*. To create window
    vectors see :func:`window_hanning`, :func:`window_none`,
    :func:`numpy.blackman`, :func:`numpy.hamming`,
    :func:`numpy.bartlett`, :func:`scipy.signal`,
    :func:`scipy.signal.get_window`, etc. The default is
    :func:`window_hanning`. If a function is passed as the
    argument, it must take a data segment as an argument and
    return the windowed version of the segment.

So I tried:

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=kaiser,
noverlap=2)
TypeError: kaiser() takes exactly 2 arguments (1 given)

Ah, I was using wrong parameter… Thanks. That works fine

···

On Tue, Sep 20, 2011 at 8:27 AM, Fabrice Silva <silva@…1918…> wrote:

Le lundi 19 septembre 2011 à 19:54 +0200, Klonuo Umom a écrit :

I want to use kaiser window that’s part of numpy for drawing spectrogram

specgram(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,

       window=mlab.window_hanning, noverlap=128,
       cmap=None, xextent=None, pad_to=None, sides='default',
       scale_by_freq=None, **kwargs)

window: callable or ndarray

A function or a vector of length *NFFT*. To create window
vectors see :func:`window_hanning`, :func:`window_none`,
:func:`numpy.blackman`, :func:`numpy.hamming`,
:func:`numpy.bartlett`, :func:`scipy.signal`,
:func:`scipy.signal.get_window`, etc. The default is
:func:`window_hanning`.  If a function is passed as the
argument, it must take a data segment as an argument and
return the windowed version of the segment.

So I tried:

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=kaiser,

noverlap=2)

TypeError: kaiser() takes exactly 2 arguments (1 given)

Does the following solve your problem ?

NFFT = 1024

win = kaiser(NFFT,8) # 8 is the shpe parameter of the window

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=win, noverlap=2)


All the data continuously generated in your IT infrastructure contains a

definitive record of customers, application performance, security

threats, fraudulent activity and more. Splunk takes this data and makes

sense of it. Business sense. IT sense. Common sense.

http://p.sf.net/sfu/splunk-d2dcopy1


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

You could also use a callable (instead of the vector) so that specgram
internally automatically get a NFFT length window

wrapper = lambda n: kaiser(n,8)
Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=wrapper, noverlap=2)

a wrapper is needed as specgram expects a function with a single argument (as documented).

···

Le mardi 20 septembre 2011 à 12:12 +0200, Klonuo Umom a écrit :

Ah, I was using wrong parameter... Thanks. That works fine

--
Fabrice Silva

Yes, it could be handy. I only needed it temporarily on couple of data files.

If you don’t mind, I have another question.

Those files are audio files. Can I limit dB range so that, let’s say, noise below 120dB isn’t drawn? Is there some parameter so I can set this range?

Thanks

···

On Tue, Sep 20, 2011 at 12:27 PM, Fabrice Silva <silva@…1918…> wrote:

Le mardi 20 septembre 2011 à 12:12 +0200, Klonuo Umom a écrit :

Ah, I was using wrong parameter… Thanks. That works fine

You could also use a callable (instead of the vector) so that specgram

internally automatically get a NFFT length window

wrapper = lambda n: kaiser(n,8)

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=wrapper, noverlap=2)

a wrapper is needed as specgram expects a function with a single argument (as documented).

Fabrice Silva


All the data continuously generated in your IT infrastructure contains a

definitive record of customers, application performance, security

threats, fraudulent activity and more. Splunk takes this data and makes

sense of it. Business sense. IT sense. Common sense.

http://p.sf.net/sfu/splunk-d2dcopy1


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

If you don't mind, I have another question.
Those files are audio files. Can I limit dB range so that, let's say,
noise below 120dB isn't drawn? Is there some parameter so I can set
this range?

specgram internally computed the spectrogram and then displays it into a
AxesImage instance (the im output argument). You can limit the range of
values the colormap extends by passing extra arguments to specgram that
are internally passed to the AxesImage.imshow method:

See Argument "kwargs" in
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.specgram
and
http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.imshow

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=win,

noverlap=2, vmin=-120)

···

Le mardi 20 septembre 2011 à 12:59 +0200, Klonuo Umom a écrit :

--
Fabrice Silva

Thank you very much Fabrice

I have no further questions

Cheers

···

On Tue, Sep 20, 2011 at 1:43 PM, Fabrice Silva <silva@…1918…> wrote:

Le mardi 20 septembre 2011 à 12:59 +0200, Klonuo Umom a écrit :

If you don’t mind, I have another question.

Those files are audio files. Can I limit dB range so that, let’s say,

noise below 120dB isn’t drawn? Is there some parameter so I can set

this range?

specgram internally computed the spectrogram and then displays it into a

AxesImage instance (the im output argument). You can limit the range of

values the colormap extends by passing extra arguments to specgram that

are internally passed to the AxesImage.imshow method:

See Argument “kwargs” in

http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.specgram

and

http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.imshow

Pxx, freqs, bins, im = specgram(x, NFFT=1024, Fs=fs, window=win,

noverlap=2, vmin=-120)

Fabrice Silva


All the data continuously generated in your IT infrastructure contains a

definitive record of customers, application performance, security

threats, fraudulent activity and more. Splunk takes this data and makes

sense of it. Business sense. IT sense. Common sense.

http://p.sf.net/sfu/splunk-d2dcopy1


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users