Main Content

Add Effects to Audio Signals Using Android Devices

This example shows how to use the Simulink® Support Package for Android® Devices to add echo and wah effects to an audio signal using audio signal processing. It also shows how to estimate the frequency-domain transfer function of a system using the Discrete Transfer Function Estimator block.

Echo — Echo is the reflection of an audio signal that reaches the listener after a delay. Use this example to understand and study the importance of echo in various applications such as noise cancellation, sonar, radar, and many more.

Wah effect — Wah effect is the audio spectral glide created when the guitar pedal sweeps the peak response of a frequency filter up and down to create the effect.

Prerequisites

Required Hardware

  • Android device such as a phone or tablet

  • USB cable

  • Headphones with microphones

Hardware Setup

  1. Connect your Android device to the host computer using the USB cable.

  2. Connect the headphones to your Android device.

Configure androidAudioSimpleEcho Simulink Model and Calibrate Parameters

This example uses a preconfigured Simulink model from the Simulink Support Package for Android Devices to add an echo effect to an audio signal.

Open the androidAudioSimpleEcho Simulink model.

Echo adds a delayed version of the audio signal to the original signal. You can model the echo effect by delaying the audio signal and adding it back. Feedback is added to the delay to provide a fading effect. Use these blocks to observe the echo effect on the audio signal.

  • Delay — Delay applied to the audio signal. Set Delay length to 44100.

  • Gain — Linear gain of the delayed audio signal. Set Gain to 0.5.

  • Sum — Adds the delayed audio signal to the original signal.

For more information on how to configure the Simulation Sources, Android Inputs, Display and Visualization, and Android Output areas of the androidAudioSimpleEcho Simulink model, see Get Started with Audio Signal Processing Using Android Devices.

Run androidAudioSimpleEcho Model in Simulation Mode

  1. Position the manual switch in the Algorithm area to receive the simulation output from the Sine Wave block in the Simulation Sources area.

  2. On the Simulation tab of the Simulink model, click Run.

  3. Move the slider to change the frequency of the sinusoidal signal and observe the output in the spectrum analyzer and time scope.

Observe the echo ripples in the sinusoidal output due to the delay added to the original signal.

Run androidAudioSimpleEcho Model in External Mode

  1. Position the manual switch in the Algorithm area of the model to receive output from the Sine Wave block in the Simulation Sources area.

  2. On the Hardware tab of the Simulink model, in the Mode section, click Run on board. In the Run on Hardware section, click Monitor & Tune. The androidAudioSimpleEcho application launches automatically on your Android device.

  3. Connect headphones to your Android device and listen to the echo effect.

  4. In the model, use the slider and change the frequency of the sine wave. Listen to the echo effect.

Deploy androidAudioSimpleEcho Model to Android Device

1. Position the manual switch in the Algorithm area of the model to receive output from the Sine Wave block in the Simulation Sources area.

2. On the Hardware tab of the Simulink model, in the Mode section, click Run on board. In the Deploy section, click Build, Deploy & Start. The androidAudioSimpleEcho application launches automatically on your Android device.

3. On the App tab of the application, observe the echo ripples present in the audio signal. Connect headphones to your Android device and observe the echo effect.

4. To observe the effect of change in the sine wave frequency, change the frequency using the slider in the Simulink model and redeploy the Simulink model.

5. Position the manual switch in the Algorithm area of the model to receive output from the Audio Capture block in the Android Inputs area.

6. Redeploy the Simulink model. The androidAudioSimpleEcho application launches automatically on your Android device.

7. On the Dashboard tab of the application, change the frequency of the audio signal using the slider.

8. On the App tab of the application, observe the echo ripples present in the audio signal.

9. Connect headphones to your Android device. Speak through the microphone and listen to the echo effect.

Configure androidAudioSimpleEffects Simulink Model and Calibrate Parameters

This example uses a preconfigured Simulink model from the Simulink Support Package for Android Devices to add an echo effect to an audio signal.

Open the androidAudioSimpleEffects Simulink model.

Simulation Sources

Use the Audio File Read block to add any audio file from your host computer to the Simulink model. This block is configured to its default parameters. You can browse or enter the path of the audio file.

Android Inputs

Use the Audio Capture block to capture audio from the microphone in the deployment mode. This block is configured to its default parameters.

Algorithm

The default position of the manual switch is to receive the output from the Simulation Sources area.

The MATLAB Function block includes the code that generates the wah effect from the input audio signal.

The Discrete Transfer Function Estimator block computes the frequency-domain transfer function of the Simulink model. The input to the block is the system input and the system output.

Configure these parameters in the Block Parameters dialog box of the Discrete Transfer Function Estimator block.

  1. Set Number of spectral averages to 8.

  2. Set FFT length source to Property.

  3. Set FFT length to 1024.

  4. Set Frequency range to One-sided.

  5. Set Simulate using to Interpreted execution.

Display and Visualization

Use the spectrum analyzer to observe the wah effect.

The output of the estimator is the frequency response of the system, which is complex. To extract the magnitude portion of this complex estimate, use the Abs block. To convert the result into dB, the system uses a dB (1 ohm) block. Use the Array Plot block to observe the output of the estimator.

Android Output

Use the Audio Playback block to play audio on your Android device.

Run androidAudioSimpleEffects Model in Simulation Mode

  1. Position the manual switch in the Algorithm area to receive the simulation output from the Audio File Read block in the Simulation Sources area.

  2. On the Simulation tab of the Simulink model, click Run.

Observe the wah effect on the spectrum analyzer and the output of the Discrete Transfer Function Estimator block in the Array Plot.

Deploy androidAudioSimpleEffects Model to Android Device

1. Position the manual switch in the Algorithm area of the model to receive output from the Audio File Read block in the Simulation Sources area.

2. On the Hardware tab of the Simulink model, in the Mode section, click Run on board. In the Deploy section, click Build, Deploy & Start. The androidAudioSimpleEffects application launches automatically on your Android device.

3. On the App tab of the application, observe the output of the Discrete Transfer Function Estimator block in the Array Plot.

4. Position the manual switch in the Algorithm area of the model to receive output from the Audio Capture block in the Android Inputs area.

5. Redeploy the Simulink model. The androidAudioSimpleEffects application launches automatically on your Android device.

6. Connect headphones to your Android device. Speak through the microphone and observe output of the Discrete Transfer Function Estimator block in the Array Plot on the App tab of the application.

Other Things to Try

  • In the androidAudioSimpleEcho Simulink model, in the Simulation Sources area, replace the Sine Wave block with the Audio File Read block and run the Simulink model in simulation and deployment mode.

  • In the androidAudioSimpleEffects Simulink model, replace the code in the MATLAB Function block with the code in the simple_delay_effect.txt and simple_reverb_effect.txt files and run the Simulink model in simulation and deployment mode. You can find these .txt files in the example folder.

See Also