How can I plot 3 signals one after another in on the same graph?

Hello,
I'm trying to generate a sinus with increasing frequency in time... I want them to appear one after another in the same graphic representation..I think that I should define a vector with the 3 signals as elements. I don't figure out how to implement this in code... Please help!
Thank you!
This is my code:
clear
clc
close all
F0=[100 200 300];
Fs=1000;
A=1;
tmax=0.5;
N=tmax*Fs;
for k=1:length(F0)
n=0:N-1
s=A*sin(2*pi*F0(k)/Fs*n)
t=n/Fs;
figure,plot(t,s)
end

 Accepted Answer

Tudor - you could create the figure outside of the for loop and apply the hold on command so that the figure retains the current plot (or plots) when you add new ones. Then, on each iteration of your for loop, add a multiple of tmax to your time vector t so that each signal follows the other. Try the following
figure;
hold on;
for k=1:length(F0)
n=0:N-1;
s=A*sin(2*pi*F0(k)/Fs*n);
t=n/Fs + tmax*(k-1);
plot(t,s);
end

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!