signal.spectrogram doesn't change nperseg to length of window?

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

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? Eric On Sat, Nov 19, 2016 at 10:41 PM, David Nicholson <nicholdav@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@scipy.org https://mail.scipy.org/mailman/listinfo/scipy-dev

On Tue, Nov 22, 2016 at 10:15 AM, Eric Larson <larson.eric.d@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@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@scipy.org https://mail.scipy.org/mailman/listinfo/scipy-dev
_______________________________________________ SciPy-Dev mailing list SciPy-Dev@scipy.org https://mail.scipy.org/mailman/listinfo/scipy-dev
participants (3)
-
David Nicholson
-
Eric Larson
-
Ralf Gommers