Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need a vector corresponding to a square wave done in Matlab with the function

ID: 1840213 • Letter: I

Question

I need a vector corresponding to a square wave done in Matlab with the function "square(t)" whose amplitude changes between 0 and 1 and the width tao of each rectangular pulse is 4sec. The period is 2tao = T0 = 8sec. Set the phase of the square wave so that it is centered to be +1 from -2 to +2..etc. The period T0 = 2tao = 8units of time,switching sign at times = 2+- 4n for integers n. The time average of the signal is +1/2 because half of the time it is +1 and half the time it is 0. Please show the code for matlab with comments for each line. It should look like the figure below.

Explanation / Answer

clc;
clear all;
close all;
t = linspace(-10,12);
% Creating time axis limits as required (-10 to 12 is used as per requirement of setting phase)

x = 0.5+0.5*square(2*pi*1/8*t,50); % syntax is square(t,y) => t=2*pi*(f=1/8)*t ; y= duty cycle = (ton/ton+toff)*100; 0.5 is multiplied for getting amplitude as 1 and 0.5 is added for shifting wave to zero(dc)

plot(t-2,x); axis([-10 10 -1 2]); % Ploting square wave; as part of phase correction, wave is plotted from t-2; axis are the limits for our plot

grid on;

Note: Leave comments if you need any clarification.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote