Superimpose two plots having different vector lengths
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Judicaël Fassaya
il 3 Mar 2019
Commentato: Star Strider
il 3 Mar 2019
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)
0 Commenti
Risposta accettata
Star Strider
il 3 Mar 2019
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.
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Multirate Signal Processing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!