Matlab Digital Filters Assignment 3 (Questions only) PDF

Title Matlab Digital Filters Assignment 3 (Questions only)
Course Introduction to Digital Signal Processing
Institution Oklahoma State University
Pages 14
File Size 760.6 KB
File Type PDF
Total Downloads 75
Total Views 138

Summary

I hope you REALLY like Matlab. For Dr. Teague's fall 2017 class....


Description

Page 1

DigitalSignalProcessing 

ECEN4763 Fall2017 

DesignofDigitalIIRFilterswithMatlab Purpose ThepurposeofthisassignmentisforyoutolearnmoreaboutdesigningdigitalIIRandFIR filtersusingclassicalanalogdesigntechniquesandthebilineartransform(forIIRfilters),andthe windowdesignmethod(forFIRfilters).Theassignmentisintwoparts–IIRDesignandFIRDesign 1.0IntroductiontoIIRDesignwithMatlab Aswediscussedinclass,Matlabcontainsvariousroutinesfordesigningandanalyzing digitalIIRandFIRfilters(andotherz‐domainfunctions).MostofthesearepartoftheSignal ProcessingToolbox,althoughmanyareincludedwithMatlabbydefault.Aselectionofthese functionsislistedbelow. Notallofthelistedfunctionswillbeusefulinthisassignment.Foradditionalinformation, usethehelpfunction(s)andotherdocumentationavailableinMatlab.Youshouldalsorefertothe on‐linehelpforeachfunctionyouconsiderusingasthishandoutisnotintendedtobeatutorialin theiruse. NotethatinthelistbelowarefunctionsforperformingeachofthebasicstepsinIIRdigital filterdesign(usingtheanalogdesigntechnique).Ratherthanusingtheseindividualfunctions,you willusecompositedesignfunctionswhichcombineseveraldesignstepsintoasinglecommandto simplifytheprocess(thefunction,butter,forexample)‐seetheexampleonthefollowingpage. freqz buttord,cheb1ord,ellipord butter,cheby1,ellip fir1 fir2 firls remez remezord abs,angle,unwrap fft,ifft bilinear impinvar invfreqz zplane fvtool fdatool

z‐domainfrequencyresponse IIRanalog/digitalfilterordercalculation IIRanalog/digitalfiltercalculation FIRdigitaldesign(window)‐standardresponse FIRdigitaldesign(window)‐arbitraryresponse FIRdigitaldesign‐arbitraryresponsew/t_band Parks‐McClellanoptimalFIRdigitaldesign Parks‐McClellanfilterordercalculation magnitude,phase,unwrappedphase forwardandinversediscreteFouriertransform analogtodigitalbilineartransformation analogtodigitalimpulseinvariance digitalfilterfittofrequencyresponse pole/zeroplottingroutine graphicalfilteranalysistool filterdesignandanalysistool(don’tusethis)

Page 2 1.1Example AsanexampleofIIRdigitalfilterdesignusingthebilineartransformation,considerthe designofadigitalButterworthfilterwiththefollowingspecifications: ‐1dBorless@3400Hzandbelow

‐40dBormore@3600Hzandbeyond

Samplingrate=8000Hz



