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

Here is my Matlab code for 5 different signals (sine wave, 2 square waves with d

ID: 1814453 • Letter: H

Question

                    Here is my Matlab code for 5 different signals (sine wave, 2 square waves with different duty cycles, sawtooth wave, and a triangle wave).  Each one has a frequency of 1000 Hz, peak amplitude of 2 volts, and a DC offset of 2.5 volts.  Also, one square wave has a 33% percent duty cycle and the other 50 percent.  My question is, why is it that all my plots show 4 periods great except my triangle wave code?  For some reason, I cannot get 4 periods of that wave to show.  Also, how do I make it so that I can show all the plots at once when I run the code because as of right now, only the last plot written will show up.  Lastly, how do I correcly calculate the sampling time for my time array?  As of right now, it is .000001 which plots all of the waves great except the triangle wave.  I got that number just by guessing.  How do I calculate that?                 

Explanation / Answer

clear,clc
frequency = 1000; % Hz
amplitude = 2; % Peak Voltage
dc_offset = 2.5; % Volts
periods = 4;
t = 0:.0001:((1/frequency)*periods);
sinusoid = dc_offset + amplitude * (sin(frequency * 2 * pi * t));
square_wave_1 = dc_offset + amplitude * square(1000*2*pi*t,50);
square_wave_2 = dc_offset + amplitude * square(1000*2*pi*t,33);
sawtooth = dc_offset + amplitude * sawtooth(1000*pi*2*t);
y=0:8
triangle = ((-1).^y);
subplot(5,1,1)
plot(t,sinusoid)
subplot(5,1,2)
plot(t,square_wave_1)
subplot(5,1,3)
plot(t,square_wave_2)
subplot(5,1,4)
plot(t,sawtooth)
subplot(5,1,5)
plot(y,triangle)

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