PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Analog and Digital Filters 633


Example 6.10

Test the Butterworth LP digital fi lter of Example 6.7 by applying as an input the signal

x(t) = 2 + cos(0.2 t) + cos( (^4) t ) sampled every T = 0.3 s.
Create the script fi le inpout that returns the following plots:
a. x(t) versus t
b. y(t) versus t
c. x(nT) versus nT
d. y(nT) versus nT
where y denotes the fi lter’s output.
MATLAB Solution
% Script file: inp
out
Pz = [0.0380 0.1141 0.1141 0.0380];
Qz = [1.0000 -1.3445 0.8215 -0.172];
n = 0:1:100; %Discrete time sequence
T = 0.3;
input = 2 + cos(0.2T.n)+cos(4T.n);
output= filter(Pz,Qz,input);
t = 0:.05:8; % time range
inputa = 2 + cos(0.2.t) + cos(4.t);
subplot(2,2,1)
plot(t,inputa)
xlabel(‘t in sec’)
ylabel(‘Amplitude’)
title(‘[x(t) = 2 + cos(0.2.t) + cos (4.t)] vs. t’)
axis([0 5 0 5])
subplot(2,2,2)
plot(nT,output)
xlabel(‘t in sec’)
ylabel(‘Amplitude’)
title(‘y(t) vs. t’);axis([0 8 0 4])
subplot(2,2,3)
stem(n
T,input)
xlabel(‘time index nT’)
ylabel(‘Amplitude’)
title(‘x(nT) vs. nT’);
axis([0 5 0 5])
subplot(2,2,4)
stem(n*T,output)
xlabel(‘time index nT’)
ylabel(‘Amplitude’)
title(‘y(nT) vs. nT’);
axis([0 8 0 4])
The script fi le inp_out is executed and the results are shown in Figure 6.60.




inp _ out
Note that the fi lter’s output presents a high DC component plus the low frequency of the
input with some traces of the high frequency.



Free download pdf