Support ARM CMSIS C Code Generation of dsp.FIRFilter in MATLAB Function Block
This example shows how to use the Code Replacement Library (CRL) for ARM® with DSP System object™. The model uses a MATLAB Function (Simulink) block that contains a dsp.FIRFilter System object to filter two sine waves of different frequencies.
Before you start with this example, install these MathWorks® products:
DSP System Toolbox™ Support Package for ARM Cortex®-M Processors
DSP System Toolbox
Task 1: Simulate and Setup the Model for Code Replacement
1. Open the
ex_fircmsis_tut_mlfun model, which contains a MATLAB® function block and the dsp.FIRFilter System object. Inside the MATLAB Function firfun, the dsp.FIRFilter System object is created just once and is declared to be persistent. This eliminates the overhead in creating new instances of a System object each time the function is called. It also allows users to execute the step function of the dsp.FIRFilter object multiple times with a persistent state by simply running the model with the MATLAB Function block in multiple time steps.
2. Change your current folder in MATLAB to a writable folder.
3. Simulate and setup the model for ARM Cortex-M code replacement by following Tasks 1 and 2 of Verify FIR Filter on ARM Cortex-M Processor example.
Task 2: Configure the dsp.FIRFilter System Object for Code Replacement
1. Open the MATLAB Function block within the FIR subsystem.
2. Verify that the dsp.FIRFilter System object has the following settings for its properties:
Structure: Direct form (default)
NumeratorSource: Property (default)
InitialConditions: 0 (default)
Task 3: Generate Code
1. Generate code for the FIR subsystem by following Task 3 of the Verify FIR Filter on ARM Cortex-M Processor example.
2. In the code generation report, click on the FIR.c file. Notice the CMSIS functions, arm_fir_init_f32 and arm_fir_f32 in the model's step function, FIR_step.
Task 4: Use Processor in the Loop (PIL)
To perform the previous steps using PIL, you must have the Embedded Coder Support Package for ARM Cortex-M Processors and the DST Support Package for ARM Cortex-M Processors. The following example shows you how to use PIL with ARM Cortex-M:
Code Verification and Validation with PIL and External Mode example.