Main Content

Deploy Parametric Audio Equalizer on ARM Cortex-M Processors

Since R2024b

This example shows how to deploy three-band parametric audio equalizer on the ARM Cortex-M™ STM32F746G-Discovery board. You can deploy this parametric equalizer on any supported ARM Cortex-M hardware.

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 algorithm in this example uses a second-order section (SOS) filter, whose coefficients can be adjusted to achieve a desired frequency response. The three Parametric Equalizer Design (Audio Toolbox) blocks provide the coefficients for the input parameters: gain, center frequency and bandwidth for each band. During the simulation, a user interface is used to dynamically adjust the equalizer parameters.

The following sections describe how the parametric equalizer algorithm is specified, how the behavior can be explored through simulation, and how the code can be generated.

Required Hardware

Cortex-M hardware - STM32F746G-Discovery board

Simulate Parametric Equalizer

In this example, the top model stm32f746g_parametric_audio_equalizer.slx utilizes 'From Multimedia File' block to provide audio input and employs constant blocks to supply equalizer parameters as inputs to the Parametric Equalizer. These equalizer parameters are adjusted through a user interface that includes panels with knobs for each parameter.

The model reference stm32f746g_parametric_audio_equalizer_mdlref.slx 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('stm32f746g_parametric_audio_equalizer')
open_system('stm32f746g_parametric_audio_equalizer_mdlref')

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

The model dynamically generates the SOS filter coefficients based on these settings. You can directly perform this exploration on the 'STM32F746G-Discovery' hardware. However, to facilitate tuning in the host simulation environment, set the Simulation mode to 'Normal' in the block parameters of the model reference (equalizer). Additionally, consider increasing the 'Stop Time' parameter to allow for sufficient time to tune the parameters as needed.

For more information on the equalizer parameters see Parametric Equalizer Design (Audio Toolbox).

Configure and Deploy on ARM Cortex-M board

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

Interactive Approach

For deploying the equalizer to the target, set the simulation mode of the model reference block (Equalizer) to 'Processor-in-the-Loop (PIL)'.

  • Open the top model stm32f746g_parametric_audio_equalizer.slx and select the Equalizer block to enable 'MODEL BLOCK' on the Simulink tool strip. Then set the Simulation mode to 'Processor-in-the-Loop (PIL)'.

  • Press Ctrl+E (Model settings) in the model reference to open Configuration Parameters dialog box. (or) Open the Modeling tab and select Model Settings from the model toolstrip.

  • Go to Hardware Implementation > Hardware board and select STM32F746G-Discovery.

Navigate to Hardware Implementation > Code Generation and perform the following configurations.

  • Code Generation > System target file to ert.tlc

  • Code Generation > Build Configuration to Faster Runs

  • Code Generation > Report > enable Create code generation report

  • Code Generation > Report > enable Open report automatically

Programmatic Approach

Execute the following commands to configure the Simulink model stm32f746g_parametric_audio_equalizer_mdlref.slx for deployment on the STM32F746G-Discovery board. Select ert.tlc as the system target file to optimize the code for embedded real-time systems, and choose Faster Runs for the build configuration to prioritize execution speed. Ensure that the Hardware board settings like Drive and COM Ports are set appropriately.

set_param('stm32f746g_parametric_audio_equalizer_mdlref','HardwareBoard','STM32F746G-Discovery');
set_param('stm32f746g_parametric_audio_equalizer_mdlref','SystemTargetFile','ert.tlc');
set_param('stm32f746g_parametric_audio_equalizer_mdlref','BuildConfiguration','Faster Runs');

Finally, 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('stm32f746g_parametric_audio_equalizer_mdlref','GenerateReport','on');
set_param('stm32f746g_parametric_audio_equalizer_mdlref','GenerateCodeReplacementReport','on');

Run on target

Execute the command below to run the model programmatically in PIL mode. Alternatively, you can run the model in PIL mode interactively. Go to the 'SIMULATION' tab in the tool strip and click on 'Run'. You can increase the 'Stop Time' parameter to allow for sufficient time to tune the parameters as needed.

sim('stm32f746g_parametric_audio_equalizer','StopTime','1')

The simulation will execute on STM32F746G-Discovery board. You can tune the parameters such as Gain, Center Frequency and Bandwidth during the simulation and the model will dynamically generate the SOS Filter coefficients. You can view the magnitude response of the tuned equalizer using the 'Filter Visualizer'.

For detailed information on the generated code, view the Code Generation Report.