Superimpose two plots having different vector lengths

9 次查看(过去 30 天)
Hello,
I am new with Matlab and try using it for practicing pedagogy exercises about signal processing. Unfortunately I am stuck at this point :
I try to superimpose a chirp signal (signal with increasing frequency rate) and an aliased signal of this same chirp signal onto the same plot using the "hold on" function. Unfortunately an error occurs : "Error using plot ; Vectors must be the same length". I have tried several alternatives and read similar questions without understanding how to circumvent this little issue. I understand that there is some incompatibility between my two signals, related to their respective axes I guess. I put my code below for more understanding. Also, I precise that I only want to use the hold on function and not alternatives in order to learn how to use it :
Fs = 200 % sampling frequency
t = 0:1/Fs:1
x = chirp(t,0,1,Fs/6)
dx = x(1:20:end)
subplot(3,1,1,'align');
plot(t,x),
xlabel('Time(sec)');
ylabel('Amplitude');
title('Chirp Signal')
hold on; % here is my problem
plot(t,dx)
subplot(3,1,2); % display same plot with discrete values
stem(x)
subplot(3,1,3); % display the power of frequency components
pwelch(x)

采纳的回答

Star Strider
Star Strider 2019-3-3
You need to make the ‘t’ vector the same length as the ‘dx’ vector. Thje easiest way to do that is to use the same decimation vector:
plot(t(1:20:end), dx)
That should work.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by