NotethatMatlabusesasomewhatnon‐standardformforspecifyingfrequenciesfordigital filters.Thedigitalfrequencyaxiswhichweusuallyconsiderasrangingovertheinterval [0, 2 ]is specifiedinMatlabdigitalfilterdesignfunctionsas [0, 2] ,with1.0correspondingtohalfthe samplingrateorπ.TheMatlabcommandstoperformthisdesignandgenerateasampleplotof themagnitudeandphaseresponseareshownbelow.Amagnitudeandphaseplotfollow. % Design a Butterworth Digital LPF using Matlab and Bilinear Transformation % No more than 1dB attenuation below 3400 Hz and at least 40dB % attenuation at and beyond 3600 Hz. The sampling frequency is 8000 Hz. % First compute the required order and scaling factor for the filter. Note % the manner in which the passband and stopband frequencies are specified. [n,w]=buttord(3400/4000,3600/4000,1,40) % Now design the actual filter using BUTTER. BUTTER hides most of % the design details from the user, returning the coefficients of H(z) directly. % Use the short exponential format to get reasonable printed output. format short e [b,a]=butter(n,w) % Create a 100 point array of complex frequency response values and the % corresponding frequencies (in Hertz) for plotting and examination. Note % that the sampling frequency must be specified so that the actual analog % frequency can be determined from the digital response. [h,f]=freqz(b,a,100,8000); % List out the magnitude response array so that the response can be checked at % the passband and stopband edges (be sure those frequencies are in f). [20*log10(abs(h)),f] % Also create a magnitude and phase plot of H(z). figure(1) freqz(b,a,100,8000) % Finally plot the poles and zeros. figure(2) zplane(b,a) % Now plot the response over only the transition band (and a little more) to % see the response more clearly at the two critical frequencies. figure(3) f=3350:2:3650;

Page 3 freqz(b,a,f,8000)

 MagnitudeandPhaseResponsesfortheButterworthFilter

Page 4

 MagnitudeandPhaseResponseintheTransitionBand  1.2TheIIRFilterDesignProblem(s) UseMatlabtodesignthedigitalIIRfiltersspecifiedbelow.Performtheindicatedanalysis. 1.2.1ProblemIIR‐1:UseMatlabtodesignthreehighpassfiltersoftypesButterworth,Chebyshev TypeI,andelliptictomeetorexceedthesespecifications: ‐50dBormoreatandbelow1500Hz ‐1dBorlessat2000Hzandabove (minimumstopbandattenuation) (minimumpassbandripple) samplingfrequency:12,000Hz



Foreachfilter,verifythatthespecificationsweremetatallcriticalfrequenciesby performingthefollowinganalysis.PlottheoverallmagnitudefrequencyresponseusingadB amplitudescale(freqzwillcreatemagnitudeandphaseplotstogetheronthesamefigure).Plot thetransitionband(s)indBwithsufficientfrequencyresolutionandnumericprecisiontoverify thespecificationsweremet(theMatlabzoomcommandmaybehelpful).Annotatedirectlyonthe transitionbandplot(s)usingtextboxesoranothertechniquetheactualdBresponsevalueateach criticalfrequency(passbandedgeandstopbandedge).Createapole/zeroplot(zplane).Finally, createanoverallphaseplotforeachfilteryoudesigned.Youmaywanttousethesubplot commandfornicerformatting.

Page 5  Comparethethreefiltersintermsoftheirperformancebyproducingatablewiththree columns(filtertype,order,minimumstopbandattenuationachieved)andthreerows(onefor eachfiltertype). Comparethethreephaseplots.Whichfilterappearstoproducethemostlinearphase withinthepassband?Whichseemstoproducetheleastlinearphasewithinthepassband? Comparethethreepole‐zeroplots.Observeandcommentontheplacementofpolesand zerosandhowtheyrelatetoproductionofahighpassfiltercharacteristic.Whichfilterappearsto haveitspolesclosesttotheunitcircle?Recallthatifthepolesareveryclosetotheunitcircle,this couldproduceproblemsinanimplementationusingfiniteprecisionarithmetic.Note:youranswer tothisquestionmightchangeifthedesignspecificationswerechanged(i.e.,youranswermaynot betrueingeneral). 1.2.2ProblemIIR‐2:Designabutterworthbandpassfiltertomeetthesespecifications: ‐50dBormorefrom0to1500Hz samplingfrequency:14,000Hz 

‐1dBorlessfrom2,500Hzto3,500Hz ‐50dBormoreabove4,500Hz

ConsultthehelpfiletoseeexactlyhowtospecifyabandpassfiltertoMatlab.Notethat youmustchoosetheorderproperly. Carefullyverifythatthespecificationsweremetatallcriticalfrequenciesasintheprevious problem.PlottheoverallmagnitudefrequencyresponseusingadBamplitudescale.Plotthe transitionband(s)indBwithsufficientfrequencyresolutionandnumericprecisiontoverifythe specsweremet.Annotatedirectlyonthetransitionbandplot(s)theactualdBresponsevalueat eachcriticalfrequency(passbandedgeandstopbandedge)asbefore.ListthefilterorderN. Createapole/zeroplot.Finally,createanoverallphaseplot. Commentverybrieflyontheplacementofthepolesandzerosastheirplacementrelates totheproductionofabandpassresponse. 1.2.3ProblemIIR‐3:Considertheproblemofremovingnoisefromanaudiosignal.TheMatlabfile sh27n.matcontainsasignalsampledat16,000thathasbeencontaminatedwithhighamplitude noiseplusasinusoid.TheMatlabfilesh27.matcontainstheoriginalcleansignalforcomparison. Thedesiredsignalisofamalespeakerandafemalespeakereachsayingashortsentence.The Matlabloadcommandcanbeusedtoacquirethedata. Designafilterofyourownthatwillsufficientlyremovethenoisesoastoallowthe underlyingaudiosignaltobeheardwithgoodqualityandintelligibility.Itmayhelptoknowthata voicesignalhasmostofitsenergyinthelowerfrequencyrangeofthespectrum.Notethatinmost casesyouwouldnothaveanoriginalsignalfordirectcomparison,butyouwouldprobablyknow somethingaboutthecharacteristicsofthedesiredsignalandthenoise.

Page 6 YoucanlistentothetwosignalsusingtheMatlabcommandssoundand/orsoundsc.The secondcommandwillautomaticallynormalizethedatafileforplay.Plotandlistentothetwo signalssothatyouknowwhatyouareworkingwith. Designyourfiltertoenhancethesignalbyremovingasmuchofthenoiseasyoucan withoutsignificantlydegradingthedesiredsignal.Comparethesignalbeforeandafterfiltering. Howmuchnoisedoyousee(giveaqualitativeanswer).IsthereanythingyoucandousingDSP filteringtechniquestofurtherimprovethesignal? Whenyouaresatisfied,givethespecificationsyouusedforyourfilterandprovidea magnituderesponseplot.Providesampleplots(plotsofoneormoreshortsegments–aword,for example)sufficienttoillustratetheimprovementyouwereabletomake.Providethe specificationsand/orprocessyouusedto“cleanup”thesignalincludingmagnituderesponseplots ofyourfilter(s). 2.0FIRFilterDesign‐WindowDesignProcedure OnecharacteristicofFIRfilterswhichdistinguishesthemfromIIRfiltersisthatitispossible toachieveexactlylinearphaseinthepassband.Recallthatthisisusuallyconsideredadesirable, althoughnotalwaysnecessary,characteristic.Wecanachieveitessentially“forfree”withFIR filterswhichexhibitcertaintypesofsymmetryintheirimpulseresponse. Forthisassignment,youwillusetheMatlabfunctionFIR1todesignlinearphaseFIRfilters. FIR1iscapableofdesigninglowpass,highpass,bandpassandbandrejectFIRfilters.SinceanFIR filterisanall‐zerofilter(therearetrivialpolesattheorigin),onlythebvectorofcoefficientsis returned;thereisnoavectorastherewasfortheIIRfiltersyoudesigned(thezerothacoefficient is1).Youshouldrefertothehelpfileforthisfunctionforadditionalinformation. AnFIRfilterhastrivialpolesattheorigin‐thelocationsofthezerosdeterminethe frequencyresponseofthefilter.ItcanbeshownthatifalinearphaseFIRfilterhasazeroatsome 1 location z1 intheZ‐plane,thatitwillalsohaveazeroatthereciprocallocation, .Further,ifa z1 zerooccursatacomplexlocationintheZ‐planeandiftheimpulseresponseisreal‐valued,then therewillalsobeazeroatthecomplexconjugatelocation z 1 * .Thisimpliesthatzeroswill,in general,occurinquadrupletconstellations.Zeroswhichoccurontheunitcirclewilloccurinpairs, sincethereciprocalisthesamelocation. ConsiderthedesignofthefollowingFIRlinearphaselowpassfilter.Thepassbandextends fromdcto1000Hz.Thestopbandbeginsat1500Hzandextendsupwardtohalfthesampling frequency.Attenuationinthepassbandmustbenogreaterthan0.25dB;inthestopband attenuationmustbeatleast50dB.Thesamplingrateis10000Hz.Thesespecificationsmustbe convertedtodigitalfrequencyspecificationsforusewithMatlabinamannersimilartowhatyou didintheIIRassignment.

