# measure time from fft spectrogram

3 views (last 30 days)
LO on 12 May 2019
Commented: LO on 13 May 2019
trying to convert the time scale of a signal visualized on a spectrogram in sec/msec.
the spectrogram has been calculated using known values of
1) sampling frequency (20k)
2) window size (in samples) (1024)
3) overlap (0.9)
4) total duration of the recording in samples (tspec = 11755)
5) total duration of the recording in seconds (60)
calculation of the total duration in seconds: total duration (samples) / total duration (seconds)
-> length(tspec)/60 = 195.9167
calculation of the signal duration in sec = duration of signal in samples / 195.9167
is this correct or is there any smearing of the signal time units due to nfft and overlap ?
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Greg Dionne on 13 May 2019
You can extract the time vector from the third output of the spectrogram function.
[S,F,T,Pxx] = spectrogram(X,...)
F is the frequency vector corresponding to the rows in S and Pxx.
T is the time vector corresponding to the columns of S and Pxx.
The time and frequencies correspond to the center of each estimate in S and Pxx; the resolution of the estimates in time and frequency are governed by the choice of window and overlap used. If there aren't enough samples to complete a full FFT at the end of the input signal, X, then the result is truncated.
##### 3 CommentsShowHide 2 older comments
LO on 13 May 2019
absolutely! thanks for clarifying all this. I know these are basics. but it helped :)

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!

Translated by