How to get spectrogram data to align with signal data

조회 수: 12 (최근 30일)
Zjuv9021
Zjuv9021 2021년 4월 11일
답변: Srivardhan Gadila 2021년 4월 24일
I am attempting to align the time variables of the spectrogram of a signal and it's correpsonding time points in the time domain, and as you can see, we are a bit lagging behind in the time domain (bottom subplot) because of the reduced width from the spectrogram.
Is there a way I can adjust the subplot(2,1,2) to cleverly align with where the time = 60 is on the spectrogram? Right now, I'm simply using subplot function.
Thank you,
Zach

채택된 답변

Srivardhan Gadila
Srivardhan Gadila 2021년 4월 24일
You can make use of the Position and the XLim properties of the axes. Refer to the documentation of Axes Properties for more information.
N = 1024;
n = 0:N-1;
w0 = 2*pi/5;
x = sin(w0*n)+10*sin(2*w0*n);
s = spectrogram(x);
f1 = subplot(2,1,1);
spectrogram(x,'yaxis');
f1WidthHeight = f1.Position(3:4);
f2 = subplot(2,1,2);
plot(x);
%Set same width and Xlimits for the second subplot
f2.Position(3:4) = f1WidthHeight;
f2.XLim = f1.XLim;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by