Page 7 First,refertothewindowcomparisoninTable7.2inthetextbook(below).Sincethe requiredstopbandattenuationisatleast50dB,eithertheHammingorBlackmanwindowcould beusedinthedesignbasedonthe“PeakApproximationError”(Kaiser,ofcourse,canalsobe used).

  Thetransitionbandwidthisfoundtobe 0.1 fromthespecifications.Wecancomputean estimateoftherequiredFIRfilterlengthusingthe“TransitionWidthofEquivalent…”valuesas follows(foraHammingwindow): 6.27  M 6.27  M 0.1 M  63 

0.1 

whichsuggestsafilterorder(length)ofapproximately63ifaHammingwindowischosen. TheFIR1commandinMatlabdefaultstoaHammingwindowifnootherwindowis specified.ItalsocomputesthefilterresponseusingalengthofM+1inthatcase,sowewould specifyalengthof62toFIR1whichwillresultinafilteroflength63(itwillbeTypeI)fromMatlab. Theidealcutofffrequency  canbecalculatedastheaverageofthepassbandandstopband edgesorjustthepassbandedge(bothareestimates,butusingtheaverageisusuallymuch better).Usingthecommand B  FIR1(62, 0.25) willreturntheimpulseresponseofthefilterin thebvector.Theavectorisjust1. Wemustnowdetermineifthespecificationsweremet.Iftheywere,wemustdetermineif thefiltercanbeshortenedwhilestillmeetingthespecifications.Iftheywerenotmet,wemustre‐ designthefilterusingmodifieddesignparameterssuchthattheoriginalspecificationsare satisfied.Inthiscasethefollowingplotsrepresenttheinitialresultofthisdesign–thefilterlooks generallycorrect,butisit?

Page 8

 MagnitudeandPhaseResponsesfortheFIRLowpassFilterfromFREQZ  AusefulfilteranalysistoolthatisavailableintheSignalProcessingToolboxisFVTOOL.This toolcallsFREQZandotherfunctions,anditalsoplots.Thefollowingplotswerecreatedusingthis function.Iencourageyoutoconsiderusingit. Noteinthefiguresbelowthatthemagnituderesponseinthestopbandfallstomorethan 50dBbelowitsamplitudeinthepassbandasdesired.Weneedtolookcloseratthecritical frequenciestoseeifthespecificationsareactuallymet. 

Page 9

 MagnitudeandPhaseResponseUsingFVTOOL 

 MagnitudeandPhaseResponseintheTransitionBand  Theexpandedplotofthetransitionband(above)revealsthatthisfilterreachesthe‐50dB levelatandaboveapproximately1520Hz,whichisnotasgoodasdesired(stopbandshouldbeat andabove1,500Hzwithatleast‐50dB).Notealsothattheattenuationattheedgeofthe

