How to set my wave to 0 when >1 and <-1
2 views (last 30 days)
Show older comments
I'm trying to generate a half cosine wave where
y(t) = {sqrt(2)*cos(pi/2 *t); |t|<= 1
0; |t| > 1}
I have my cosine wave working between -1 and 1 which is what I want, but then when it goes outside of that frame, I want it to be set to 0. I tried to use an if/elseif statement, but I'm not sure that it is doing what I want it to.
fs = 500; %sampling freq
t = -2:1/fs:2;
if t>1
x = 0;
elseif t<1
x = 0;
else
x = sqrt(2)*cos(pi/2*t);
end
figure(2)
plot(t,x);
axis([-2 2 -0.5 2]);
title('Half-cosine Pulse');
xlabel('Time(sec)');
ylabel('y(t)');
0 Comments
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!