PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

526 Practical MATLAB® Applications for Engineers


and
f(n) = f 1 (n) + f 2 (n) + f 3 (n)
Create the script fi le linearity that returns the following plots:
a. fi gure(1): [f(n) = f1(n) + f2(n) + f3(n)] versus n, abs{DFT[f(n)]} versus W, and
angle{DFT[f(n)]} versus W (Figure 5.39)
b. fi gure(2): abs{DFT[f1(n)} versus W, abs{DFT[f 2(n)} versus W, and abs{DFT[f3(n)} versus
W (Figure 5.40)
c. fi gure(3): angle{DFT[f1(n)} versus W, angle {DF T[f 2(n)} versus W, and angle{DFT[f3(n)}
versus W (Figure 5.41)
d. fi gure(4): Let DFT[f(n)] = DFT[f1(n)] + DFT[f2(n)] + DFT[f3(n)]; obtain plots of abs
{DFT[f(n)] = abs{[fft(fn, 16)]} and angle{DFT[f(n)] = angle{fft(fn, 16)} (Figure 5.42)
e. fi gure(5): Let us estimate the error in time and frequency by using the following
relations (Figure 5.43):
i. The error in time = [f1(n) + f2(n) + f3(n)] − ifft{DFT[f(n)]}
ii. error_magnitude_DFT = abs{DFT[f1(n) + f2(n) + f3(n)]} − abs{DFT[f1(n)]} −
abs{DFT[f2(n)]} − abs{DFT [f3(n)]}
iii. error_phase_DFT = angle{DFT[f1(n) + f2(n) + f3(n)]} − {angle[DFT[f 1(n)] +
angle{DFT[f2(n)]} + angle{DFT[f3(n)]}

MATLAB Solution
% Script file: linearity
n = 0:1:15;
f1n = [ones(1,16)]; % discrete time sequences
f2n = (1/3).^n;
f3n = 7*cos(n*pi/3);
fn = f1n + f2n + f3n;
DFT _ fn = fft(fn,16);
figure(1)
subplot (3,1,1)
stem (n,fn);hold on; stairs(n,fn); ylabel(‘Amplitude’);
title(‘ [f(n) = f1(n) + f2(n) + f3(n)] ’)
subplot(3,1,2)
stem(n,abs(DFT _ fn));hold on; stairs(n,abs(DFT _ fn));
ylabel(‘abs [ DFT[f(n)]]’);
subplot (3,1,3)
stem (n,angle(DFT _ fn));hold on;stairs(n,angle(DFT _ fn));
ylabel (‘angle[ DFT [f(n)]]’); xlabel(‘frequency W in rad.’)
figure(2)
DFT _ f1= fft(f1n,16); % magnitude of the DFT’s of the discrete
sequences
DFT _ f2 = fft(f2n,16);
DFT _ f3 = fft(f3n,16);
subplot (3,1,1)
stem(n,abs (DFT _ f1));hold on; stairs(n,abs(DFT _ f1));
ylabel (‘abs [ DFT[f1(n)]]’);
title (‘[Magnitudes of the DFTs of f1(n), f2(n) & f3(n)] vs. W ’)
Free download pdf