PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Time Domain Representation of Continuous and Discrete Signals 89


Create the script fi le multiplex that returns the following plots:

a. f 1 (t) and f 2 (t) are sampled with a sampling rate of Ts = 2 π/100.
b. The multiplex signals of part a.

MATLAB Solution
t = linspace(0,2*pi,100);
f1 = cos(2*t)+2*sin(3*t);
f2 = 10*sin(2*t).*exp(-t/pi);
yzero = zeros(1,100);

figure(1)
subplot(2,2,1)
plot(t,f1,’dk’,t,f2,’sk’,t,yzero);
a xis([0 2*pi -6 10])
legend(‘f1(t)’,’f2(t)’)
title(‘f1(t) vs. n and f2(t) vs. t’)
ylabel(‘Amplitude’); xlabel(‘time index n’)
subplot(2,2,2)
a = [1 0 1 0 1 0 1 0 1 0];
aa = [a a a a a a a a a a];
b = [0 1 0 1 0 1 0 1 0 1];
bb = [b b b b b b b b b b];
f1samp = f1.*aa;
f2samp = f2.*bb;
stem(t(1:2:100),f1(1:2:100));hold on; plot(t,yzero);
title(‘f1(n) vs. n’)
a x is([0 2* pi -4 5]);yla b e l(‘A m plitu d e’);
xlabel (‘time index n’);
subplot(2,2,3)
stem(t(1:2:100),f2(1:2:100));hold on;plot(t,yzero)
title(‘f2(n)vs. n’)
a xis([0 2*pi -6 10]);yla bel(‘A m plitude’)
xlabel(‘time index n’)
subplot(2,2,4);
stem(t(1:2:100),f1(1:2:100),‘d’);hold on;
stem(t(1:2:100),f2(1:2:100),‘s’);
hold on; plot(t,yzero);
a xis([0 2*pi -6 10]);
title(‘ [Multiplexed samples of f1(n) and f2(n)] vs. n’);
legend(‘f1(t)’,‘f2(t)’)
xlabel(‘time index n’)

figure(2)
plot(t(1:2:50),f1(1:2:50),t(1:2:50),f2(1:2:50),t,yzero);
hold on; stem(t(1:2:50),f1(1:2:50),‘d’); hold on;
stem(t(2:2:50),f2(2:2:50),‘s’);
title(‘ [Enlarge alternating (multiplexed) samples from f1(n)
and f2(n)] vs. n ‘)
axis([0 3.1 -6 10]);ylabel(‘Amplitude’);
xlabel(‘time index n’)

Back in the command window the script fi le multiplex is executed and the results are
shown in Figures 1.75 and 1.76.
Free download pdf