This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Generate MATLAB code for a filter cascade




generateFilteringCode(FC) creates a MATLAB® function that contains code that creates the stages of a filter cascade, as defined in FC, and calls each stage in sequence. If the filters in each stage support code generation, you can generate C/C++ code from the function returned by generateFilteringCode.


generateFilteringCode(FC,fileName) generates code and saves the function to the file specified in fileName.


collapse all

This example shows how to generate a MATLAB™ function from a filter cascade. You cannot generate C/C++ code from the dsp.FilterCascade object directly, but you can generate C/C++ code from the generated function. The function defines the filter stages and calls them in sequence. The function is saved in the filename you specify.

FC = dsp.FilterCascade(dsp.FIRFilter('Numerator',ones(1,5)), dsp.FIRDecimator)
FC = 
  dsp.FilterCascade with properties:

    Stage1: [1x1 dsp.FIRFilter]
    Stage2: [1x1 dsp.FIRDecimator]

fName = 'myfilterCascade.m'; 

Examine the generated file.

type 'myfilterCascade.m'
function y = myfilterCascade(x)
%MYFILTERCASCADE Construct filter cascade and process each stage

% Generated by MATLAB(R) 9.6 and DSP System Toolbox 9.8.
% Generated on: 13-Apr-2019 02:23:58

% To generate C/C++ code from this function use the codegen command.
% Type 'help codegen' for more information.

%% Construction
persistent filter1 filter2
if isempty(filter1)
    filter1 = dsp.FIRFilter(  ...
        'Numerator', [1 1 1 1 1]);
    filter2 = dsp.FIRDecimator();

%% Process
y1 = filter1( x );
y  = filter2( y1);

Input Arguments

collapse all

Filter cascade, specified as a dsp.FilterCascade System object™.

File name where the generated function is saved, specified as a character array.

Data Types: char | string

Introduced in R2014b