Hi Hasan,
To repeat the waveform that you have designed for any desired number of periods (or cycles), you will need to make a few modifications to your code:
1.Define a variable to specify the number of cycles you want to plot:
com5 = 'Insert the number of cycles to plot - ';
numCycles = input(com5);
2. Create a “for” loop which iterates over the number of cycles you have defined. A time shift “shift = k * T” has to be created to ensure that each cycle starts at the correct time position on the plot:
for k = 0:(numCycles - 1)
shift = k * T;
3. Within the loop, we can shift the sine wave segments for each iteration. The “line” function draws a horizontal line from “x = shift” to “x = shift + T at y = 0”, with a specified line width and color:
line([shift shift+T], [0, 0], 'LineWidth', 1, 'Color', 'k');
plot(tx + shift, x, 'b')
plot(ty + shift, y, 'b')
4.The conditional statements that you used to determine the endpoints of the clipped waveform segments should also be shifted:
plot([t1 t1] + shift, [0 c1], 'r')
if t3 < T/4
plot([t1 ((T/2)-t3)] + shift, [c1 c1], 'r')
else
plot([t1 t3] + shift, [c1 c1], 'r')
end
plot([t2 t2] + shift, [0 c2], 'r')
if t4 < (3*T)/4
plot([t2 (t4+T)] + shift, [c2 c2], 'r')
else
plot([t2 t4] + shift, [c2 c2], 'r')
end
5.Set the x-axis limits to “xlim([0 numCycles*T])” to cover the entire duration of all plotted cycles.
This is the plot generated by applying the changes to the code, displaying the waveform over three periods (or cycles):

I hope this helps!