Products & Services Solutions Academia Support User Community Company

Learn more about Signal Processing Toolbox   

Exporting a Filter Design

Exporting Coefficients or Objects to the Workspace

You can save the filter either as filter coefficients variables or as a dfilt or mfilt filter object variable. (Note that you must have Filter Design Toolbox product installed to save as an mfilt.) 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 or select Objects to save the filter in a filter 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.

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 filename 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 or a filter object as variables 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 or select Objects to save the filter in a filter 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 filename and click the Save button.

See also Saving and Opening Filter Design Sessions.

Exporting to SPTool

You may want to use your designed filter in SPTool to do signal processing and analysis.

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

  2. Select SPTool from the Export To menu.

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

  4. Click the Export button.

    SPTool opens and the current FDATool filter appears in the Filter area list as the specified variable name followed by (Imported).

      Note   If you are using the Filter Design Toolbox product and export a quantized filter, only the values of its quantized coefficients are exported. The reference coefficients are not exported. SPTool does not restrict the coefficient values, so if you edit them in SPTool by moving poles or zeros, the filter will no longer be in quantized form.

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

  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. Select the DestinationCurrent to insert the block into the current (most recently selected) Simulink model or New to open a new model.

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

  5. If you select Build model using basic elements, you can select the desired optimization(s) for your block:

    • 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 sturcture.

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

    Optimization Effects

  6. Click the Realize Model button to create the filter block. The filter is implemented as a subsystem block using Sum, Gain, and Integer Delay blocks.

If you double-click the Simulink Filter block, the filter structure is displayed. The following figure shows the first section of the default four-section, direct form II filter.

Other Ways to Export a Filter

You can also send your filter to a C header file or generate an M-file. The M-file contains code that replicates the filter you designed. See the following sections:

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS