PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

390 Practical MATLAB® Applications for Engineers


title (‘Fundamental frequency’); ylabel (‘Amplitude of F1’)
subplot (3,2,3); plot (t,F2);
title (‘Second harmonic’); ylabel (‘Amplitude of F2’)
subplot (3,2,4); plot (t,F3);
title (‘Third harmonic’); ylabel (‘Amplitude of F3’);
subplot (3,2,5); plot (t,F4);
title (‘Fourth harmonic’); ylabel (‘Amplitude of F4’); xlabel (‘time (in sec)’)
subplot (3,2,6); plot (t,F5);
title (‘Fifth harmonic’); ylabel (‘Amplitude ofF5’); xlabel (‘time (in sec)’)
figure(2); % see Figure 4.41, part (2b)
plot(t,F1,t,F2,t,F3,t,F4,t,F5);
title(‘Harmonic frequencies of f(t)’)
ylabel (‘Amplitude’);
xlabel (‘time (in sec)’) ;
legend (‘first’,’second’,’third’,’fourth’,’fifth’)
figure(3); % Figure 4.42, part (2c)
F0 =1;
App1 =F0+F1;
App2=App1+F2+F3;
App3=App2+F4;
App4=App3+F5;
subplot(2,2,1);
plot(t,App1)
title(‘Partial sum of first 2 components (F0+F1)’)
ylabel(‘Amplitude’);
subplot(2,2,2);plot(t,App2);
title(‘Partial sum of first 3 harmonics + DC’)
ylabel(‘Amplitude’)
subplot(2,2,3);plot(t’,App3);
title(‘Partial sum of first 4 harmonics + DC’)
xlabel(‘time(in sec)’);ylabel(‘Amplitude’);
subplot(2,2,4);plot(t’,App4);
title(‘Partial sum of first 5 harmonics + DC’)
xlabel(‘time (in sec)’);
ylabel(‘Amplitude’)
figure(4) % Figure 4.43, parts (2d) & (2e)
Fn(6) =.5;
subplot (2,1,1);stem(n.*pi,Fn);
grid on
title(‘line spectrum’);ylabel(‘Amplitude of Fn’)
subplot(2,1,2);stem(n.*pi,Fn.^2);
grid on
title(‘power spectrum’);xlabel(‘frequency’);
ylabel(‘Magnitude of Fn^2’);
disp(‘*********************************’);
disp(‘ Verification of Parsevals theorem’);
disp(‘*********************************’);
Fnsquare=Fn.^2;
Pave=sum(Fnsquare); % parts (2f)
disp(‘ ’);
disp(‘ ’);
disp(‘The average power using summations of Fn(coefficients) is:’)
disp(Pave);
Free download pdf