Page 10 passbandisverycloseto0dBwhichisbetterthanspecified.Thus,therearetwoproblems–the passbandspecificationappearstobemetsignificantlybetterandearlierinthespectrumthan required(thisisok,butnotnecessary),andthedesiredstopbandattenuationisnotquitemetat 1,500Hz.Thisfilterwillhavetobere‐designed. Thewindowdesignmethodisnotfullyspecified–thereisnowheretospecifythe passbandedgeattenuation.But,wecanstretchorcontractthepassbandbytellingMatlabthe passbandedgefrequency(ortheaverageofpassbandandstopbandedgefrequencies)islargeror smallerthanitactuallyis. Wepicked0.25πtostart.Let’spickaslightlysmallervalue,0.24πforexample,inorderto shiftthetransitionbandslightlytotheleftwhichgivesitmoretimetofallandpossiblymeetthe specificationattheedgeofthestopband.Hereisthenewmagnituderesponse(phasehasbeen de‐selected). 

 MagnitudeResponsefortheRevisedDesign  Youcanseethestopbandattenuationof‐50dBhasnowbeenachievedbefore1,500Hz andthisspecificationisclearlymet.Let’slookcloser. Thetwofiguresbelowshowtheoveralltransitionbandalongwithafurtherzoomedview oftheedgeofthestopband.Bothspecificationsaremeteasilynow.Takeacloselookandverify thisforyourself.

Page 11



 ZoomedMagnitudeResponseintheTransitionBandandPassband  

Page 12

 FinalDesignedFIRFilter–FullResponse Hamming,N=63,0.24π 

 ImpulseResponseoftheFIRFilter 

Page 13

 Pole‐ZeroPlotfortheFIRFilter  Notethatthephaseappearstobehighlylinearinthepassband(itisactuallyexactlylinear becausetheimpulseresponseisevensymmetric).Thesawtoothbehaviorinthestopbandisdue tozero‐crossings(signchanges)intheamplituderesponse.Finally,theimpulseresponseandpole‐ zeroplotsareshownforthisfilter. 2.1TheFIRDesignProblems 2.1.1ProblemFIR‐1:Repeatthehighpassfilterdesignfromproblem1oftheIIRassignment.The specificationisrepeatedbelowforconvenience.UsetheFIRdesignprocedureasintheexample above,andselectanappropriatewindowfunctionforthedesign.Plottheoverallmagnitudeand phaseplotsfortheresultingdesign,alongwithexpandedresponseplotstoverifythatthe specificationsweremetbythedesign.Ifthespecificationswerenotmet,re‐designandoptimize thefiltersothattheyare,anddocumentyourfinaldesign.Plottheimpulseresponse,verifythatit isindeedsymmetricandreal,andidentifythetypeoflinearphaseFIRfilter.Includeapole‐zero plotfortheresponse. Computethenumberofrealmultipliesandaddsrequiredtocomputeeachoutputsample ifthisFIRfilterisimplementedasadifferenceequation.Comparethecomputationalcosttothe equivalentellipticfilterdesignedintheIIRassignment.AssumetheIIRfilterisimplementedasa recursivedifferenceequation. 

Page 14 ‐50dBormoreatandbelow1,500Hz ‐1dBorlessat2,000Hzandabove (minimumstopbandattenuation) (minimumpassbandripple) samplingfrequency:12,000Hz



2.1.2ProblemFIR‐2:Repeatthebandpassfilterdesignfromproblem2oftheIIRassignment. IncludethesameanalysisandplotsasinthefirstFIRproblemabove;however,thistimethereis noneedtomakeacomparisonofthecomputationalcosts.Yourfinalresultshouldbean optimizeddesignasabove. ‐50dBormorefrom0to1,500Hz

‐1dBorlessfrom2,500Hzto3,500Hz

samplingfrequency:14,000Hz

‐50dBormoreabove4,500Hz

 

3.0TheReport  TurninyourfilterdesignsandthecorrespondinganalysesfortheIIRandFIRdesign problems,completewithplotsandallrequestedinformationfromthequestionsabove. EverythingshouldbeclearlylabeledandorganizedinasinglePDFdocumentintheorderinwhich itwasrequested.Neatnessisimportant!InsertallMatlabplotsdirectlyinthedocument.Insert youranswersanddiscussionasrequestedinthedocumentand/ordirectlyontheplotsas appropriate.ItisnotnecessarytoincludeanyMatlabcode.    ThisassignmentisdueonFriday,November17,intheOCDropboxsetupforthispurpose.        ...


Similar Free PDFs