What is the reference for the power/frequency scale bar on the right in Spectrogram?

4 次查看(过去 30 天)
Dear experts,
Can anyone help me how to get the power/frequency scale in Spectrogram using STFT?
What is the reference for the power/frequency scale bar on the right?
Additionally, how to plot actual time interval? I want it to plot on the time axis from for exp. 5083s time span but using the spectrogram built in function plots from 0 s as seen below.
I appreciate if anyone can help me with this.

回答(1 个)

Prasanna
Prasanna 2024-5-22
Hi,
The ‘spectogram’ function present in the signal processing toolbox returns the Short-Time Fourier Transform (STFT) of the input signal x. Each column of s contains an estimate of the short-term, time-localized frequency content of x. The magnitude squared of s is known as the spectrogram time-frequency representation of x[1]. The reference for the same is provided in the following documentation: https://www.mathworks.com/help/signal/ref/spectrogram.html
The time period provided in the input signal to the spectrogram function is reflected in the spectrogram plot obtained accordingly. However, if your data is large and scaled in minutes, you can use either the ‘imagesc’ function of MATLAB or manually set the x axis of the plot using the ‘get(gca, 'XTick')’ and set(gca, 'XTickLabel', newXTickLabels)’. To see how to use the ‘imagesc’ function to set the real time value, refer to the following link: https://in.mathworks.com/matlabcentral/answers/720554-how-to-plot-spectrogram-with-actual-time
A sample example to do the same:
[S, F, T, P] = spectrogram(y,128,120,128,fs,'yaxis')
startTime = 5083; % Start time in seconds
T_adj = T + startTime; % Adjust time vector
% Now plot using the adjusted time vector
imagesc(T_adj, F, 10*log10(P + eps));
axis xy;
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Spectrogram');
colorbar;
For more information on the ‘imagesc’ function, refer to the following documentation:
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by