PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Time Domain Representation of Continuous and Discrete Signals 37


R.1.114 For example, create the script fi le rect_pulses that returns rectangle plots with the
following specs:
a. f 1 (t) versus t, with mag[f 1 (t)] = 1 and width = 1
b. f 2 (t) versus t, with mag[f 2 (t)] = 2 and width = 3
c. f 3 (t) versus t, with mag[f 3 (t)] = 3 and width = 6
d. f 4 (t) versus t, with mag[f 4 (t)] = 4 and width = 9

MATLAB Solution
% Script file: rect_ pulses
t = -6:.1:6;
f1 = rectpuls(t,1);
f2 = 2*rectpuls(t,3);
f3 = 3*rectpuls(t,6);
f4 = 4*rectpuls(t,9);
subplot(2,2,1)
plot (t,f1)
ylabel (‘ Amplitude [f1(t)]’);xlabel(‘t (time)’);
axis ([-6 6 -0.5 1.5])
title(‘Rectpuls(t,1) vs. t’)
subplot(2,2,2)
plot(t,f2)
ylabel( ‘Amplitude [f2(t)]’); xlabel(‘t (time)’);
axis([-6 6 -0.5 2.5])
title(‘2*Rectpuls(t,3) vs. t’)
subplot(2,2,3)

tripuls(t,3) versus t

3*tripuls(t,10) versus t

1.5

1

0.5

0

−0.5
− 5 0 5

Amplitude [f1(t)]

Amplitude [f3(t)]

t (time)

Amplitude [f2(t)]

2.5
2
1.5
1
0.5

−0.5
− 55

0

0

t (time)

2*tripuls(t,5) versus t

4*tripuls(t,12) versus t
5 4 3 2 1 0

− 5 0 5

t (time)

Amplitude [f4(t)]

4

3

2

1

− 5 0 5

(^0) t (time)
FIGURE 1.33
Plot of the function tripuls of R.1.112.

Free download pdf