PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

618 Practical MATLAB® Applications for Engineers


w =-5*a:10000:5*a;
t =linspace(0,2e-3,1000);
f0 = 1000; % input frequencies
f1 = 35000;
input0 =5.*cos(2*pi*f0.*t);input1=12.5*sin(2*pi*f1.*t);
input = input0+input1; % input signal
H0lp = a./(j*2*pi*f0+a); % mag of LPF at f = f0
H1lp = a./(j*2*pi*f1+a); % mag of LPF at f = f1
resp0lp = abs(H0lp).*(cos((2*pi*f0.*t)+angle(H0lp)));
resp1lp = abs(H1lp).*(sin((2*pi*f1.*t)+angle(H0lp)));
outputlp = resp0lp+resp1lp; % output of LPF
H0hp = j*2*pi*f0./(j*2*pi*f0+a); % mag of HPF at f = f0
H1hp = j*2*pi*f1./(j*2*pi*f1+a); % mag of HPF at f = f1
resp0hp = abs(H0hp).*(cos((2*pi*f0.*t)+angle(H0hp)));
resp1hp = abs(H1hp).*(sin((2*pi*f1.*t)+angle(H0hp)));
outputhp = resp0hp+resp1hp; % output of HPF

figure(1)
subplot(3,1,1)
plot(t,input);
axis([0 2e-3 -18 18]);
ylabel(‘Input Amplitude’);
subplot(3,1,2)
plot(t,outputlp);
ylabel(‘Output Amplitude’);
axis([0 2e-3 -1.5 1.5]);
subplot(3,1,3)
plot(t,input0);
axis([0 2e-3 -6.5 6.5]);
ylabel(‘Amplitude’);
xlabel(‘time in sec’)

figure(2)
subplot(3,1,1)
plot(t,input);
axis([0 2e-3 -18 18]);
ylabel(‘Input Amplitude’);
subplot(3,1,2)
plot(t,outputhp);
ylabel(‘Output Amplitude’);
axis([0 .1e-3 -1.2 1.2]);
subplot(3,1,3)
plot(t,input1);
a xis([0 .1e-3 -12.5 12.5]);
ylabel(‘Amplitude’);
xlabel(‘time in sec’)

Back in the command window, the script fi le test_fi lter is executed and the fi lters’ out-
puts are shown in Figures 6.45 and 6.46.
Note that the LPF output consists of a 1000 Hz sinusoidal wave plus a small high-
frequency 35 kHz ripple. The HPF passes the 35 kHz frequency, while completely
removing the low-frequency component of 1000 Hz.
Free download pdf