PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Fourier and Laplace 383


plot(t,Har _ 123456)
axis([0 2 -.6 .6])
title(‘Fund.+2nd.+3rd.+4th.+5th.+6th.Harm. ‘);
ylabel(‘Amplitude’);
xlabel(‘time (in sec)’);

figure(4); % Figure 4.36; part (d)
plot(t,Harmonic _ 1,t,Har _ 12,t,Har _ 123,t,Har _ 1234,t,Har _ 12345,t,
Har _ 123456);
title(‘Approximations of the sawtooth wave by sum of harmonics’);
ylabel(‘Amplitude’);
xlabel(‘time (in sec)’);

figure(5) % Figure 4.37; part(e)
x =0:.01:T;y =0:.01:T-.01;
trian0 =.5.*x-.5;trian1 =.5.*y-.5;
triag = [trian0 trian1];
error1 = triag-Harmonic _ 1;
error2 = triag-Har _ 12;
error3 = triag-Har _ 123;
error4 = triag-Har _ 1234;
error5 = triag-Har _ 12345;
error6 = triag-Har _ 123456;
subplot(3,2,1)
plot(t,error1)
title(‘error1(t) = sawtooth wave-harmonics 1’)
ylabel(‘Amplitude’)
subplot(3,2,2)
plot(t,error2)
title(‘error2(t) = sawtooth wave-harmonics 1,2’)
ylabel(‘Amplitude’)
subplot(3,2,3)
plot(t,error3)
title(‘error3(t) = sawtooth wave-harmonics 1,2,3’)
ylabel(‘Amplitude’)
subplot(3,2,4)
plot(t,error4)
title(‘error4(t) = sawtooth wave-harmonics 1,2,3,4’)
ylabel(‘Amplitude’)
subplot(3,2,5)
plot(t,error1)
title(‘error5(t) = sawtooth wave-harmonics 1,2,3,4,5’)
ylabel(‘Amplitude’)
xlabel(‘time (in sec)’);
subplot(3,2,6)
plot(t,error6)
title(‘error6(t)=sawtooth wave-harmonics 1,2,3,4,5,6’)
ylabel(‘Amplitude’)
xlabel(‘time (in sec)’);

The script fi le sawtooth_fourier is executed and the results are shown in Figures 4.33
through 4.37.

>> sawtooth _ fourier
Free download pdf