MATLAB: Spectrogram time axis samples to actual time

convertsamplessampling ratespectrogramtimetime axis

Hi. I'm trying to plot the result of a spectrogram like: y-axis frequency and x-axis for time, but instead of time in seconds, it plots samples and I don't know how to convert samples to time. Normally, it would be Sample_number / Sampling_rate, but the original signal has 7813 samples and the spectrogram has only 961. Any ideas? Thank you.

Best Answer

Include the sampling frequency, and the result is a time-frequency plot (rather than an index-frequency plot). See for example: Spectrogram and Instantaneous Frequency (link). Note that fs must be the fifth input to spectrogram. To input a sample rate and still use the default values of the preceding optional arguments, specify these arguments as empty, [].

Related Question