Model Code Profiling for Multiband Dynamic Range Compression System Using Android Device
This example shows how to use multi-rate multitasking along with real-time code execution profiling for a digital audio multiband dynamic range compression system on an Android® device.
Prerequisites
For more information on how to use the Simulink® Support Package for Android Devices to run a Simulink model on an Android device, refer to the Getting Started with Android Devices example.
For more information on multiband dynamic range compression, see Multiband Dynamic Range Compression (Audio Toolbox) example.
For more information on how to use multirate multitasking along with real-time code execution profiling for a Simulink model, see Model Multitask Execution and Real-Time Code Execution Profiling on Android Device example.
Required Hardware
Android device such as phone or tablet
Micro USB cable
Headphones with built-in speakers (recommended)
Open audiomultibanddynamiccompression
Simulink Model and Calibrate Parameters
This example uses a preconfigured Simulink model from the Simulink Support Package for Android Devices.
Open the audiomultibanddynamiccompression Simulink model.
In this example, the audio signal is first divided into four bands using a multiband crossover filter. Each band is compressed using a separate compressor. The four bands are then recombined to form the audio output. The dynamic range of the uncompressed and compressed signals (defined as the ratio of the largest absolute value of the signal to the signal RMS) is computed. To hear the difference between the original and compressed audio signals, toggle the switch on the top level.
The model integrates a User Interface (UI) designed to interact with the simulation. To launch the UI that controls the simulation, click 'Launch Parameter Tuning UI' on the model. This UI allows you to tune parameters, such as the compression ratio, the attack and release time, the threshold and the knee width, independently for each band. The effects of compression on the dynamic range of the signal can be observed on the Android application running in the external mode. Depending on the compression that you observe on the dynamic range of the signal, you can fine tune the band parameters while the Simulink model runs in the external mode.
For more information on how to enable Embedded Coder for the audiomultibanddynamiccompression
Simulink Model, see the Enable Embedded Coder Features section in the Model Multitask Execution and Real-Time Code Execution Profiling on Android Device example.
For more information on how to configure the external mode of the audiomultibanddynamiccompression
Simulink Model to run in a background thread, see the Run External Mode in Background Thread section in the Model Multitask Execution and Real-Time Code Execution Profiling on Android Device example.
For more information on how to configure the audiomultibanddynamiccompression
Simulink Model to detect and notify when a task overrun occurs, see the Detect Task Overruns section in the Model Multitask Execution and Real-Time Code Execution Profiling on Android Device example.
For more information on how to configure the audiomultibanddynamiccompression
Simulink Model for profiling the execution of different functions, see the Configure Code Execution Profiling for Simulink Model section in the Model Multitask Execution and Real-Time Code Execution Profiling on Android Device example.
Run Simulink Model in External Mode
On the Hardware tab of the Simulink model, in the Run on Hardware section, set the Stop Time to 30 seconds and click Monitor & Tune. Simulink writes the execution profiling data in the ModelName.txt
file in the application data cache location. For example, for the audiomultibanddynamiccompression
Simulink model, you can locate the file in the /storage/emulated/0/Android/data/com.example.audiomultibanddynamiccompression /files/audiomultibanddynamiccompression.txt path. Execute this command in the MATLAB® Command Window to transfer the file to the host computer. This command copies the text file as mentioned in the current working directory and saves the data in the output variable. In this example, the output variable is executionProfile
.
executionProfile = codertarget.profile.getData(audiomultibanddynamiccompression);
You can also visualize the data by executing this command.
coder.profile.show(executionProfile);
Observe and analyze the task execution times in the Task Execution
tab of the Code Profile Analyzer.
Similarly, observe and analyze the function execution times in the Function Execution
tab of the Code Profile Analyzer.
To improve the task and function execution times, tune the band parameters through the UI in real-time.
Deploy Simulink Model
After fine tuning the band parameters and observing the expected real-time code profiling results in the Code Profile Analyzer (Embedded Coder) application, you can deploy the audiomultibanddynamiccompression
Simulink model on your Android device.
On the Hardware tab of the Simulink model, in the Mode section, select Run on board and then click Build, Deploy & Start to build and deploy the model on the Android device. The audiomultibanddynamiccompression application launches automatically.
Start speaking through the microphone. We recommend that you use a headset to reduce the feedback loop between the microphone and the speaker. Observe the uncompressed and compressed audio signals. Press the Bypass button to hear the uncompressed audio signal.