ThissectiondescribeshowtographicallydesignandimplementdigitalfiltersusingtheSignalProcessingToolboxFDAToolGUI.Filterdesignistheprocessofcreatingthefiltercoefficientstomeetspecificfrequencyspecifications.Filterimplementationinvolveschoosingandapplyingaparticularfilterstructuretothosecoefficients.Onlyafterbothdesignandimplementationhavebeenperformedcanyourdatabefiltered.
本章描述了怎样利用信号处理工具箱(FDAToolGUI)图解设计和执行数字滤波器。滤波器的设计是一个为满足频率要求创建滤波器系数的过程。滤波器的执行是利用这些滤波器系数选择和应用一个特殊的滤波器结构。只有在设计和执行完成之后才可以将你的数据进行滤波。
ThissectionincludesabriefdiscussionofapplyingthecompletedfilterdesignandfilterimplementationusingMATLABcommandlinefunctions,suchasfilter.
本章包括完全的利用MatlabCommandLine函数(例如filter)对滤波器进行设计和执行的简要论述。
ForaninteractiveFDATooldemo,typedemosattheMATLABcommandline,andselectToolboxes.Expandthetree,scrolldown,andselectSignalProcessingToolbox.UnderFilterDesignandAnalysis,clickIntroductiontoFilterDesignandAnalysisTool.
针对一个交互式FDATool演示,在MatlabCMDLine中键入demos然后选择Toolboxes。展开树,向下滚屏选择信号处理工具箱。在滤波器设计和分析中单击IntroductiontoFilterDesignandAnalysisTool。
Thissectionisastep-by-stepintroductiontousingtheFilterDesignandAnalysisTool(FDATool)todesignanoctave-bandfilter.Anoctaveistheintervalbetweentwofrequencieshavingaratioof2:1.Anoctave-bandfilterisabandpassfilterwithhighcutofffrequencyapproximatelytwicethatofthelowcutofffrequency.Theclassofanoctavefilterisdeterminedbyitsallowablepassbandrippleanditsstopbandattenuation.RefertotheANSIS1.11–2004standardformoreinformation.Formoreinformationondesigningfilters,seeFDATool:AFilterDesignandAnalysisGUIintheSignalProcessingToolboxUser'sGuide.(NotethatyoucanalsoaccessFDAToolfromSPTool).
这一部分按部就班的介绍应用FDATool设计一个倍频滤波器。倍频是指两个频率中间的比例为2:1。倍频滤波器是一个在通带的高频截止频率大约是低频截止频率两倍的滤波器。倍频滤波器的种类是由允许的通带波纹和阻带衰减决定的。滤波器设计的更多信息,见FDATool:AFilterDesignandAnalysisGUIintheSignalProcessingToolboxUser’sGuide.(注意:由SPTool也可以访问FDATool)。
Fdatool
TheFDATooldialogopenswithadefaultfilter.Itsfilterinformationissummarizedintheupperleft(CurrentFilterInformation)anditsfilterspecificationsaredepictedintheupperright.Inadditiontodisplayingfilterspecification,thisupperrightpanedisplaysfilterresponsesandfiltercoefficients.
FDATool对话框打开默认滤波器。这个滤波器的信息的概述位于左上角(CurrentFilterInformation),设计规则显示在右上角。右上角除了能显示滤波器设计规则,还可以显示滤波器响应和滤波器系数。
ThebottomhalfofFDAToolshowstheFilterDesignpanel,whereyouspecifythefilterparameters.Otherpanels,suchasImportfilterfromworkspaceandPole/ZeroEditor,whichyouaccesswiththebuttonsonthelowerleft,arealsodisplayedinthisarea.Ifyouhaveotherproductsinstalled,youmayseeadditionalbuttons.
在FDAToo的底部显示了滤波器设计面板,你可以在这里指定滤波器参数。其他的面板,例如可以在左下部访问的按钮:由workspace导入和零极点Pole/Zero编辑器也在这个区域显示。如果你安装其他的产品,你也许可以看到其他的按钮。
在响应类型ResponseType面板中,选择带通Bandpass按钮。
在设计方法DesignMethod面板中,选择IIR,然后选择Butterworth形式。
在滤波器阶数面板中,选择指定阶数,输入6.
设置频率规则如下:
Parameter
Setting
Description
Units
Hz
Unitsfortheparameters参数单位
Fs
48000
Samplingfrequency%采样频率
Fc1
22
Firstcutofffrequency(i.e.,thefrequencyprecedingthepassbandatwhichthemagnituderesponseis3dBbelowthepassbandgain)
第一个截止频率(例如通带前面的相对通带衰减3dB时的频率)
Fc2
45
Secondcutofffrequency(i.e.,thefrequencyfollowingthepassbandatwhichthemagnituderesponseis3dBbelowthepassbandgain)
第二个截止频率(例如通带之后的相对通带衰减3dB时的频率)
指定滤波器参数之后,点击在设计面板下面的设计滤波器DesignFilter按钮计算滤波器系数。设计的滤波器的幅值响应将会显示出来。
NoticethattheDesignFilterbuttonisdisabledafteryoucomputethecoefficientsforyourfilterdesign.Thisbuttonisenabledagainifyoumakeanychangestothefilterspecifications.
注意设计滤波器DesignFilter按钮在计算滤波器系数之后是不可用的。当你改变任何滤波器规则时这个按钮将会再次开启。
点击保存滤波器按钮
在保存滤波器对话框,将滤波器名称该为Butterworth-1然后点击OK保存滤波器在滤波器管理器中。
Afterdesigningthefilter,youcanviewthefollowingfilterresponsesinthedisplayregionbyclickingontheassociatedtoolbarbuttonorbyselectingthedesiredresponsefromtheAnalysismenu.
滤波器设计完成后,你可以通过点击联合工具条或在Analysis菜单下选择期望的响应观察如下滤波器的响应。
Response响应
ToolbarButtonImage
Magnituderesponse幅值响应
Phaseresponse相位响应
MagnitudeandPhaseresponses幅值和相位响应
Groupdelay群延迟
Phasedelay相角延迟
Impulseresponse脉冲响应
Stepresponse阶跃响应
Pole-zeroplot零极点图
Filtercoefficients滤波器系数
Filterinformation滤波器信息
Zero-phaseresponse–onlyavailablefromacontextmenu.Right-clickonthey-axisofaMagnitudeorMagnitudeandPhaseresponseplotorselectAnalysis>AnalysisParameters.
零相位响应——只存在于上下文菜单中。右击幅值或幅值和相位响应图的y轴或选择Analysis>AnalysisParameters:
NoteOtheranalysesareavailableifyouhavetheFilterDesignToolboxproductinstalled.
注意如果你已经安装了FilterDesignToolbox就会存在其他的分析。
1.Examinethedisplayedmagnituderesponseofthefilter.
检查显示的滤波器的幅频特性
2.Displayotherresponses,asdesired.Clicktheappropriatebuttons,showninthetableaboveorselectthedesiredresponsefromtheAnalysismenu.
显示其他期望的响应。点击显示于上表中合适的按钮或在Analysis菜单中选择期望的响应。
3.ClicktheFiltercoefficientsbuttontodisplaythefiltercoefficients.
Youhavedesignedoneofthebandsofanoctavefilterbank.Thissectionshowsyouhowtodesignandsavetheotherninebands.Thefollowingtabledefinestheparametersfortheremainingbands.Notethatallofthebandsusetheseparameters:Bandpass,IIR–Butterworth,order=6,Fs=48000Hz.
你已经设计了一个倍频滤波器。这一部分向你展示如何设计和保存其他9个频段。下面的表格定义了剩下频段的参数。注意所有的频段都用这个参数:BandPass,IIR-Butterworth,order=6,Fs=48000Hz。
FilterName
89
BandpassButterworth-2
178
BandpassButterworth-3
355
BandpassButterworth-4
708
BandpassButterworth-5
1413
BandpassButterworth-6
2818
BandpassButterworth-7
5623
BandpassButterworth-8
11220
BandpassButterworth-9
22387
BandpassButterworth-10
1.Usingtheparameterslistedinthetableabove,foreachtablerow,settheappropriatetheFc1andFc2values.
用在上表中的参数的每一行设置合适的Fc1和Fc2值。
2.DesignthefilterbyclickingtheDesignFilterbutton.
点击DesignFilter按钮设计滤波器。
3.ClickStoreFiltertosavethefilter.
点击StoreFilter保存滤波器
4.Changethenametotheappropriatefilternameshowninthetableabove.
给滤波器命名为上表中合适的名字
5.Repeatthesestepsuntilall10filtersaredesignedandstored.
重复这些步骤直到10个滤波器全部设计完成和存储
ThissectionteachesyouhowtousetheFilterVisualizationTool(FVTool)toviewtheoctave-bandfilter.Italsodescribeshowtoannotateyourfilter.
这一部分教你如何利用滤波器可视化工具(FVTool)去观察倍频滤波器。其中也描述了怎样注释你的滤波器。
1.ClicktheFilterManagerbuttontodisplaytheFilterManager,whichlistsyoursavedfilters.
点击FilterManager按钮去显示滤波器管理器,管理器中列出了你保存的滤波器。
2.PressCtrl+clickoneachfilternametoselectallthefilters,andthenclickFVTool.FVToolopenswiththefilterresponsesoverlaidforeasycomparison.(IfyouwanttoviewasinglefilterinFVTool,clicktheFullViewAnalysisbuttonwhenthatfilterisshownintheFDATooldisplaypanelorselectView>FilterVisualizationTool).
点击Ctrl+Click每个滤波器的名字选择所有的滤波器,然后点击FVTool。FVTool为了方便比较以覆盖模式打开滤波器响应。(如果你想用FVTool查看一个滤波器,当滤波器已经显示在FDATool面板时点击FullViewAnalysis按钮或选择View->FilterVisualizationTool).
3.Changethex-axisscaletologarithmicbyselectingAnalysis>AnalysisParameterstodisplaytheAnalysisParametersdialog.
通过选择Analysis>AnalysisParameters来显示分析参数对话框去改变x轴刻度为对数坐标。
4.ChangetheFrequencyScaletoLog.
改变频率刻度为log。
5.ClickOK.
点击OK
点击图例按钮开启图例功能,你可以拖放到想要的位置。
7.ClicktheLegendbuttonagaintoturnoffthelegend.
再次点击Legend按钮可以关闭图例。
利用Zoom按钮拖放一个方框在前几个通带去放大图像。
点击恢复默认视图按钮返回全景视图。
9.Displayotherresponses,asdesired.(TheFVToolAnalysistoolbarbuttonsandAnalysismenuarethesameasinFDATool.SeeAnalyzingtheFilterfordescriptionsofthebuttons.
按照需要显示其他响应。(FVTool分析工具按钮和Analysis菜单在FDATool中是一样的。按钮的描述见AnalysistheFilter)
FVToolisalsousefulfordoingfurtheranalysis,addingannotations,andprinting.Availableannotationsincludeaddingrectangles,textboxes,arrowsandlines,andaddingdatatips.
FVTool对深入分析是有用的,添加注释然后打印。可用的注释包括添加矩形,文本框,箭头和直线,添加数据标签。
ForademoaboutFVTool,typedemosattheMATLABcommandline,andselectToolboxes.Expandthetree,scrolldown,andselectSignalProcessingToolbox.UnderFilterDesignandAnalysis,clickFilterAnalysisusingFVToolanditsAPI.
在MATLAB的CMD中键入demos选择Tooboxes,展开树,滚动到SignalProcessingToolbox并选中来打开对FVTool的演示。在FilterDesignandAnalysis下点击FilterAnalysisusingFVToolanditsAPI。
1.Usethetoolbarbuttonstoannotateyourresponseplot.Addalinebyclickingoneofthelinebuttons,andthenuseyourmousetodrawthelineonyourplot.
利用工具栏按钮去注释你的响应图形。通过点击直线按钮中的一个去添加一条直线,然后利用你的鼠标在你的图像中画出直线。
2.Addadatatipbyclickingonaplotatthedesiredpoint.Thedatatipshowsthefrequencyandmagnitudeatthatpoint.
3.CloseFVToolbyselectingFile>Close.
通过选择File>Close关闭FVTool。
FDAToolprovidesasimplewaytocreatefilterobjects(dfilts)fromyourfilterdesigns.ThisisparticularlyusefulforsavingyourfilterdesigntotheMATLABworkspaceforusewithcommandlinefunctions.YoucanalsosaveyourfilterstoM-filesusingFile>GenerateM-filetoruninscriptsorbatchfiles.
FDATool提供了一种由你的滤波器设计创建滤波器对象(dfilts)的简单方法。这在你保存你的滤波器设计到MATLABworkspace并用于命令行函数时是非常有用的。你可以利用using>GenerateM-file保存你的滤波器为M文件然后在脚本或批处理中运行。
1.InFDATool,clickFilterManagerandhighlightonlytheBandpassButterworth-1filter.
在FDATool中,点击FilterManager然后高亮BandpassButterworth-1滤波器。
2.SelectFile>Export.
选择File>Export.
3.SetExporttotoWorkspace.SetExportastoObjects.InDiscreteFiltertypeHd1.ClickExporttoexportthefirstfilterinyourfilterbanktoanHd1dfiltobjectintheworkspace.
4.Repeatsteps1through3foreachoftheremainingninefilters.HighlighteachfilterindividuallytomakeittheactivefilterandchangetheDiscreteFilternametomatchthefilternumber.Whenyoufinishyouwillhave10dfiltobjectsintheworkspace.
为剩余9个滤波器重复步骤1到3。高亮每个滤波器为当前滤波器并改变离散滤波器的名字匹配滤波器序号。完成后你将由10个dfilt对象在工作空间中。
5.CloseFDAToolbyselectingFile>Close.
通过选择File>Close关闭FDATool。
6.OntheMATLABcommandline,verifythatyourobjectswereexportedbyusingthewhoscommand.
在MatlabCMDLine中通过whos命令核实你所导出的对象。
whosNameSizeBytesClassAttributesHd11x1dfilt.df2sosHd101x1dfilt.df2sosHd21x1dfilt.df2sosHd31x1dfilt.df2sosHd41x1dfilt.df2sosHd51x1dfilt.df2sosHd61x1dfilt.df2sosHd71x1dfilt.df2sosHd81x1dfilt.df2sosHd91x1dfilt.df2sos
1.TypethefollowingontheMATLABcommandlinetoconcatenateyourfilterbankfilterobjectsintoasingledfiltobject.
在CMD中键入如下命令使你的滤波器组对象成为单独的滤波器对象。
Hd=[Hd1Hd2Hd3Hd4Hd5Hd6Hd7Hd8Hd9Hd10];
2.Toviewthefirstfilter,typeHd(1).
查看第一个滤波器,键入Hd(1)
Hd(1)ans=FilterStructure:'Direct-FormII,Second-OrderSections'sosMatrix:[3x6double]ScaleValues:[3.40097054256801e-009;1;1;1]PersistentMemory:false
3.AnumberofmethodscanbeusedtoviewandmanipulatetheHd1dfiltobject.Trytheinfocommand:
由许多的方法能够用于查看和处理Hdldfilt对象。可以试着info命令。
info(Hd1)%DisplaysfilterinformationDiscrete-TimeIIRFilter(real)-------------------------------FilterStructure:Direct-FormII,Second-OrderSectionsNumberofSections:3Stable:YesLinearPhase:No
4.YoucanopenFVToolfromtheMATLABcommandlineandspecifydisplayparametersasfollows.
你可以由MATLABCMD打开FVTool然后像如下指定显示的参数.
F=fvtool(Hd,'Analysis','magnitude')%OpenFVToolwith%magnitudedisplayset(F,'FrequencyScale','Log')%Changetologscale
Thisproducesthesamedisplayasstep5ofViewingtheFilterinFVToolabove.
5.NowusingtheMATLABcommandline,createsomediscretewhiteGaussiannoisedata,whichyoucanthenfilterusingthefilterbank.
现在利用MatlabCMDline创建一些离散的高斯白噪声数据,这样你可以用滤波器组进行滤波。
rand;%InitializerandomnumbergeneratorNx=100000;%Numberofnoisedatapointsxw=randn(Nx,1);%Createwhitenoisefori=1:10,yw(:,i)=filter(Hd(i),xw);%Filterthewhitenoisethroughend%theentirefilterbank.%(:,i)meansallrowsofcolumni
6.Plotthefiltereddata.
plot(yw)
Thenextsectiondiscussesspectralanalysis,whereyouanalyzethisdata.
下一节将讨论频谱分析来分析这些数据。
BeginningwithR2009a,userscanspecifyanddesignfiltersatthecommandlineusingfdesignanddesign.Theuseoffdesignanddesignprovidesapowerfulandefficientwaytospecifyandimplementdigitalfilters.Withfdesignanddesign,digitalfilterdesignisatwo-stepprocess.Inthefirststep,theuserspecifiesthedesiredcharacteristicsofthefilterandsavesthosespecificationsinaFilterSpecificationObject.Inthesecondstep,theuserimplementsthefilterasadfiltobject,whichcanthenbeusedtofilterdata.Asanexampleofthistwo-stepprocess,wewilldesignalowpassfilterfordatasampledat20kHz.Thedesiredpassbandfrequencyis1kHzwithastopbandfrequencyof1.2kHz.Wewilllimitthepassbandrippleto1dBandrequire60dBofattenuationbetweenthepassbandandstopbandfrequencies.
由2009a开始,用户可以在CMD中利用fdesign和design函数指定和设计滤波器。fdesign和design的利用提供了一种强大和高效的方法去指定和运行数字滤波器。利用fdesign和design设计数字滤波器是一个两步的过程。第一步,用户指定滤波器的期望特性,保存这些指标在一个滤波器指标对象中。第二步,用户将滤波器作为dfilt对象进行处理,这可以别用于滤波器数据。例如:我们将要设计一个低通滤波器,数据采样频率为20kHz。期望的通带频率为1kHz阻带频率为1.2kHz。我们将限制通带波纹为1dB,阻带衰减为60dB。
1.Tospecifythefilterusefdesign.lowpasswiththeparametersgivenabove.YoucancopyandpastethefollowingcodeattheMATLABcommandprompt.
利用fdesign.lowpass指定以上参数,你可以拷贝然后粘贴如下代码在MATLABCMD中。
d=fdesign.lowpass('Fp,Fst,Ap,Ast',1000,1200,1,60,20000);
2.Todesignthefilterusedesignwiththeappropriatedesignmethods.Inthisexample,wecreateFIRequirippleandIIRButterworthdesignsandcomparethefilters'magnituderesponses.
利用design和合适的设计方法设计滤波器。在这个例子中,我们创建FIR线性相位滤波器和IIR巴特沃兹滤波器设计然后比较滤波器的幅值响应。
Hd1=design(d,'equiripple');%FIRequirippledesignHd2=design(d,'butter');%ButterworthdesignHd=[Hd1Hd2];%filterobjectwithbothdesigns%comparefiltersfvtool(Hd,'legend','on');axis([02-7010])
TodeterminewhichfilterdesignmethodsareavailableforagivenFilterSpecificationObject,usedesignmethods.Forthelowpassfilterexampleabove,youhaveachoiceoftwoFIRandfourIIRdigitalfilterdesigns.:
利用designmethods去决定对于给定的滤波器设计对象存在什么滤波器设计方法。对于上面的例子提及的低通滤波器,你可以选择两种FIR和四种IIR数字滤波器进行设计。