Designing Filters Using Command Line Functions

You can specify and design filters at the command line using fdesign and design. The use of fdesign and design provides a powerful and efficient way to specify and implement digital filters. With fdesign and design, digital filter design is a two-step process. In the first step, the user specifies the desired characteristics of the filter and saves those specifications in a Filter Specification Object. In the second step, the user implements the filter as a dfilt object, which can then be used to filter data. As an example of this two-step process, we will design a lowpass filter for data sampled at 20 kHz. The desired passband frequency is 1 kHz with a stopband frequency of 1.2 kHz. We will limit the passband ripple to 1 dB and require 60 dB of attenuation between the passband and stopband frequencies.

  1. To specify the filter use fdesign.lowpass with the parameters given above. You can copy and paste the following code at the MATLAB® command prompt.

    d=fdesign.lowpass('Fp,Fst,Ap,Ast',1000,1200,1,60,20000);
  2. To design the filter use design with the appropriate design methods. In this example, we create FIR equiripple and IIR Butterworth designs and compare the filters' magnitude responses.

    Hd1=design(d,'equiripple'); %FIR equiripple design
    Hd2=design(d,'butter'); %Butterworth design
    Hd=[Hd1 Hd2];%filter object with both designs
    %compare filters
    fvtool(Hd,'legend','on'); axis([0 2 -70 10])
    

To determine which filter design methods are available for a given Filter Specification Object, use designmethods. For the lowpass filter example above, you have a choice of two FIR and four IIR digital filter designs:

designmethods(d)
Design Methods for class fdesign.lowpass (Fp,Fst,Ap,Ast):


butter
cheby1
cheby2
ellip
equiripple
kaiserwin
Was this topic helpful?