How to plot spectrogram in actual time period?

Does anyone know how to plot actual time interval in Spectrogram using STFT?
I want to analyze an event in a signal in a certain time span, but using the spectrogram built in function plots in Spectrogram from 0, while I want it to be plotted from for exp. 5083s time span as seen below. I appreciate if anyone can help me with this.

9 commentaires

hello
I am not sure to understand what you want to do on the time axis ?
here a code that includes the spectrogram of a signal
now what you would do on its time axis ? you can interpolate or shift or whatever ...
Jan Ali
Jan Ali le 1 Mai 2021
Modifié(e) : Jan Ali le 3 Mai 2021
Thanks Mathieu for the answer.
I am using the Spectrogram built in function, and want the time axis to show the time interval as seen in the picture below:
Additionally, how the power/frequency scale is obtained?
What is the reference for the power/frequency scale bar on the right?
hello
ok, so your time vector in the first plot starts at a now zero value; take this value and use it as an offset value to the time vector generated by the spectrogram function, so both data should be time aligned
also, there is something strage about the fact that the upper plot has a time span of 12 seconds and the lower plot only 1 second; I assume you did modify manually the xaxis rendering (limits) not the same way on both plots
Jan Ali
Jan Ali le 2 Mai 2021
Hello again Mathieu, as I use the built in function for the spectrogram, it plots automatically and I can't see any option to modify the scale/limit as seen in the lower plot. I don't know how to modify it. Could you please share the code to plot the spectrogram in the same time span accordingly?
Also what is the reference for the power/frequency scale bar on the right?
Thanks in advance,
hello again
can you share your code ? - it would be easier to show you what I mean once it's implemented.
tx
Jan Ali
Jan Ali le 4 Mai 2021
Here is the code I am using for spectrogram:
% x is an AC current signal as shown above.
spectrogram(x,120,100,120,fs,'yaxis')
Then I get a colorbar scaled by power/frequency (dB/Hz).
I don't know what the reference (magnitude) for this is?
Hello
I have to admit that to get the fft output which same amplitude and scalling as the input time signal, I finally preferred (some time ago alreagy) to build my own code; the "new" recent implementation of Matlab functions need some time to be fully understood , and I have not taken this time yet; sure there must be the explanation somewhere in the doc;
I am now sure that a sinewave with amplitude = 1 is plotted with also the same amplitude , for the averaging fft spectrum and for the spectrogram
attached my code
Jan Ali
Jan Ali le 7 Mai 2021
Thanks Mathieu for the support. However, I don't know how to use the script/function for the colorbar.
The function [fft_specgram,freq_vector,time] = myspecgram(x, fs, 120, 0.9) provides outputs that I can plot like a signal. I appreciate if you guide me how to use it for the colorbar
hello
yiu can simply add this line of code , after the plot :
colorbar('vert');

Connectez-vous pour commenter.

Réponses (0)

Question posée :

le 1 Mai 2021

Commenté :

le 10 Mai 2021

Community Treasure Hunt

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

Start Hunting!

Translated by