PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Time Domain Representation of Continuous and Discrete Signals 67


axis([-1 5 -.2 4.3]);
subplot(2,2,3);
f3=-1.*fn; % creates -f(n)
plot(n,f3);title(‘-f(n) vs. n’);
axis([-1 5 -2.3 .2]);
ylabel(‘Amplitude’);xlabel(‘time index n’);
subplot(2,2,4)
shiftn = n+2;plot(shiftn, fn)
title(‘f(n-2) vs. n’);
ylabel(‘Amplitude’);xlabel(‘time index n’);
axis([0 5 -.5 2.5]);
disp(‘*********** RESULTS ARE : ************************’)
Energy _ fn = sum(fnsquare)
disp(‘ ’)
Power _ fn = Energyfn/length(n) % asuming, f (n) is periodic T=20
disp(‘(in joules and watts)’)
disp(‘*************************************************’)
The script fi le f_ n is executed and the results are shown as follows and in Figure 1.57.
**************** RESULTS ARE:*******************
Energy _ fn =
34.8500
Power _ fn =
0.1734
(in joules and watts)
*************************************************

f(n) versus n

−f(n) versus n f(n−2) versus n

[f(n)]^2 versus n

2

1.5

0.5

0

0

−0.5

2.5

1.5

0.5
0

0

−0.5

1

2

− 1

−1.5
− 2

0 2 4

024

1
Amplitude

Amplitude Amplitude

Amplitude

4

3

2

1

0
024

time index n

12345
time index n
FIGURE 1.57
Plots of f(n), f(n)^2 , −f(n), and f(n − 2) of Example 1.8.
Free download pdf