Specgram vs Spectrogram

83 views (last 30 days)
Edward
Edward on 8 Aug 2011
Commented: Bjorn Gustavsson on 22 Jun 2021
I am using someone elses code to plot sound input. I am trying to change the specgram function to spectrogram. Their code is written like this: specgram(x,2048,fs); with x=sound input in a 6000000 x 1 vector, fs = sample frequency of 100,000;
I admit I am not sure what 2048 is. This is part of the reason why I am trying to use spectrogram to get a document on the syntax.
If i change the function to spectrogram I get the error:
??? Error using ==> welchparse at 36 The number of samples to overlap must be less than the length of the segments.
I am flying blind here. I can't troubleshoot this on my own as I can not access any information on Mathwork about the syntax of specgram. Anyone have any ideas on appropriate syntax with spectrogram?
  3 Comments
Cutie
Cutie on 21 Jun 2021
I have the signal processing tool box installed, yet I am getting same error. I got code from someone which I am trying to adapt to my data but using spectrogram in place of specgram function is giving same error as above.
Bjorn Gustavsson
Bjorn Gustavsson on 22 Jun 2021
The error-message says that "The number of samples to overlap must be less than the length of the segments". That means that the length of the window input (for the case that you specify an explicit windowing filter) or the window-length input parameter (one can also send in an integer that specifies the length of the segments and use the default windowing filter of that length) has to be larger than the overlap input parameter. If you for example use a segment of 128 samples (or a windowing filter with 128 elements) your overlap has to be smaller than 128. The function (handwavingly) works such that it takes the first 128 samples (in this illustrating case) windows those and calculates the fft of them, then steps forward in the data-array by 128-samples minus the length of the overlap (so if you use 28 samples of overlap it would then start at sample 101 and takes the next 128 samples from that point, and so on till the end of the data sequence. If your overlap is larger than the window-length this would be a stepping-forward through the data-array.

Sign in to comment.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 9 Aug 2011
The help for specgram (in the signal processing toolbox) I find in an older version of matlab (2004) it says that the calling sequence it
[B,F,T] = specgram(A,NFFT,Fs,Window,Noverlap);
Strange thing is that I dont recall having to change a lot of scripts and functions to the spectrogram syntax.
HTH

More Answers (0)

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!