Reputation: 735
I need to plot on matlab a simple x(t) function that changes its freqency after specific time:
x(t) = cos(2pi*2hz*t) for t<1;
x(t) = cos(2pi*5hz*t) for t>=1
I managed by using a simple IF statement on a function, but seems like I have to use some existing matlab function that does the same. Any help would be appreciated.
Upvotes: 0
Views: 175
Reputation: 35525
It is as easy as this:
t1=0:0.01:1;
t2=1:0.01:2;
x1=cos(2*pi*2*t1);
x2=cos(2*pi*5*t2);
hold on
plot(t1,x1,'b')
plot(t2,x2,'b')
EDIT : As @Dan suggested, if you want the whole signal to be in one variable so you can do some SCIENCE with it, youo can also do:
t1=0:0.01:1;
t2=1:0.01:2;
x1=cos(2*pi*2*t1);
x2=cos(2*pi*5*t2);
x=[x1 x2];
t=[t1 t2];
plot(t,x)
Upvotes: 3