使用 fdesign 设计滤波器
使用以下两个步骤设计简单的滤波器。
创建一个滤波器设定对象。
设计您的滤波器。
假设您要设计带通滤波器。通常,带通滤波器的定义如下图所示。

在本示例中,使用 Fs = 48 kHz 的采样频率。此带通滤波器具有以下设定,此处使用 MATLAB® 代码进行设定:
A_stop1 = 60; % Attenuation in the first stopband = 60 dB F_stop1 = 8400; % Edge of the stopband = 8400 Hz F_pass1 = 10800; % Edge of the passband = 10800 Hz F_pass2 = 15600; % Closing edge of the passband = 15600 Hz F_stop2 = 18000; % Edge of the second stopband = 18000 Hz A_stop2 = 60; % Attenuation in the second stopband = 60 dB A_pass = 1; % Amount of ripple allowed in the passband = 1 dB
在以下两个步骤中,这些设定作为参数传递给 fdesign.bandpass 方法。
- 步骤 1
要创建滤波器设定对象,请在 MATLAB 提示符下执行以下代码:
d = fdesign.bandpass
现在,传递与默认
Specification相对应的滤波器设定 -fst1、fp1、fp2、fst2、ast1、ap、ast2。此示例添加fs作为最终输入参量,以指定 48 kHz 的采样频率。>> BandPassSpecObj = ... fdesign.bandpass('Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2', ... F_stop1, F_pass1, F_pass2, F_stop2, A_stop1, A_pass, ... A_stop2, 48000)注意
未指定滤波器的阶数,从而给予算法设计一定的自由度来实现设定。该设计将采用最低阶数设计。
设定参数(如
Fstop1)在没有提供默认值的情况下都赋予默认值。在创建滤波器设定对象后,您可以更改设定参数的值。例如,如果需要更改两个值,即Fpass2和Fstop2,请使用set命令,该命令首先获取对象,然后获取参数值对组。在 MATLAB 提示符下执行以下代码:>> set(BandPassSpecObj, 'Fpass2', 15800, 'Fstop2', 18400)
BandPassSpecObj是新滤波器设定对象,其中包含所有必需的设计参数,包括滤波器类型。您也可以像访问
struct数组中的元素一样访问滤波器设定对象,从而在其中更改参数值。>> BandPassSpecObj.Fpass2=15800;
- 步骤 2
使用
design命令设计滤波器。您可以通过调用designmethods函数来访问对您的设定对象可用的设计方法。例如,在本例中,您可以执行以下命令在选择使用的设计方法后,您可以在 MATLAB 提示符下执行以下代码(此示例假设您选择了“>> designmethods(BandPassSpecObj) Design Methods for class fdesign.bandpass (Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2): butter cheby1 cheby2 ellip equiripple kaiserwin
equiripple”):>> BandPassFilt = design(BandPassSpecObj, 'equiripple') BandPassFilt = FilterStructure: 'Direct-Form FIR' Arithmetic: 'double' Numerator: [1x44 double] PersistentMemory: false如果您安装了 DSP System Toolbox™,还可以使用滤波器 System object™ 设计滤波器。要创建具有相同设定对象
BandPassSpecObj的滤波器 System object,您可以执行以下命令滤波器 System object 的可用设计方法和设计选项不一定与滤波器对象的相同。>> designmethods(BandPassSpecObj,... 'SystemObject',true) Design Methods that support System objects for class fdesign.bandpass (Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2): butter cheby1 cheby2 ellip equiripple kaiserwin >> BandPassFiltSysObj = design(BandPassSpecObj,... 'equiripple','SystemObject',true) System: dsp.FIRFilter Properties: Structure: 'Direct form' NumeratorSource: 'Property' Numerator: [1x44 double] InitialConditions: 0 FrameBasedProcessing: true Show fixed-point properties注意
如果您未指定设计方法,将使用默认方法。例如,您可以执行以下命令
此时将自动选择设计方法。>> BandPassFilt = design(BandPassSpecObj) BandPassFilt = FilterStructure: 'Direct-Form FIR' Arithmetic: 'double' Numerator: [1x44 double] PersistentMemory: false