PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Time Domain Representation of Continuous and Discrete Signals 59


MATLAB Solution
% Script file: analog _ func
t = -1:0.01:5;
t0 = 0;
ut = stepfun(t,t0); % u(t)
t0 =1;
ut1 =stepfun(t,t0); % u(t-1)
t0 = 2;
ut2 = stepfun(t,t0); % u(t-2)
t0 = 3;
ut3 = -3 * stepfun(t,t0); % -3u(t-3)
fn = ut+ut1+ut2+ut3;
plot(t,fn);
axis([-1 5 -1 4])
title(‘f(t) = u(t) + u(t-1) + u(t-2) - 3u(t-3) ‘)
xlabel(‘time t’)
ylabel(‘Amplitude [f(t)]’)
The script fi le analog-func is executed and the result is shown in Figure 1.50.

Example 1.3

Create the script fi le sequences that uses MATLAB to verify graphically that the discrete
sequences f 1 (n) and f 2 (n), defi ned as follows, over the range − 10 ≤ n ≤ 10 are equal:
ƒ 1 (n) = 3 u(−n) * u(n + 5)
and
ƒ 2 (n) = 3[u(n + 5) − u(n + 1)]

MATLAB Solution
% Script file: sequences
clc; clf;
yzero = [zeros(1,21)]; n=-10:10;
n0 = 0;un = stepfun(n, n0);

FIGURE 1.50
Plot of Example 1.2.

− 1 0 1 2 3 4 5

− 1

−0.5

0

0.5

1

1.5

2

2.5

3

3.5

4
f(t) = u(t) + u(t−1) + u(t−2) − 3u(t−3)

time (t)

Amplitude [f(t)]
Free download pdf