Direct-Form I and Direct-form II Realizations Using MATLAB
OBJECTIVES
1. To learn how to implement the designed digital filter using the direct-form I realization.
2. To learn how to implement the designed digital filter using the direct-form II realization.
PROCEDURE:
Study the attached keys for the lab.
Part A: FIR Filter Implementation
FIR system coefficients are given below
Numerator coefficients:
bLP =[
-0.0012 -0.0025 -0.0045 -0.0068 -0.0073 -0.0030 0.0089 …
0.0297 0.0583 0.0907 0.1208 0.1422 0.1500 0.1422 …
0.1208 0.0907 0.0583 0.0297 0.0089 -0.0030 -0.0073 …
-0.0068 -0.0045 -0.0025 -0.0012]
1. Write a MATLAB program to implement the filter using the direct-form I to replace the MALAB routine “filter()”.
2. Generate the sum of the sinusoids for a duration of one second achieved from:
using the sampling rate of 8 kHz.
3. Perform filtering, plot, and verify the input spectrum and output spectrum, respectively.
Part B: IIR Filter Implementation Using Direct-form I
IIR system coefficients are given below:
Numerator coefficients: bBP = [0.0201 0.0000 -0.0402 0.0000 0.0201 ]
Denominator coefficients: aBP = [1.0000 -2.1192 2.6952 -1.6924 0.6414 ]
1. Write a MATLAB program to implement the filter using the direct form I to replace the MTALAB routine “filter()”.
2. Perform filtering for the input generated in Part A (2), plot, and verify the input spectrum and output spectrum.
Part C: IIR Filter Implementation Using Direct-form II
IIR system 2:
Numerator coefficients: bHP =[ 0.0938 -0.3753 0.5630 -0.3753 0.0938 ]
Denominator coefficients: aHP =[ 1.0000 0.0784 0.8267 0.2597 0.1960 ]
1. Write a MATLAB program to implement the filter using the direct-form II to replace the MATLAB routine “filter()”.
2. Perform filtering the input generated in Part A (2), plot, and verify the input spectrum and output spectrum.
sample codes for the FIR filter with direct-form I
__________________________________________________________________
sample =1:1:10; %input test array
x=[ 0 0 0 0]; %input buffer [x(n) x(n-1) ...]
y=[0]; %output buffer [y(n) y(n-1) ... ]
b=[0.2 0.3 0.5 -0.2]; %FIR filter coefficients [b0 b1 ...]
KK=length(b);
for n=1:1:length(sample) % loop processing
for k=KK:-1:2 % shift input by one sample
x(k)=x(k-1);
end
x(1)=sample(n); % get new sample
y(1)=0; % perform FIR filtering
for k=1:1:KK
y(1)=y(1)+b(k)*x(k);
end
out(n)=y(1); %send filtered sample to the output array
end
Compare with the standard MATLAB routine:
yy =filter([ 0.2 0.3 0.5 –0.2],1,sample)
The results of y and yy must be same.
Sample codes for the IIR filter with direct form I
sample = 2:2:20; %input test array
x=[ 0 0 0 ]; % input buffer [x(n) x(n-1) ...]
y=[ 0 0 0]; % output buffer [y(n) y(n-1) ... ]
b=[0.5 0.0 0.5]; % numerator coefficients [b0 b1 ... ]
a=[1 -0.8 0.7]; % denominator coefficients [1 a0 a1 ...]
for n=1:1:length(sample) % processing loop
for k=3:-1:2
x(k)=x(k-1); % shift input by one sample
y(k)=y(k-1); % shift output by one sample
end
x(1)=sample(n); % get new sample
y(1)=0; % digital filtering
for k=1:1:3
y(1)=y(1)+x(k)*b(k);
end
for k=2:3
y(1)=y(1)-a(k)*y(k);
end
out(n)=y(1); %output the filtered sample to output array
end
Compare with the standard MATLAB routine:
yy =filter([ 0.5 0 0.5],[ 1 –0.8 0.7],1,sample)
The results of out(n) and yy must be same.
Sample codes for the IIR filter with direct-form II
____________________________________________________________________
sample =2:2:20; % input test array
x=[0]; %input buffer [x(n)]
y=[0]; %output buffer [y(n)]
w=[0 0 0]; % buffer for w(n) [w(n) w(n-1) ...]
b=[0.5 0.0 0.5]; % numerator coefficients [b0 b1 ...]
a=[1 –0.8 0.7]; % denominator coefficients [1 a1 a2 ...]
for n=1:1:length(sample) % processing loop
for k=3:-1:2
w(k)=w(k-1); %shift w(n) by one sample
end
x(1)=sample(n); % get new sample
w(1)=x(1); % perform IIR filtering
for k=2:1:3
w(1)=w(1)-a(k)*w(k);
end
y(1)=0; % perform FIR filtering
for k=1:1:3
y(1)=y(1)+b(k)*w(k);
end
out(n)=y(1);% send the filtered sample to output array
end
Compare with the standard MATLAB routine:
yy =filter([ 0.5 0 0.5],[ 1 –0.8 0.7],1,sample)
The results of out(n) and yy must be same.
0 comments:
Post a Comment