Design a Filter Using fdesign

Use the following two steps to design a simple filter.

  1. Create a filter specification object.

  2. Design your filter.

Design a Filter in Two Steps

Assume that you want to design a bandpass filter. Typically a bandpass filter is defined as shown in the following figure.

In this example, a sampling frequency of Fs = 48 kHz is used. This bandpass filter has the following specifications, specified here using MATLAB® code:

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

In the following two steps, these specifications are passed to the fdesign.bandpass method as parameters.

Step 1

To create a filter specification object, evaluate the following code at the MATLAB prompt:

d = fdesign.bandpass

Now, pass the filter specifications that correspond to the default Specificationfst1,fp1,fp2,fst2,ast1,ap,ast2. This example adds fs as the final input argument to specify the sampling frequency of 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)
      

    Note:   The order of the filter is not specified, allowing a degree of freedom for the algorithm design in order to achieve the specification. The design will be a minimum order design.

The specification parameters, such as Fstop1, are all given default values when none are provided. You can change the values of the specification parameters after the filter specification object has been created. For example, if there are two values that need to be changed, Fpass2 and Fstop2, use the set command, which takes the object first, and then the parameter value pairs. Evaluate the following code at the MATLAB prompt:

>> set(BandPassSpecObj, 'Fpass2', 15800, 'Fstop2', 18400)   

BandPassSpecObj is the new filter specification object which contains all the required design parameters, including the filter type.

You may also change parameter values in filter specification objects by accessing them as if they were elements in a struct array.

>> BandPassSpecObj.Fpass2=15800;
Step 2

Design the filter by using the design command. You can access the design methods available for you specification object by calling the designmethods function. For example, in this case, you can execute the command

>> designmethods(BandPassSpecObj)


Design Methods for class 
fdesign.bandpass (Fst1,Fp1,Fp2,Fst2,Ast1,Ap,Ast2):


butter
cheby1
cheby2
ellip
equiripple
kaiserwin

After choosing a design method use, you can evaluate the following at the MATLAB prompt (this example assumes you've chosen 'equiripple'):

>> BandPassFilt = design(BandPassSpecObj, 'equiripple')
 
BandPassFilt =
 
     FilterStructure: 'Direct-Form FIR'
          Arithmetic: 'double'         
           Numerator: [1x44 double]    
    PersistentMemory: false            
                      

If you have the DSP System Toolbox™ installed, you can also design your filter with a filter System object™. To create a filter System object with the same specification object BandPassSpecObj, you can execute the commands

>> 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
 

Available design methods and design options for filter System objects are not necessarily the same as those for filter objects.

    Note:   If you do not specify a design method, a default method will be used. For example, you can execute the command

    >> BandPassFilt = design(BandPassSpecObj)
     
    BandPassFilt =
     
         FilterStructure: 'Direct-Form FIR'
              Arithmetic: 'double'         
               Numerator: [1x44 double]    
        PersistentMemory: false

    and a design method will be selected automatically.

To check your work, you can plot the filter magnitude response using the Filter Visualization tool. Verify that all the design parameters are met:

>> fvtool(BandPassFilt) %plot the filter magnitude response

If you have the DSP System Toolbox installed, the Filter Visualization tool produces the following figure with the dashed red lines indicating the transition bands and unity gain (0 in dB) over the passband.

Was this topic helpful?