I am new to DSP and i have a question because it is not the same as theory.

I need to get spectrogram of wav file and feed it to CNN. I have used scipy.signal to get spectrogram.

I know spectrogram is square of absolute of STFT result. From what i know STFT is calculated by split signal into small chunks (a chunk overlap previous chunk ex. 50% overlap). With each chunk we apply DFT to calculate frequency components, and this is a line in STFT matrix. After STFT we have one dimension matrix with size m * n. But when i see documatation of scipy.signal.spectrogram link.

In this documentation i see 3 parameter:

  • windowstr: Specify what type of windows will be used and length of it. ex: windows("hann", 0.25). I understand is hanning windows and length is 0.25s

  • nperseg: Length of each segment. Defaults to None, but if window is str or tuple, is set to 256, and if window is array_like, is set to the length of the window.

  • nfftint, optional Length of the FFT used, if a zero padded FFT is desired. If None, the FFT length is nperseg. Defaults to None.

I think scipy calculate spectrogram by apply window in the signal. so the length of each segment is equal lenght of windows. Then apply DFT in windowed signal. And the result is one column in spectroram result.

But what i concern is I think nperseg parameter will derive from windows parameter and nfft parameter must be power of (2).

If my signal have fs = 16000Hz, windows = ("hann", 0.25), npereg = 500, nfft = None. What happened??. How spectrogram will be calculated? How many sample in each chunk 500 or equal windows size (16000 * 0.25)?

  • $\begingroup$ The windows size is not (16000 * 0.25). The 0.25 is a shape for a Tukey window, not a length. $\endgroup$ – hotpaw2 Nov 5 '19 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.