378 Practical MATLAB® Applications for Engineers
fundamental freq. wo=pi
1
0.5
−0.5
0.2
0.1
0
−0.1
−0.2
− 1
0
Amplitude
Amplitude
time (in sec)
(^01234)
5th. harmonic, freq. w=5wo
0 1 2 3 4
time (in sec)
3rd. harmonic, freq. w=3wo
0.4
0.2
−0.2
−0.4
0
(^01234)
time (in sec)
7th. harmonic, freq. w=7wo
0.15
0.1
0
0.05
−0.05
−0.1
0 1 2 3 4
time (in sec)
Amplitude
Amplitude
FIGURE 4.28
Plots of part a of Example 4.1.
figure(5); % Figure 4.32, part (e)
sqr = [.5ones(1,101) -.5ones(1,100) .5ones(1,100) -.5*ones(1,100)];
error1= sqr-Harmonic 1;
error3 = sqr-Har 13;
error5 = sqr-Har 135;
error7 = sqr-Har 1357;
subplot(2,2,1)
plot(t,sqr,t,error1);
title('error1(t)=square wave-harmonics:1')
yla b e l('A m plitu d e');a x is([0 4 -0.6 0.6]);
subplot(2,2,2)
plot(t,sqr,t,error3);
title('error3(t)=square wave-harmonics:1,3')
yla b e l('A m plitu d e');a x is([0 4 -0.6 0.6]);
subplot(2,2,3)
plot(t,sqr,t,error5);
title('error5(t)=square wave-harmonics:1,3.5')
xlabel('time (in sec)');axis([0 4 -0.6 0.6]);
ylabel('Amplitude');
subplot(2,2,4)
plot(t,sqr,t,error7);axis([0 4 -0.6 0.6]);
title('error7(t)=square wave-harmonics:1,3,5,7')
xlabel('time (in sec)');
ylabel('Amplitude');
The script fi le square_Fourier is executed and the results are shown in Figures 4.28
through 4.32.