Main Content

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® processors with DSP System object™. The model uses a MATLAB Function block that contains a dsp.FIRFilter System object to filter two sine waves of different frequencies.

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 when creating new instances of a System object each time you call the function. It also enables users to execute the step function of the dsp.FIRFilter System 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 is configured with the following 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. Observe the CMSIS functions arm_fir_init_f32 and arm_fir_f32 in the FIR_step model step function.

Task 4: Use Processor in the Loop (PIL)

The Code Verification and Validation with PIL example shows you how to use processor in the loop (PIL) with ARM Cortex-M processors.