Repeating a Waveform in MATLAB
3 views (last 30 days)
Show older comments
I need to create a sine wave with a certain firing angle in the positive and negative cycles (both firing angles differ), and also different clipping values in the positive and negative cycles.
I did it for one cycle basically, using the following code:
clear
clc
com0 = 'Insert the frequency of the sine waveform - ';
f = input(com0);
com1 = 'Insert the time at which the positive cycle starts - ';
t1 = input(com1);
com2 = 'Insert the time at which the negative cycle starts - ';
t2 = input(com2);
com3 = 'Insert the clipping value desired during positive cycle - ';
c1 = input(com3);
com4 = 'Insert the clipping value desired during negative cycle - ';
c2 = input(com4);
T = 1/f; %Period of the Signal
t3 = (asin(c1))/(2*pi*f);
t4 = (asin(c2))/(2*pi*f);
if t3 < T/4
tx = ((T/2)-t3):0.00001:(T/2);
x = sin(2*pi*f*tx);
end
if t3 >= T/4
tx = t3:0.00001:(T/2);
x = sin(2*pi*f*tx);
end
ty = t2:0.00001:T;
if t4 < (3*T)/4
ty = (t4+T):0.00001:T;
y = sin(2*pi*f*ty);
end
if t4 >= (3*T)/4
ty = t4:0.00001:T;
y = sin(2*pi*f*ty);
end
line(xlim(), [0,0], 'LineWidth', 1, 'Color', 'k');
hold on
plot(tx,x)
plot(ty,y)
grid
plot([t1 t1],[0 c1])
if t3 < T/4
plot([t1 ((T/2)-t3)],[c1 c1])
end
if t3 >= T/4
plot([t1 t3],[c1 c1])
end
plot([t2 t2],[0 c2])
if t4 < (3*T)/4
plot([t2 (t4+T)],[c2 c2])
end
if t4 >= (3*T)/4
plot([t2 t4],[c2 c2])
end
xlim([0 T])
hold off
How can I repeat the same waveform for at least two more periods (or cycles)?
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!