Plotting cycles of signal

2 views (last 30 days)
Ben Hamill
Ben Hamill on 15 Nov 2019
Answered: Raunak Gupta on 18 Nov 2019
Hi, I am relatively unexperienced with MATLAB but how do i plot any number of cycles of the following signal;
z(t) = 0 if − π ≤ t < 0
3 if 0 ≤ t ≤ π

Answers (1)

Raunak Gupta
Raunak Gupta on 18 Nov 2019
For plotting the function mentioned in the question you may use square wave as it will replicate your requirements. I have written an example below which plots the function in range [-16π,16π]. You may find it helpful.
% This particular t will plot 16 cycles
% t can be changed accordingly for plotting particular number of cycles
t = -16*pi:0.02:16*pi;
x = 3*square(t); % Period of the wave is 2*pi
x = x.*(x>=0); % converting negative cycle to zero as per function requirement
plot(t/pi,x); % Plotting t/pi for better understanding
xlabel('t / \pi')

Community Treasure Hunt

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

Start Hunting!