66
Practical MATLAB
® Applications for Engineers
Example 1.8
Let f(n) be given by
f n
n
n
n
n
n
( ) ϭ
0
0
2
1 0
1
1
2
Ͻ
Ͼ
Ͻ Յ
Ͻ Յ
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
0
5
f5(t)
2
2.5
3
3.5
4
t
0.5
−0.5
−1
−5
0
5
0
t
CRC_47760_CH001.indd 66
CRC_47760_CH001.indd 66
7/25/2008 4:16:24 PM
7/25/2008 4:16:24 PM
Précédent

- 77/708

Suivant