数字信号处理实验7.docx
《数字信号处理实验7.docx》由会员分享,可在线阅读,更多相关《数字信号处理实验7.docx(15页珍藏版)》请在冰豆网上搜索。
数字信号处理实验7
LaboratoryExercise7
DIGITALFILTERDESIGN
7.1DESIGNOFIIRFILTERS
Project7.1EstimationofIIRFilterOrder
Answers:
Q7.1ThenormalizedpassbandedgeangularfrequencyWpis-0.2
ThenormalizedstopbandedgeangularfrequencyWsis-0.4
ThedesiredpassbandrippleRpis-0.5dB
ThedesiredstopbandrippleRsis-40dB
(1)UsingthesevaluesandbuttordwegetthelowestorderforaButterworthlowpassfiltertobe-8
ThecorrespondingnormalizedpassbandedgefrequencyWnis-0.2469or0.2469pi
(2)Usingthesevaluesandcheb1ordwegetthelowestorderforaType1Chebyshevlowpassfiltertobe-5
ThecorrespondingnormalizedpassbandedgefrequencyWnis-0.2000
(3)Usingthesevaluesandcheb2ordwegetthelowestorderforaType2Chebyshevlowpassfiltertobe-5
[N,Wn]=cheb2ord(0.2,0.4,0.5,40).
ThecorrespondingnormalizedpassbandedgefrequencyWnis-0.4000
(4)Usingthesevaluesandellipordwegetthelowestorderforanellipticlowpassfiltertobe–4
[N,Wn]=ellipord(0.2,0.4,0.5,40).
FromtheaboveresultsweobservethattheEllipticfilterhasthelowestordermeetingthespecifications.
Q7.2ThenormalizedpassbandedgeangularfrequencyWpis-0.6000
ThenormalizedstopbandedgeangularfrequencyWsis-0.3429
ThedesiredpassbandrippleRpis-1dB
ThedesiredstopbandrippleRsis-50dB
(1)UsingthesevaluesandbuttordwegetthelowestorderforaButterworthhighpassfiltertobe-8
[N,Wn]=buttord(Wp,Ws,Rp,Rs).
ThecorrespondingnormalizedpassbandedgefrequencyWnis-0.5647
(2)Usingthesevaluesandcheb1ordwegetthelowestorderforaType1Chebyshevhighpassfiltertobe–5
[N,Wn]=cheb1ord(Wp,Ws,Rp,Rs).
ThecorrespondingnormalizedpassbandedgefrequencyWnis-0.6000
(3)Usingthesevaluesandcheb2ordwegetthelowestorderforaType2Chebyshevhighpassfiltertobe-5
[N,Wn]=cheb2ord(Wp,Ws,Rp,Rs).
ThecorrespondingnormalizedpassbandedgefrequencyWnis–0.3429
(4)Usingthesevaluesandellipordwegetthelowestorderforanelliptichighpassfiltertobe-4
[N,Wn]=ellipord(Wp,Ws,Rp,Rs).
ThecorrespondingnormalizedpassbandedgefrequencyWnis–Wn=0.6000,
FromtheaboveresultsweobservethattheEllipticfilterhasthelowestordermeetingthespecifications.
Project7.2IIRFilterDesign
AcopyofProgramP7_1isgivenbelow:
%程序p7.1
%巴特沃斯带阻滤波器的设计
ws=[0.40.6];wp=[0.30.7];rp=0.4;rs=50;
%估计滤波器的阶数
[N1,wn1]=buttord(wp,ws,rp,rs);
%设计滤波器
[num,den]=butter(N1,wn1,'stop');
%显示传输函数
disp('分子系数是');disp(num);
disp('分母系数是');disp(den);
%计算增益响应
[g,w]=gain(num,den);
%绘制增益响应
plot(w/pi,g);grid
axis([01-605]);
xlabel('\omega/\pi');
ylabel('增益,dB');
title('巴特沃斯带阻滤波器的设计');
Answers:
Q7.5ThecoefficientsoftheButterworthbandstoptransferfunctiongeneratedbyrunningProgramP7_1areasfollows:
分子系数是
Columns1through6
0.03300.00000.29720.00001.18890.0000
Columns7through12
2.77410.00004.16110.00014.16110.0000
Columns13through18
2.77410.00001.18890.00000.29720.0000
Column19
0.0330
分母系数是
Columns1through6
1.00000.00002.66210.00004.14510.0001
Columns7through12
4.12730.00012.89770.00001.43810.0000
Columns13through18
0.50270.00000.11780.00000.01670.0000
Column19
0.0011
Theexactexpressionforthetransferfunctionis–
Thegainresponseofthefilterasdesignedisgivenbelow:
Fromtheplotweconcludethatthedesign符合thespecifications.
Theplotoftheunwrappedphaseresponseandthegroupdelayresponseofthisfilterisgivenbelow:
Hereistheprogramtofindandplottheunwrappedphaseresponseandgroupdelay:
%程序Q7_5B
%巴特沃斯帯阻滤波器的设计
%Plottheunwrappedphaseandthegroupdelay.
Ws=[0.40.6];Wp=[0.20.8];Rp=0.4;Rs=50;
%估计滤波器节数
[N1,Wn1]=buttord(Wp,Ws,Rp,Rs);
%设计滤波器
[num,den]=butter(N1,Wn1,'stop');
%显示传输函数,绘制不卷绕相位
wp=0:
pi/1023:
pi;
wg=0:
pi/511:
pi;
Hz=freqz(num,den,wp);
Phase=unwrap(angle(Hz));
figure
(1);
plot(wp/pi,Phase);
grid;
%axis([01ab]);
xlabel('\omega/\pi');ylabel('UnwrappedPhase(rad)');
title('UnwrappedPhaseResponseofaButterworthBandstopFilter');
%全延时
GR=grpdelay(num,den,wg);
figure
(2);
plot(wg/pi,GR);
grid;
%axis([01ab]);
xlabel('\omega/\pi');ylabel('GroupDelay(sec)');
title('GroupDelayofaButterworthBandstopFilter');
Project7.4EstimationofFIRFilterOrder
Answers:
Q7.13Theestimatedorderofalinear-phaselowpassFIRfilterwiththefollowingspecifications:
ωp=2kHz,ωs=2.5kHz,δp=0.005,δs=0.005,andFT=10kHzobtainedusingkaiordis-
Thepurposeofthecommandceilis-Toroundtheestimatedorderuptothenextlargestinteger;theorderhastobeinteger,soiftheformulareturnsafractionitneedstoberoundeduptothenextwholenumber.
Thepurposeofthecommandnarginis-Todetectifkaiordhasbeencalledwithfour
argumentsorwithfive.Iffive,it’sassumedthatallthefrequenciesareanalogandthat
thelastargumentisthesamplingfrequency.Iffour,thenthesamplingfrequency
defaultsto2,implyingthattheotherfrequencyargumentsareinunitsofcyclespersample.
Project7.5FIRFilterDesign
Answers:
Q7.20TheMATLABprogramtodesignandplotthegainandphaseresponsesofalinear-phaseFIRfilterusingfir1isshownbelow.Thefilterorderisestimatedusingkaiserord.Theoutputdataarethefiltercoefficients.
%程序Q7_20
%线性相位FIR低通滤波器的设计
%满足Q7.13的参数
%写出分子系数
%传输函数
%-增益响应
%-相位响应
%-绘制未卷绕相位响应
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
Fp=2*10^3;
Fs=2.5*10^3;
FT=10*10^3;
Rp=0.005;
Rs=0.005;
%估计阶数
N=kaiord(Fp,Fs,Rp,Rs,FT)
Wp=2*Fp/FT;%规划角频率
Ws=2*Fs/FT;
Wn=Wp+(Ws-Wp)/2;
h=fir1(N,Wn);
disp('NumeratorCoefficientsare');disp(h);
[g,w]=gain(h,[1]);
figure
(1);
plot(w/pi,g);grid;
%axis([01-605]);
xlabel('\omega/\pi');ylabel('GainindB');
title('GainResponse');
%频率响应
w2=0:
pi/511:
pi;
Hz=freqz(h,[1],w2);
MagH=abs(Hz);
T1=1.005*ones(1,length(w2));
T2=0.995*ones(1,length(w2));
T3=0.005*ones(1,length(w2));
figure(4);
plot(w2/pi,MagH,w2/pi,T1,w2/pi,T2,w2/pi,T3);grid;
%相位
figure
(2);
Phase=angle(Hz);
plot(w2/pi,Phase);grid;
xlabel('\omega/\pi');ylabel('Phase(rad)');
title('PhaseResponse');
figure(3);
UPhase=unwrap(Phase);
plot(w2/pi,UPhase);grid;
xlabel('\omega/\pi');ylabel('UnwrappedPhase(rad)');
title('UnwrappedPhaseResponse');
ThecoefficientsofthelowpassfiltercorrespondingtothespecificationsgiveninQuestion7.20areasshownbelow–
0.0010-0.0004-0.00150.00000.00240.0010-0.0038-0.00320.0049
0.0071-0.0050-0.01280.00260.02020.0038-0.0284-0.01660.0366
0.0404-0.0436-0.09090.04830.31290.44980.31290.0483-0.0909
-0.04360.04040.0366-0.0166-0.02840.00380.02020.0026-0.0128
-0.00500.00710.0049-0.0032-0.00380.00100.00240.0000-0.0015
-0.00040.0010
Thegeneratedgainandphaseresponsesaregivenbelow:
Fromthegainplotweobservethatthefilterasdesigned___DOESNOT__meetthespecifications.
ASSHOWNinthetwodetailplotsabove,withN=46,neitherthepassbandspecatwp=0.4(normalizedfrequency)northestopbandspecatws=0.5(normalizedfrequency)aremet.SothisdesignDOESNOTmeetthespec.
Thefilterorderthatmeetsthespecificationsis–N=66
Q7.23TheMATLABprogramtodesignandplotthegainandphaseresponsesofalinear-phaseFIRfilterusingfir1andkaiserisshownbelow.ThefilterorderNisestimatedusingEq.(7.37)andtheparameterβiscomputedusingEq.(7.36).Theoutputdataarethefiltercoefficients.
%程序Q7_23
%使用凯泽共识设计FIR低通滤波器
%-增益响应
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear;
%参数满足Q7.23.
Wp=0.31;
Ws=0.41;
Wn=Wp+(Ws-Wp)/2;
As=50;
Ds=10^(-As/20);
Dp=Ds;
ifAs>21
N=ceil((As-7.95)*2/(14.36*(abs(Wp-Ws)))+1)
else
N=ceil(0.9222*2/abs(Wp-Ws)+1)
end
%(7.36)计算B
ifAs>50
BTA=0.1102*(As-8.7);
elseifAs>=21
BTA=0.5842*(As-21)^0.4+0.07886*(As-21);
else
BTA=0;
end
Win=kaiser(N+1,BTA);
h=fir1(N,Wn,Win);
%分子系数
disp('NumeratorCoefficientsare');disp(h);
%增益响应
[g,w]=gain(h,[1]);
figure
(1);
plot(w/pi,g);grid;
axis([01-805]);
xlabel('\omega/\pi');ylabel('GainindB');
title('GainResponse');
%频率响应
w2=0:
pi/511:
pi;
Hz=freqz(h,[1],w2);
figure
(2);
Phase=angle(Hz);
plot(w2/pi,Phase);grid;
xlabel('\omega/\pi');ylabel('Phase(rad)');
title('PhaseResponse');
figure(3);
UPhase=unwrap(Phase);
plot(w2/pi,UPhase);grid;
xlabel('\omega/\pi');ylabel('UnwrappedPhase(rad)');
title('UnwrappedPhaseResponse');
ThecoefficientsofthelowpassfiltercorrespondingtothespecificationsgiveninQuestion7.23areasshownbelow–
0.00030.00080.0003-0.0011-0.00170.00000.00260.0027-0.0010-0.0049
-0.00350.00330.00800.0034-0.0074-0.0119-0.00180.01400.0161-0.0027
-0.0241-0.02010.01270.04060.0236-0.0354-0.0754-0.02580.12140.2871
0.35970.28710.1214-0.0258-0.0754-0.03540.02360.04060.0127-0.0201
-0.0241-0.00270.01610.0140-0.0018-0.0119-0.00740.00340.00800.0033
-0.0035-0.0049-0.00100.00270.00260.0000-0.0017-0.00110.00030.0008
0.0003
Fromthegainplotweobservethatthefilterasdesigned___DOES__meetthespecifications.
Thefilterorderthatmeetsthespecificationsis-N=60.
Thegeneratedgainandphaseresponsesaregivenbelow: