Main Content

Getting Started with Filter Designer

The Filter Designer app enables you to design and analyze digital filters. You can also import and modify existing filter designs.

To open the Filter Designer app, type

filterDesigner
at the MATLAB® command prompt.

The Filter Designer app opens with the Design Filter panel displayed.

Filter Designer app

Note that when you open Filter Designer, Design Filter is not enabled. You must make a change to the default filter design in order to enable Design Filter. This is true each time you want to change the filter design. Changes to radio button items or drop down menu items such as those under Response Type or Filter Order enable Design Filter immediately. Changes to specifications in text boxes such as Fs, Fpass, and Fstop require you to click outside the text box to enable Design Filter.

Choosing a Response Type

You can choose from several response types:

  • Lowpass

  • Raised cosine

  • Highpass

  • Bandpass

  • Bandstop

  • Differentiator

  • Multiband

  • Hilbert transformer

  • Arbitrary magnitude

Additional response types are available if you have DSP System Toolbox™ software installed.

Note

Not all filter design methods are available for all response types. Once you choose your response type, this may restrict the filter design methods available to you. Filter design methods that are not available for a selected response type are removed from the Design Method region of the app.

Choosing a Filter Design Method

You can use the default filter design method for the response type that you've selected, or you can select a filter design method from the available FIR and IIR methods listed in the app.

To select the Remez algorithm to compute FIR filter coefficients, select the FIR radio button and choose Equiripple from the list of methods.

Setting the Filter Design Specifications

Viewing Filter Specifications

The filter design specifications that you can set vary according to response type and design method. The display region illustrates filter specifications when you select Analysis > Filter Specifications or when you click the Filter Specifications toolbar button.

You can also view the filter specifications on the Magnitude plot of a designed filter by selecting View > Specification Mask.

Filter Order

You have two mutually exclusive options for determining the filter order when you design an equiripple filter:

  • Specify order: You enter the filter order in a text box.

  • Minimum order: The filter design method determines the minimum order filter.

Note that filter order specification options depend on the filter design method you choose. Some filter methods may not have both options available.

Options

The available options depend on the selected filter design method. Only the FIR Equiripple and FIR Window design methods have settable options. For FIR Equiripple, the option is a Density Factor. See firpm for more information. For FIR Window the options are Scale Passband, Window selection, and for the following windows, a settable parameter:

Window

Parameter

Chebyshev (chebwin)

Sidelobe attenuation

Gaussian (gausswin)

Alpha

Kaiser (kaiser)

Beta

Taylor (taylorwin)

Nbar and Sidelobe level

Tukey (tukeywin)

Alpha

User Defined

Function Name, Parameter

You can view the window in the Window Visualization Tool (WVTool) by clicking the View button.

Bandpass Filter Frequency Specifications

For a bandpass filter, you can set

  • Units of frequency:

    • Hz

    • kHz

    • MHz

    • Normalized (0 to 1)

  • Sample rate

  • Passband frequencies

  • Stopband frequencies

You specify the passband with two frequencies. The first frequency determines the lower edge of the passband, and the second frequency determines the upper edge of the passband.

Similarly, you specify the stopband with two frequencies. The first frequency determines the upper edge of the first stopband, and the second frequency determines the lower edge of the second stopband.

Bandpass Filter Magnitude Specifications

For a bandpass filter, you can specify the following magnitude response characteristics:

  • Units for the magnitude response (dB or linear)

  • Passband ripple

  • Stopband attenuation

Computing the Filter Coefficients

Now that you've specified the filter design, click the Design Filter button to compute the filter coefficients.

Note

The Design Filter button is disabled once you've computed the coefficients for your filter design. This button is enabled again once you make any changes to the filter specifications.

Analyzing the Filter

Displaying Filter Responses

You can view the following filter response characteristics in the display region or in a separate window.

  • Magnitude response

  • Phase response

  • Magnitude and Phase responses

  • Group delay response

  • Phase delay response

  • Impulse response

  • Step response

  • Pole-zero plot

  • Zero-phase response — available from the y-axis context menu in a Magnitude or Magnitude and Phase response plot.

Note

If you have DSP System Toolbox installed, two other analyses are available: magnitude response estimate and round-off noise power. These two analyses are the only ones that use filter internals.

You can display two responses in the same plot by selecting Analysis > Overlay Analysis and selecting an available response. A second y-axis is added to the right side of the response plot. (Note that not all responses can be overlaid on each other.)

You can also display the filter coefficients and detailed filter information in this region.

For all the analysis methods, except zero-phase response, you can access them from the Analysis menu, the Analysis Parameters dialog box from the context menu, or by using the toolbar buttons. For zero-phase, right-click the y-axis of the plot and select Zero-phase from the context menu.

You can overlay the filter specifications on the Magnitude plot by selecting View > Specification Mask.

Using Data Tips

You can click the response to add plot data tips that display information about particular points on the response.

For information on using data tips, see Interactively Explore Plotted Data.

Drawing Spectral Masks

To add spectral masks or rejection area lines to your magnitude plot, click View > User-defined Spectral Mask.

The mask is defined by a frequency vector and a magnitude vector. These vectors must be the same length.

  • Enable Mask — Select to turn on the mask display.

  • Normalized Frequency — Select to normalize the frequency between 0 and 1 across the displayed frequency range.

  • Frequency Vector — Enter a vector of x-axis frequency values.

  • Magnitude Units — Select the desired magnitude units. These units should match the units used in the magnitude plot.

  • Magnitude Vector — Enter a vector of y-axis magnitude values.

Changing the Sample Rate

To change the sample rate of your filter, right-click any filter response plot and select Sampling Frequency from the context menu.

To change the filter name, type the new name in Filter name.

To change the sample rate, select the desired unit from Units and enter the sample rate in Fs.

To save the displayed parameters as the default values to use with Filter Designer, click Save as Default.

To restore the default values, click Restore Original Defaults.

Editing the Filter Using the Pole-Zero Editor

Displaying the Pole-Zero Plot

You can edit a designed or imported filter's coefficients by moving, deleting, or adding poles or zeros or both using the Pole-Zero Editor panel.

Note

You cannot generate MATLAB code (File > Generate MATLAB code) if your filter was designed or edited with the Pole-Zero Editor.

You cannot move quantized poles and zeros. You can only move the reference poles and zeros.

Click the Pole-Zero Editor button in the sidebar or select Edit > Pole-Zero Editor to display the Pole-Zero Editor panel.

Poles are shown using "x" symbols and zeros are shown using "o" symbols.

Changing the Pole-Zero Plot

Plot mode buttons are located to the left of the pole-zero plot. Select one of the buttons to change the mode of the pole-zero plot. The Pole-Zero Editor has these buttons from left to right: Move Pole-Zero, Add Pole, Add Zero, and Delete Pole-Zero.

Note

For filters with orders larger than approximately 100, the Pole-Zero Editor might encounter numerical problems when computing transfer function polynomials. As a result, the displayed filter responses might be different than expected. To inspect poles and zeros without attempting to compute high-order polynomials, select Analysis > Pole-Zero Plot. You cannot edit a filter in this view.

The following plot parameters and controls are located to the left of the pole-zero plot and below the plot mode buttons.

  • Filter gain — factor to compensate for the filter's pole(s) and zero(s) gains

  • Coordinates — units (Polar or Rectangular) of the selected pole or zero

  • Magnitude — if polar coordinates is selected, magnitude of the selected pole or zero

  • Angle — if polar coordinates is selected, angle of selected pole(s) or zero(s)

  • Real — if rectangular coordinates is selected, real component of selected pole(s) or zero(s)

  • Imaginary — if rectangular coordinates is selected, imaginary component of selected pole or zero

  • Section — for multisection filters, number of the current section

  • Conjugate — creates a corresponding conjugate pole or zero or automatically selects the conjugate pole or zero if it already exists.

  • Auto update — immediately updates the displayed magnitude response when poles or zeros are added, moved, or deleted.

The Edit > Pole-Zero Editor has items for selecting multiple poles or zeros, for inverting and mirroring poles or zeros, and for deleting, scaling and rotating poles or zeros.

  • When you select a pole or zero from a conjugate pair, the Conjugate check box and the conjugate are automatically selected.

Converting the Filter Structure

Converting to a New Structure

You can use Edit > Convert Structure to convert the current filter to a new structure. All filters can be converted to the following representations:

  • Direct-form I

  • Direct-form II

  • Direct-form I transposed

  • Direct-form II transposed

  • Lattice ARMA

Note

If you have DSP System Toolbox installed, you will see additional structures in the Convert structure dialog box.

In addition, the following conversions are available for particular classes of filters:

  • Minimum phase FIR filters can be converted to Lattice minimum phase

  • Maximum phase FIR filters can be converted to Lattice maximum phase

  • Allpass filters can be converted to Lattice allpass

  • IIR filters can be converted to Lattice ARMA

Note

Converting from one filter structure to another might produce a result with different characteristics than the original. This is due to the computer's finite-precision arithmetic and the variations in the conversion's round-off computations.

For example:

  • Select Edit > Convert Structure to open the Convert structure dialog box.

  • Select Direct-form I in the list of filter structures.

Converting to Second-Order Sections

You can use Edit > Convert to Second-Order Sections to store the converted filter structure as a collection of second-order sections rather than as a monolithic higher-order structure.

Note

The following options are also used for Edit > Reorder and Scale Second-Order Sections, which you use to modify an SOS filter structure.

The following Scale options are available when converting a direct-form II structure only:

  • None (default)

  • L-2 (L2 norm)

  • L-infinity (L norm)

The Direction (Up or Down) determines the ordering of the second-order sections. The optimal ordering changes depending on the Scale option selected.

For example:

  • Select Edit > Convert to Second-Order Sections to open the Convert to SOS dialog box.

  • Select L-infinity from the Scale menu for L norm scaling.

  • Leave Up as the Direction option.

Note

To convert from second-order sections back to a single section, use Edit > Convert to Single Section.

Exporting a Filter Design

Exporting Coefficients or Objects to the Workspace

You can save the filter either as filter coefficients variables, as a filter object variable, or as a System object™. To save the filter to the MATLAB workspace:

  1. Select File > Export. The Export dialog box appears.

  2. Select Workspace from the Export To menu.

  3. Select Coefficients from the Export As menu to save the filter coefficients, select Objects to save the filter as a filter object, or select System Objects to save the filter as a System object. You must have a DSP System Toolbox license to save the filter as a System object.

  4. For coefficients, assign variable names using the Numerator (for FIR filters) or Numerator and Denominator (for IIR filters), or SOS Matrix and Scale Values (for IIR filters in second-order section form) text boxes in the Variable Names region.

    For objects, assign the variable name in the Discrete Filter text box. If you have variables with the same names in your workspace and you want to overwrite them, select the Overwrite Variables check box.

  5. Click the Export button.

Exporting Coefficients to an ASCII File

To save filter coefficients to a text file,

  1. Select File > Export. The Export dialog box appears.

  2. Select Coefficients File (ASCII) from the Export To menu.

  3. Click the Export button. The Export Filter Coefficients to FCF File dialog box appears.

  4. Choose or enter a file name and click the Save button.

The coefficients are saved in the text file that you specified, and the MATLAB Editor opens to display the file. The text file also contains comments with the MATLAB version number, the Signal Processing Toolbox™ version number, and filter information.

Exporting Coefficients or Objects to a MAT-File

To save filter coefficients, a filter object, or a filter System object in a MAT-file:

  1. Select File > Export. The Export dialog box appears.

  2. Select MAT-file from the Export To menu.

  3. Select Coefficients from the Export As menu to save the filter coefficients, select Objects to save the filter as a filter object, or select System Objects to save the filter as a System object. You must have a DSP System Toolbox license to save the filter as a System object.

  4. For coefficients, assign variable names using the Numerator (for FIR filters) or Numerator and Denominator (for IIR filters), or SOS Matrix and Scale Values (for IIR filters in second-order section form) text boxes in the Variable Names region.

    For objects, assign the variable name in the Discrete Filter (or Quantized Filter) text box. If you have variables with the same names in your workspace and you want to overwrite them, select the Overwrite Variables check box.

  5. Click the Export button. The Export to a MAT-File dialog box appears.

  6. Choose or enter a file name and click the Save button.

Exporting to a Simulink Model

If you have the Simulink® product installed, you can export a Simulink block of your filter design and insert it into a new or existing Simulink model.

You can export a filter designed using any filter design method available in Filter Designer.

Note

If you have DSP System Toolbox and Fixed-Point Designer™ installed, you can export a CIC filter to a Simulink model.

  1. After designing your filter, click the Realize Model sidebar button or select File > Export to Simulink Model. The Realize Model panel is displayed.

  2. Specify the name to use for your block in Block name.

  3. To insert the block into the current (most recently selected) Simulink model, set the Destination to Current. To inset the block into a new model, select New. To insert the block into a user-defined subsystem, select User defined.

  4. If you want to overwrite a block previously created from this panel, check Overwrite generated `Filter' block.

  5. If you select the Build model using basic elements check box, your filter is created as a subsystem (Simulink) block, which uses separate sub-elements. In this mode, the following optimization(s) are available:

    • Optimize for zero gains — Removes zero-valued gain paths from the filter structure.

    • Optimize for unity gains — Substitutes a wire (short circuit) for gains equal to 1 in the filter structure.

    • Optimize for negative gains — Substitutes a wire (short circuit) for gains equal to -1 and changes corresponding additions to subtractions in the filter structure.

    • Optimize delay chains — Substitutes delay chains composed of n unit delays with a single delay of n.

    • Optimize for unity scale values — Removes multiplications for scale values equal to 1 from the filter structure.

    The following illustration shows the effects of some of the optimizations:

    Filter design optimization strategies for zero gains, unity gains, negative gains and delay chains.

    Note

    The Build model using basic elements check box is enabled only when you have a DSP System Toolbox license and your filter can be designed using a Biquad Filter (DSP System Toolbox) block or a Discrete FIR Filter (Simulink) block. For more information, see the Filter Realization Wizard (DSP System Toolbox) topic in the DSP System Toolbox documentation.

  6. Set the Input processing parameter to specify whether the generated filter performs sample- or frame-based processing on the input. Depending on the type of filter you design, one or both of the following options may be available:

    • Columns as channels (frame based) — When you select this option, the block treats each column of the input as a separate channel.

    • Elements as channels (sample based) — When you select this option, the block treats each element of the input as a separate channel.

  7. Click the Realize Model button to create the filter block. When the Build model using basic elements check box is selected, Filter Designer implements the filter as a subsystem block using Sum (Simulink), Gain (Simulink), and Delay (Simulink) blocks.

If you double-click the Simulink Filter block, the filter structure is displayed.

Generating a C Header File

You may want to include filter information in an external C program. To create a C header file with variables that contain filter parameter data, follow this procedure:

  1. Select Targets > Generate C Header. The Generate C Header dialog box appears.

  2. Enter the variable names to be used in the C header file. The particular filter structure determines the variables that are created in the file.

    Filter Structure

    Variable Parameter

    Direct-form I

    Direct-form II

    Direct-form I transposed

    Direct-form II transposed

    Numerator, Numerator length, Denominator, Denominator length

    Lattice ARMA

    Lattice coeff., Lattice coeff. length, Ladder coeff., Ladder coeff. length

    Lattice MA

    Lattice coeff., Lattice coeff. length, and Number of sections (inactive if filter has only one section)

    Direct-form FIR Direct-form FIR transposed

    Numerator, Numerator length, and Number of sections (inactive if filter has only one section)

    Length variables contain the total number of coefficients of that type.

    Note

    Variable names cannot be C language reserved words, such as for.

  3. Select Export Suggested to use the suggested data type or select Export As and select the desired data type from the pull-down.

    Note

    If you do not have DSP System Toolbox software installed, selecting any data type other than double-precision floating point results in a filter that does not exactly match the one you designed in the Filter Designer. This is due to rounding and truncating differences.

  4. Click Generate to save the file and leave the dialog box open for additional C header file definitions. To close the dialog box, click Close.

Generating MATLAB Code

You can generate MATLAB code that constructs the filter you designed in Filter Designer from the command line. Select File > Generate MATLAB Code > Filter Design Function and specify the file name in the Generate MATLAB code dialog box.

Note

You cannot generate MATLAB code (File > Generate MATLAB Code > Filter Design Function) if your filter was designed or edited with the Pole-Zero Editor.

The following is generated MATLAB code for the default lowpass filter in Filter Designer.

function Hd = ExFilter
%EXFILTER Returns a discrete-time filter object.

%
% MATLAB Code
% Generated by MATLAB(R) 7.11 and the Signal Processing Toolbox 6.14.
%
% Generated on: 17-Feb-2010 14:15:37
%

% Equiripple Lowpass filter designed using the FIRPM function.

% All frequency values are in Hz.
Fs = 48000;  % Sample Rate

Fpass = 9600;            % Passband Frequency
Fstop = 12000;           % Stopband Frequency
Dpass = 0.057501127785;  % Passband Ripple
Dstop = 0.0001;          % Stopband Attenuation
dens  = 20;              % Density Factor

% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fpass, Fstop]/(Fs/2), [1 0], [Dpass, Dstop]);

% Calculate the coefficients using the FIRPM function.
b  = firpm(N, Fo, Ao, W, {dens});
Hd = dfilt.dffir(b);

% [EOF]

Managing Filters in the Current Session

You can store filters designed in the current Filter Designer session for cascading together, for exporting, or for recalling later in the same or future Filter Designer sessions.

You store and access saved filters with the Store Filter and Filter Manager buttons, respectively, in the Current Filter Information pane.

Store Filter — Displays the Store Filter dialog box in which you specify the filter name to use when storing the filter in the Filter Manager. The default name is the type of the filter.

Filter Manager — Opens the Filter Manager.

The current filter is listed below the list box. To change the current filter, highlight the desired filter. If you select Edit current filter, Filter Designer displays the currently selected filter specifications. If you make any changes to the specifications, the stored filter is updated immediately.

To cascade two or more filters, highlight the desired filters and press Cascade. A new cascaded filter is added to the Filter Manager.

To change the name of a stored filter, press Rename. The Rename filter dialog box is displayed.

To remove a stored filter from the Filter Manager, press Delete.

Saving and Opening Filter Design Sessions

You can save your filter design session as a MAT-file and return to the same session another time.

Select the Save Session button to save your session as a MAT-file. The first time you save a session, a Save Filter Design Session browser opens, prompting you for a session name.

The .fda extension is added automatically to all filter design sessions you save.

Note

You can also use File > Save Session and File > Save Session As to save a session.

You can load existing sessions into Filter Designer by selecting the Open Session button or File > Open Session . A Load Filter Design Session browser opens that allows you to select from your previously saved filter design sessions.