Main Content

Deploy Parametric Audio Equalizer on ARM Cortex-A Processors

Since R2025a

This example shows how to deploy a three-band parametric audio equalizer on a Raspberry Pi™ 3 Model B board with an ARM Cortex-A ™ processor running on a 32 bit operating system. You can deploy this parametric equalizer on any Raspberry Pi boards which are above 3 Model B .

A parametric equalizer adjusts the frequency response of an audio system. For example, a parametric equalizer compensates for physical speakers that have peaks and dips at different frequencies. The parametric equalizer in this example uses a second-order section (SOS) filter. You can adjust the coefficients of the SOS filter to achieve the desired frequency response. You use three Parametric Equalizer Design blocks to design parametric equalizers and pass the coefficients to an SOS filter block. Tune the equalizer parameters such as gain, center frequency, and bandwidth for each band using the Simulink user interface.

This example covers the following sections.

Simulation of Parametric Equalizer

The top model armcortexa_parametric_audio_equalizer.slx contains the three-band parametric equalizer, model reference armcortexa_parametric_audio_equalizer_mdlref.slx, and a From Multimedia File block to provide the audio input. Additionally, the top model contains constant blocks to pass equalizer parameters as inputs to the model reference . You can adjust the equalizer parameters using the knobs in the user interface panel.

The model reference contains the actual implementation of the three-band parametric equalizer that generates the coefficients. The system then cascades these coefficients to input into the SOS filter, ensuring precise signal processing according to the specified equalizer parameters.

Open the top model and the model reference.

open_system('armcortexa_parametric_audio_equalizer')
open_system('armcortexa_parametric_audio_equalizer_mdlref')

Use the Filter Visualizer block to visualize the magnitude response of the equalizer. Observe the changes in the magnitude response by adjusting the equalizer parameters such as gain, center frequency, and bandwidth.

The model dynamically generates the SOS filter coefficients based on the equalizer parameters. Open the block parameters of the model reference and set Simulation mode to Normal to tune the parameters in the host simulation environment. Increase the Stop Time parameter to allocate sufficient time for tuning the equalizer parameters. For more information on equalizer parameters, see Parametric Equalizer Design (Audio Toolbox).

Configure and Deploy Equalizer on ARM Cortex-A Board

You can configure the top model either interactively, using the Configuration Parameters in Simulink, or programmatically, using the MATLAB programming interface.

Interactive Approach

You can follow these steps to deploy the parametric equalizer interactively.

  • Open the top model armcortexa_parametric_audio_equalizer.slx.

  • Click the Equalizer block.

  • On the Simulink toolstrip, click the Model Block tab.

  • Set the Simulation Mode to Processor-in-the-Loop (PIL).

  • In the model reference click the Modeling tab on the Simulink toolstrip and click Model Settings to open the Configuration Parameters dialog box.

  • Select Hardware Implementation from the left pane of the Configuration Parameters dialog box.

  • Set Hardware board to Raspberry Pi.

  • Click Target hardware resources and Set the Device Address, Username, and Password of the Raspberry Pi board.

  • Select Code Generation from the left pane of the Configuration Parameters dialog box.

  • Set System target file to ert.tlc.

  • Set Build Configuration to Faster Runs.

  • Select the Interface option under Code Generation.

  • Set Code replacement libraries to ARM Cortex-A CMSIS.

  • To view the code generation report, select Report option under Code Generation.

  • Enable Create code generation report and Open report automatically.

  • To profile the generated code on hardware, select Verification option under Code Generation of armcortexa_parametric_audio_equalizer.slx .

  • Enable Measure task execution time.

  • Set Measure function execution times to Detailed (all function call sites).

Programmatic Approach

To configure and deploy the Simulink model on the Raspberry Pi board,set the SystemTargetFile to ert.tlc and BuildConfiguration to Faster Runs to prioritize execution speed.

set_param('armcortexa_parametric_audio_equalizer_mdlref','HardwareBoard','Raspberry Pi');
set_param('armcortexa_parametric_audio_equalizer_mdlref','SystemTargetFile','ert.tlc');
set_param('armcortexa_parametric_audio_equalizer_mdlref','BuildConfiguration','Faster Runs');

Set the code replacement library to ARM Cortex-A CMSIS to use the CMSIS APIs which, improves performance.

set_param('armcortexa_parametric_audio_equalizer_mdlref',"CodeReplacementLibrary",'ARM Cortex-A CMSIS');

Enable the generation of detailed code replacement reports. These reports provide valuable insights into the code structure, facilitating a deeper understanding of the deployment process.

set_param('armcortexa_parametric_audio_equalizer_mdlref','GenerateReport','on');
set_param('armcortexa_parametric_audio_equalizer_mdlref','GenerateCodeReplacementReport','on');

Enable the profiling statistics for detailed CPU time. These reports provide more information about the time taken by an individual function to analyze the complexity of each function.

set_param('armcortexa_parametric_audio_equalizer',"CodeExecutionProfiling",'on') ;
set_param('armcortexa_parametric_audio_equalizer',"CodeProfilingInstrumentation",'detailed') ;

Set up the connection to the Raspberry Pi board using this command. Set the ipaddress, username, and password of the Raspberry Pi board.

r = raspberrypi('ipaddress', 'username', 'password')

Run on Target

To run the model programmatically in PIL mode, execute these commands.

set_param('armcortexa_parametric_audio_equalizer','HardwareBoard','Raspberry Pi'); %this
set_param('armcortexa_parametric_audio_equalizer','SimulationMode','processor-in-the-loop (PIL)')
output = sim('armcortexa_parametric_audio_equalizer','StopTime','1')

Alternatively, to run in interactive approach. In the Simulink toolstrip clicks Apps section and select the SIL/PIL Manager.

In the SIL/PIL Manager. Select the System Under Test to Top model and SIL/PIL Mode to PIL. Then click Run SIL/PIL to run the Simulink model

You can increase the Stop Time parameter to allocate sufficient time to tune the equalizer parameters.

You can tune the equalizer parameters such as gain, center frequency and bandwidth during the simulation and the model dynamically generates the SOS Filter coefficients. You can view the magnitude response of the tuned equalizer using the Filter Visualizer.

Open the code Generation Report to view the detailed information about the generated code.

Performance Benchmarking of Vanilla C code vs CMSIS CRL code

  • Run the armcortexa_parametric-audio_equalizer model with the code replacement library set to ARM Cortex-A CMSIS in the first iteration and None in the second iteration.

  • Click the Code Profile Analyzer to view the comparison results in the Code Profile Analyzer app.

  • Alternatively, you can run this command after each iteration to view the comparison results.

output.executionProfile
coder.profile.show(ans)

The figure shows the minimum CPU time in nano seconds for each function call with and without ARM Cortex-A CMSIS CRL. You can observe that the code generation with the ARM Cortex-A CMSIS CRL takes less time than the Vanilla C code.Improvement can vary based on various parameters like hardware board , input dimensions, number of sections for filter coefficients.