[SciPy-Dev] signal.spectrogram doesn't change nperseg to length of window?

Ralf Gommers ralf.gommers at gmail.com
Sat Nov 26 17:41:45 EST 2016


On Tue, Nov 22, 2016 at 10:15 AM, Eric Larson <larson.eric.d at gmail.com>
wrote:

> It looks like you are reading the docs correctly. From looking at the
> code, I can confirm that it doesn't change `nperseg` based on what is
> passed for `window`. So it looks like a bug to me.
>
> Do you have time to look into making a Pull Request to fix it?
>

Opened an issue for this to not lose track of it:
https://github.com/scipy/scipy/issues/6817

Ralf



> Eric
>
>
> On Sat, Nov 19, 2016 at 10:41 PM, David Nicholson <nicholdav at gmail.com>
> wrote:
>
>> Hi scipy-dev list,
>>
>> I'm using spectrogram from scipy.signal with a custom window. My
>> understanding from the docs is that when I provide an array_like for the
>> window, the value for nperseg will change from the default of 256 to
>> whatever the length is of the window I provide.
>>
>> But instead I get an error saying  'noverlap must be less than nperseg' and
>> when I check with pdb I can see that nperseg is still the default value.
>> I'm using a value for noverlap that's larger than the default nperseg, but
>> less than the length of the window. I don't get the error if I call the
>> function with 'nperseg=window.shape[0]'.
>>
>>  I skimmed the source and don't see anything in the _spect_helper
>> function that would change nperseg to the length of window.
>>
>> Am I misunderstanding the docs, or am I calling the function wrong, or is
>> this a bug?
>>
>> Here's my code:
>> from scipy.io import wavfile
>> from scipy.signal import slepian # i.e. 'DPSS' window used for FFT
>> from scipy.signal import spectrogram
>>
>> FFT_SIZE = 512
>> FFT_OVERLAP = FFT_SIZE - 32
>> win_dpss = slepian(FFT_SIZE, 4/FFT_SIZE) #shape =
>>
>> [rate,data] = wavfile.read('a_file_you_have.wav')
>> f,t,spec = spectrogram(data, rate, window=win_dpss, noverlap=FFT_OVERLAP)
>>
>> Thanks for your help
>> --David
>>
>> --
>> David Nicholson, Ph.D. Candidate
>> Sober Lab <http://www.biology.emory.edu/research/Sober/Home.html>, Emory
>> Neuroscience Program. <http://www.emory.edu/NEUROSCIENCE/>
>> www.nicholdav.info; <http://www.nicholdav.info>
>> https://github.com/NickleDave
>>
>> _______________________________________________
>> SciPy-Dev mailing list
>> SciPy-Dev at scipy.org
>> https://mail.scipy.org/mailman/listinfo/scipy-dev
>>
>>
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/scipy-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20161127/36d48a8b/attachment.html>


More information about the SciPy-Dev mailing list