PA.
VALAR MATHEI A/P PADMANADHAN
CE180015
SECTION 2
QUIZ
The example question chosen is 2.
1. First of all, we should identify the unit step function and the period of the given question.
Unit step function of the given waveform is,
𝑓(𝑡) = 250 𝑢(𝑡 − 7.5𝑚𝑠) − 250𝑢 (𝑡 − 10𝑚𝑠) + (−250 𝑢(𝑡 − 17.5𝑚𝑠)
− (−250 𝑢(𝑡 − 20𝑚𝑠)))
Period, T = 0.02s
2. After that, start the Matlab software. Figure 1 shown the home interface of the Matlab
software.
Figure 1: Home Interface of Matlab.
3. Next, open new script as shown in Figure 2. Now, insert the following code in that tab
and run the program.
Figure 2: New function window.
Figure 3: After inserting the code.
The code used:
syms t;
T=20e-3;
w0=2*pi/T;
f=(250*heaviside(t-7.5e-3)-250*heaviside(t-10e-3))+(-250*heaviside(t-
17.5e-3)-(-250*heaviside(t-20e-3)));
a0_sym=1/T*int(f,t,0,T);
a0=double(a0_sym);
tnum=[0:1e-6:20e-3];
fnum=a0;
for n=1:21
a_sym(n)=2/T*int(f*cos(n*w0*t),t,0,T);
b_sym(n)=2/T*int(f*sin(n*w0*t),t,0,T);
a(n)=double(a_sym(n));
b(n)=double(b_sym(n));
harmonics=a(n)*cos(n*w0*tnum)+b(n)*sin(n*w0*tnum);
fnum=fnum+harmonics;
plot(tnum,fnum)
end
4. The answers for a0, an and bn (Figure 5,6) was obtained from the workspace as shown
in Figure 4.
Figure 4: The harmonics table in the Workspace.
Figure 5: The answers for an.
Figure 6: The answers for bn.
5. The answers obtained are tabulated as below.
n an bn
0 0 -
1 -112.539539519638 46.6154035722571
2 0 0
3 -37.5131798398794 90.5648275371779
4 0 0
5 22.5079079039277 54.3388965223067
6 0 0
7 16.0770770742340 6.65934336746530
8 0 0
9 -12.5043932799598 5.17948928580634
10 0 0
11 -10.2308672290580 24.6994984192303
12 0 0
13 8.65688765535679 20.8995755855026
14 0 0
15 7.50263596797588 3.10769357148381
16 0 0
17 -6.61997291291990 2.74208256307395
18 0 0
19 -5.92313365892833 14.2997096111333
20 0 0
21 5.35902569141135 12.9378325053111
6. We obtained the waveform as well, that is shown in Figure 7,8 below.
Figure 7: The waveform obtained in Matlab.
Figure 8: More detailed version of the waveform.