p3_dsp
TRANSCRIPT
-
8/8/2019 p3_dsp
1/14
DSP MatLab: Assessed exercise IIR and FIR filter design
IIRlow-pass filter Butterworth
signal sampled frequency = 40kHz
cut-off frequency = 8kHz.transition band = 4kHz.
gain in pass-band = 0dB.
attenuation in stop-band = 40dB.
This difference equation defines how the input signal is related to the output signal
where P is the forward filter order, bi are the forward filter coefficients, Q is the feedback
filter order, ai, are the feedback filter coefficients, x(n) is the input signal and y(n) is theoutput signal.
Filter order
n = 8
n Factors of Polynomial Bn(s)8 = (s2 + 0.3902s + 1)(s2 + 1.1111s + 1)(s2 + 1.6629s + 1)(s2 + 1.9616s + 1)
LP PreWarping
Wd = 2 pi 8000
2 Wd delta(t)Walfa = --------- tan ---------------
delta(t) 22 pi 8000 (1/40000)
Walfa = 2(40 000) tan -------------------------- = 58123.40 = 2 pi 58123
21
H(s) = -------------------------------------------------------------------------------------(s2 + 0.3902s + 1)(s2 + 1.1111s + 1)(s2 + 1.6629s + 1)(s2 + 1.9616s + 1)
s = s / 2 pi 58123
Bilinear transformation
2 (1 Z -)s = ----------------------------
delta (t) (1 + Z -)
b = 0.0001 0.0008 0.0028 0.0056 0.0070 0.0056 0.0028 0.0008 0.0001a = 1.0000 -1.5906 2.0838 -1.5326 0.8694 -0.3192 0.0821 -0.0122 0.0009
0.0001+0.0008Z-+0.0028Z-+0.0056Z-+0.0070Z-+0.0056Z-+0.0028Z-6+0.0008Z+0.0001Z-HLP(z) = --------------------------------------------------------------------------------------------------------------------
1-1.5906Z-+2.0838Z--1.5326Z-+0.8694Z--0.3192Z-+0.0821Z-6-0.0122Z-+0.0009Z-
Luis Alfredo Mateos Guzman
1
-
8/8/2019 p3_dsp
2/14
DSP MatLab: Assessed exercise IIR and FIR filter design
IIRlow-pass filter Butterworth
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-400
-300
-200
-100
0Butterworth Lowpass Filter, Magnitude,order=8
frequency
|H(f)|dB
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-4
-2
0
2
4Butterworth Lowpass Filter, Phase,order=8
frequency
angleH(f)rad
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
ImaginaryPart
Pole-Zero, Butterworth Low Pass Filter
% Butterworth Filter[n,fn] =buttord(frequency_pass_band,frequency_stop_band,ripple_pass_band,ripple_stop_band)
[b,a] = butter(n,fn)
[H,w] = freqz(b,a,512,40000);
figure;% Magnitude Responseplot(w, 20*log10(abs(H)));title(['Butterworth Lowpass Filter,Magnitude,order=',num2str(n)]);
% Plotting the phase responseplot(w,angle(H));title(['Butterworth Lowpass Filter,
Phase,order=',num2str(n)]);grid on
% Pole-Zero Plotz = roots(b);p = roots(a);figure;zplane(z,p);title('Pole-Zero, Butterworth Low Pass Filter');
b = 0.0001 0.0008 0.0028 0.0056 0.0070 0.0056 0.0028 0.0008 0.0001a = 1.0000 -1.5906 2.0838 -1.5326 0.8694 -0.3192 0.0821 -0.0122 0.0009
Luis Alfredo Mateos Guzman
2
-
8/8/2019 p3_dsp
3/14
DSP MatLab: Assessed exercise IIR and FIR filter design
IIRhigh-pass filter Butterworth
signal sampled frequency = 40kHz
cut-off frequency = 12kHz.transition band = 4kHz.
gain in pass-band = 0dB.
attenuation in stop-band = 40dB.
Filter order
Is the same formula used in the low-pass filter, we use the value obtained in the low-passfilter
n = 8
n Factors of Polynomial Bn(s)
8 = (s2 + 0.3902s + 1)(s2 + 1.1111s + 1)(s2 + 1.6629s + 1)(s2 + 1.9616s + 1)
Low-Pass to High-Pass Filter
Since the High-Pass filter has a cut-off frequency of 8KHz, the filter transfer function may beobtained from the Low-Pass filter, HLP(Z) by substitution Z to -Z.
From the HLP(Z):
b = 0.0001 0.0008 0.0028 0.0056 0.0070 0.0056 0.0028 0.0008 0.0001
a = 1.0000 -1.5906 2.0838 -1.5326 0.8694 -0.3192 0.0821 -0.0122 0.0009
0.0001+0.0008Z-+0.0028Z-+0.0056Z-+0.0070Z-+0.0056Z-+0.0028Z-6+0.0008Z+0.0001Z-HLP(z) = --------------------------------------------------------------------------------------------------------------------
1-1.5906Z-+2.0838Z--1.5326Z-+0.8694Z--0.3192Z-+0.0821Z-6-0.0122Z-+0.0009Z-
This yields the High-Pass filter transfer function HHP(Z):
b_HP = 0.0001 -0.0008 0.0028 -0.0056 0.0070 -0.0056 0.0028 - 0.0008 0.0001a_HP = 1.0000 1.5906 2.0838 1.5326 0.8694 0.3192 0.0821 0.0122 0.0009
0.0001-0.0008Z-+0.0028Z--0.0056Z-+0.0070Z--0.0056Z-+0.0028Z-6-0.0008Z+0.0001Z-HLP(z) = -------------------------------------------------------------------------------------------------------------------
1+1.5906Z-+2.0838Z-+1.5326Z-+0.8694Z-+0.3192Z-+0.0821Z-6+0.0122Z-+0.0009Z-
Luis Alfredo Mateos Guzman
3
-
8/8/2019 p3_dsp
4/14
DSP MatLab: Assessed exercise IIR and FIR filter design
IIRhigh-pass filter Butterworth
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-400
-200
0
200Butter Highpass Filter, Magnitude ,order=8
f
|H(f)|
dB
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-4
-2
0
2
4Butter Highpass Filter, Phase ,order=8
f
angleH(f)rad
-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
ImaginaryPart
Pole-Zero Butter HighPass Filter
[n,fn] =buttord(frequency_pass_band,frequency_stop_band,ripple_pass_band,ripple_stop_band);
[z,p,k] = buttap(n);N = n;b = k*poly(z); % Numerator polynomiala = poly(p); % Demnominator[b1,a1] = lp2hp(b,a,2*pi*12000); % LowPass to High Passtransformation
[b2,a2] = bilinear(b1,a1,40000, 12000); %Bilinear Transformation , frequency_pass_band=Pre-warping freq.%Or trying the Z -> -Z%a2 = [1.0000 1.5906 2.0838 1.53260.8694 0.3192 0.0821 0.0122 0.0009];
%b2 = [0.0001 -0.0008 0.0028 -0.00560.0070 -0.0056 0.0028 - 0.0008 0.0001];
[H3,w3] = freqz(b2,a2,512,40000);figure;
% Pole-Zero Plotz = roots(b2);p = roots(a2);figure;zplane(z,p);title('Pole-Zero, Butterworth HighPass Filter');
b_HP = 0.0001 -0.0008 0.0028 -0.0056 0.0070 -0.0056 0.0028 - 0.0008 0.0001a_HP = 1.0000 1.5906 2.0838 1.5326 0.8694 0.3192 0.0821 0.0122 0.0009
Luis Alfredo Mateos Guzman
4
-
8/8/2019 p3_dsp
5/14
DSP MatLab: Assessed exercise IIR and FIR filter design
IIRband-pass filter Butterworth
signal sampled frequency = 40kHzcut-off frequency = 12kHz.
transition band = 8kHz.
gain in pass-band = 0dB.attenuation in stop-band = 40dB.
Low-Pass to Band-Pass Filter
For the Band-Pass filter, the prototype Low-Pass filter should have cut-off frequency of
WCLP = 2 pi (12 000 4 000)
WCLP = 2 pi 8000
Thus the Low-Pass filter HLP(Z) may also be used to design the Band-Pass filter. The otherparameter that is required is alfa, which may be found:
pi(2 pi 12000) + 2 pi 8000Cos --------------------------------
2 pi 40000alfa = -----------------------------------------------------
pi(2 pi 12000) - 2 pi 8000Cos --------------------------------
2 pi 40000
The Low-Pass to Band-Pass transformation then simplifies to Z- to -Z-
From the HLP(Z):
b = 0.0001 0.0008 0.0028 0.0056 0.0070 0.0056 0.0028 0.0008 0.0001a = 1.0000 -1.5906 2.0838 -1.5326 0.8694 -0.3192 0.0821 -0.0122 0.0009
0.0001+0.0008Z-+0.0028Z-+0.0056Z-+0.0070Z-+0.0056Z-+0.0028Z-6+0.0008Z+0.0001Z-HLP(z) = --------------------------------------------------------------------------------------------------------------------
1-1.5906Z-+2.0838Z--1.5326Z-+0.8694Z--0.3192Z-+0.0821Z-6-0.0122Z-+0.0009Z-
This yields the Band-Pass filter transfer function HBP(Z):
From matlab:
HBP(Z)
a = [1.0000 -0.8085 3.2043 -1.8508 3.7585 -1.4247 1.9031 -0.3663 0.3486];b = [0.0010 -0.0000 -0.0040 -0.0000 0.0060 -0.0000 -0.0040 -0.0000 0.0010];
Luis Alfredo Mateos Guzman
5
-
8/8/2019 p3_dsp
6/14
DSP MatLab: Assessed exercise IIR and FIR filter design
IIRband-pass filter Butterworth
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-400
-200
0
200Butterworth BandPass Filter, Magnitude response,order=8
f
|H(f)|dB
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-4
-2
0
2
4Butterworth BandPass Filter, Phase response,order=8
f
angleH(f)rad
frequency_sample = 40000;frequency_pass_band1 = 8000;
frequency_pass_band2= 12000;
wo =2*pi*sqrt(frequency_pass_band1*frequency_pass_band2);%Centre Frequency rad/s wo =2*pi*sqrt(Fpb1*Fpb2);
bw = (frequency_pass_band2-frequency_pass_band1)*2*pi; %Bandwidthrad/s bw = (Fpb2-Fpb1)*2*pi;N =4;[z,p,k] = buttap(N);b = k*poly(z); % Numerator polynomiala = poly(p); % Demnominator
[bt,at] = lp2bp(b,a,wo,bw); % Low Pass toBandpass Transformation[b2,a2] = bilinear(bt,at,frequency_sample,frequency_pass_band1); % BilinearTransformation matchinglower pass frequency
%Butterworth Filter[H,w] = freqz(b2,a2,512,40000);
% Pole-Zero Plotz = roots(b2);p = roots(a2);figure;
zplane(z,p);title('Pole-Zero, Butterworth BandPass Filte
a = 1.0000 -0.8085 3.2043 -1.8508 3.7585 -1.4247 1.9031 -0.3663 0.3486b = 0.0010 -0.0000 -0.0040 -0.0000 0.0060 -0.0000 -0.0040 -0.0000 0.0010
Luis Alfredo Mateos Guzman
6
-
8/8/2019 p3_dsp
7/14
DSP MatLab: Assessed exercise IIR and FIR filter design
FIRlow-pass filter Hanning
signal sampled = 40kHz
cut-off frequency = 8kHz.transition band = 4kHz.
gain in pass-band = 0dB.
attenuation in stop-band = 40dB.
This difference equation defines how the input signal is related to the output signal
where P is the filter order, bi are the forward filter coefficients, x(n) is the input signaland y(n) is the output signal.
HD(W) = 0 {2 pi /5 < w < pi / delta (t)}
HD(W) = 1 {0
-
8/8/2019 p3_dsp
8/14
DSP MatLab: Assessed exercise IIR and FIR filter design
FIRlow-pass filter Butterworth
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500
-1000
-500
0
Normalized Frequency ( rad/sample)
Phase(degrees)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150
-100
-50
0
50
Normalized Frequency ( rad/sample)
Magnitude(dB)
0 50 100 150 200 250 300 350-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4FIR
N / 100
% 1 Design a low pass filter FIR Filter type% Filter Specs
% Hanning = 3.1 / delta t = 3.1 x 40000 /4000 = 31
%15 1 15n=[-15:1:15];
%Stop-band = 8000 Hz%Stop-band = 8 pi / 20 delta t = 2 pi / 5delta(t)
y = 2/5*sinc(2/5.*n);
% Wn = (1 + cos (31 pi / 15)w=0.5*(1+cos(n.*pi/15));
FIR=y.*wfigure;plot(FIR)grid on;title(['FIR']);xlabel('N / 100');ylabel('');% plot the magnitud and phasefreqz(FIR)
% help to plot allfvtool(FIR);
[a values]Columns 1 through 7 0 -0.0002 -0.0006 0.0015 0.0046 -0.0000 -0.0116
Columns 8 through 14 -0.0105 0.0148 0.0330 -0.0000 -0.0632 -0.0564 0.0895
Columns 15 through 21 0.2994 0.4000 0.2994 0.0895 -0.0564 -0.0632 -0.0000
Columns 22 through 28 0.0330 0.0148 -0.0105 -0.0116 -0.0000 0.0046 0.0015
Columns 29 through 31 -0.0006 -0.0002 0
FIRhigh-pass filter Hanning
Luis Alfredo Mateos Guzman
8
-
8/8/2019 p3_dsp
9/14
DSP MatLab: Assessed exercise IIR and FIR filter design
signal sampled frequency = 40kHz
cut-off frequency = 12kHz.transition band = 4kHz.
gain in pass-band = 0dB.attenuation in stop-band = 40dB.
This formula defines how the input signal is related to the output signal
where P is the filter order, bi are the forward filter coefficients, x(n) is the input signaland y(n) is the output signal.
HD(W) = 0 {0 < w < pi /5 }
HD(W) = 1 {pi /5
-
8/8/2019 p3_dsp
10/14
DSP MatLab: Assessed exercise IIR and FIR filter design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500
-1000
-500
0
500
Normalized Frequency ( rad/sample)
Phase(degrees)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150
-100
-50
0
50
Normalized Frequency ( rad/sample)
Magnitude(dB)
0 50 100 150 200 250 300 350-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4FIR
N / 100
% 1 Design a high pass filter FIR Filter type% Filter Specs% Hanning = 3.1 / delta t = 3.1 x 40000 /4000 = 31n=[-15:1:15]
%Stop-band = 12000 Hz%Stop-band = 12 pi / 20 delta t = 3 pi / 5delta t
const=2/5;part1=sinc(n/5)part2=cos(4*pi*n/5)y=const.*part1.*part2
%y = 2/5*sinc(2/5.*n);
figureplot (y)grid on;title(['FIR']);xlabel('N / 100');ylabel('');
% Wn = (1 + cos (31 pi / 15)
w=0.5*(1+cos(n.*pi/15));
[a values]Columns 1 through 7 0 -0.0002 0.0006 0.0015 -0.0046 -0.0000 0.0116
Columns 8 through 14 -0.0105 -0.0148 0.0330 0.0000 -0.0632 0.0564 0.0895
Columns 15 through 21 -0.2994 0.4000 -0.2994 0.0895 0.0564 -0.0632 0.0000
Columns 22 through 28 0.0330 -0.0148 -0.0105 0.0116 -0.0000 -0.0046 0.0015
Columns 29 through 31 0.0006 -0.0002 0
FIRband-pass filter Hanning
Luis Alfredo Mateos Guzman
10
-
8/8/2019 p3_dsp
11/14
DSP MatLab: Assessed exercise IIR and FIR filter design
signal sampled frequency = 40kHzcut-off frequency = 12kHz.
transition band = 8kHz.gain in pass-band = 0dB.
attenuation in stop-band = 40dB.
HD(w) = 0 {0 < w < pi /10,4 pi /10 < w
-
8/8/2019 p3_dsp
12/14
DSP MatLab: Assessed exercise IIR and FIR filter design
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1000
-500
0
500
Normalized Frequency ( rad/sample)
Phase(degrees)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150
-100
-50
0
Normalized Frequency ( rad/sample)
Magnitude(dB)
0 50 100 150 200 250 300 350-0.4
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4FIR
N / 100
% 1 Design a band pass filter FIR Filter type% Filter Specs% Hanning = 3.1 / delta t = 3.1 x 40000 /4000 = 31n=[-15:1:15]
%Stop-band1 = 12000 Hz and%Stop-band2 = 4000Hz%Stop-band1 = 12 pi / 40 delta t = 3 pi / 10%Stop/band2 = 1 pi / 10 delta t
const=1/5;part1=sinc(n/10)part2=cos(pi*n/2)
y=const.*part1.*part2
figureplot (y)grid on;
title(['FIR']);xlabel('N / 100');ylabel('');
% Wn = (1 + cos (31 pi / 15)w=0.5*(1+cos(n.*pi/15));FIR=y.*w
[a values]Columns 1 through 7 0 0.0005 0.0000 -0.0030 0.0000 -0.0000 0.0000
Columns 8 through 14 0.0209 -0.0000 -0.0660 0.0000 0.1263 -0.0000 -0.1790
Columns 15 through 21 0.0000 0.2000 0.0000 -0.1790 -0.0000 0.1263 0.0000
Columns 22 through 28 -0.0660 -0.0000 0.0209 0.0000 -0.0000 0.0000 -0.0030
Columns 29 through 31 0.0000 0.0005 0
Bonus work.
Luis Alfredo Mateos Guzman
12
-
8/8/2019 p3_dsp
13/14
-
8/8/2019 p3_dsp
14/14