PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

66 Practical MATLAB® Applications for Engineers


Example 1.8

Let f(n) be given by

fn

nn
n
nn

()

00 2
10 1
12





 and







Create the script fi le f_ n that returns the following:
a. Plot of [f(n)] versus n
b. Plot of [f(n)]^2 versus n
c. Plot of [-f(n)] versus n
d. Plot of [f(n − 2)] versus n
e. The energy of [f(n)]
f. The power of [f(n)]

MATLAB Solution
% Script file: f _ n
fn = [zeros(1,100) ones(1,10) [1.1:0.1:2] zeros(1,81)];
n = -10:0.1:10;
subplot(2,2,1);
plot(n, fn);
title(‘f(n) vs n’);ylabel(‘Amplitude’);
axis([-1 5 -.2 2.3]);
subplot(2,2,2);
fnsquare = fn.^2;
plot(n, fnsquare);ylabel(‘Amplitude’);
title(‘[f(n)]^2 vs. n’);

FIGURE 1.56
Plots of f 5 (t), f 6 (t), f 7 (t), and f 8 (t) of Example 1.7.


f5(t) versus t, (Example 1.7)

f7(t) versus t, (Example 1.7) f8(t) versus t, (Example 1.7)

f6(t) versus t, (Example 1.7)
0.2

0.1

0

−0.1

0.2

0.1

−0.1

0

f5(t)

f5(t) f5(t)

1 2 3 4

1

1.5

1
0.5

0
−0.5
− 5 05

f5(t)

2 2.5 3 3.5 4
t

0.5

−0.5
− 1
− 5 05

0

t
Free download pdf