PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Time Domain Representation of Continuous and Discrete Signals 69


Example 1.10

Create the script fi le period_seq that returns the plots of the following periodic sequences
defi ned as follows over one period:

a. f 1 (n) = (^) ∑ (^) k= 0
25
(–1)k δ(n – k), for 0 ≤ k ≤ 25.
b.fn
nn
(^2) n
01
01 2
()
sin( )

 for
for 



over 0 ≤ n ≤ 6.
c. f 3 (n) = n, with period − 4 ≤ n ≤ 4 , over − 5 ≤ n ≤ 30.
d. Random periodic function f 4 (n), with a period of 1, over − 1 ≤ n ≤ 3.
MATLAB Solution
n = 1:25;
f1n = [(-1).^n.ones(1,25)];
yzero = zeros(1,25);
subplot(2,2,1);
stem(n,f1n);hold on; plot(n,yzero);
ylabel(‘Amplitude [f1(n)]’);xlabel(‘n’);
axis([-1 25 -1.3 1.3])
title (‘f1(n) vs. n’);
% part (b)
nn = 0:0.1
pi:0.9pi;
Y = sin(nn);
f2n= [Y zeros(1,10) Y zeros(1,10) Y zeros(1,10)]; m=0:.1:5.9;
subplot(2,2,2);stem(m, f2n);axis([-.1 6 -.1 1.3]);
ylabel(‘Amplitude [f2(n)]’); xlabel(‘n’);
title(‘f2(n) vs. n’);
% part c
f3 = -4:1:4; f3n = [f3 f3 f3 f3];
nnn = linspace(-4,28,36);
subplot(2,2,3); yzer =zeros(1,length(nnn));
stem(nnn, f3n);hold on; plot(nnn,yzer);
xlabel(‘n’);axis([-5 30 -5 5]);
ylabel(‘Amplitude [f3(n)]’);
title(‘f3(n) vs. n’)
% part d
f4 = 10
rand(1,10) ;f4n=[f4 f4 f4 f4];
n4 =linspace(-1,3,40);
s u b plot (2,2,4);y z e =z e r o s(1,le n g t h(n4));
stem(n4,f4n);hold on; plot(n4,yze);
axis ([-1 3 -1 11]);xlabel(‘n’);
ylabel(‘Amplitude [f4(n)]’);
title(‘f4(n) vs. n’)
The script fi le period_seq is executed and the results are shown in Figure 1.59.

Free download pdf