Main Content

Synthesize Variable Frequency Tones Using Android Devices

This example shows how to use the Simulink® Support Package for Android® Devices to produce tones of variable frequency. Use the example to generate noise in different tones for an audio system. This example uses the Audio Oscillator block to generate sinusoidal, square, and sawtooth waveforms. You can tune the frequency and amplitude of the sinusoidal noise signal from the dashboard panel deployed on your Android device.

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 Simulink Model and Calibrate Parameters

Open the androidAudioOscillator Simulink model.

Simulation Sources

Use the Constant blocks to set the frequency and amplitude of the sinusoidal noise signal. Set the frequency Constant block to 100 and the amplitude Constant block to 1.

Android Inputs

The frequency and amplitude of the sinusoidal noise signal is connected to the Edit and Slider Dashboard blocks, respectively.

Algorithm

Three Audio Oscillator blocks are used to generate sinusoidal, square, and sawtooth waveforms, respectively. You can set the sinusoidal frequency and amplitude of the Audio Oscillator block using the Constant block inputs from the Simulation Sources area.

For the Audio Oscillator block that produces a sinusoidal signal as the output, configure these parameters in the Block Parameters dialog box.

  1. Set Signal type to sine.

  2. Select Specify frequency from input port.

  3. Select Specify amplitude from input port.

  4. Set Samples per frame to 4410.

For the Audio Oscillator block that produces a square signal as the output, configure these parameters in the Block Parameters dialog box.

  1. Set Signal type to square.

  2. Set Frequency (Hz) to 100.

  3. Set Amplitude to 1.

  4. Set Samples per frame to 4410.

For the Audio Oscillator block that produces a sawtooth signal as the output, configure these parameters in the Block Parameters dialog box.

  1. Set Signal type to sawtooth.

  2. Set Frequency (Hz) to 100.

  3. Set Amplitude to 1.

  4. Set Samples per frame to 4410.

Display and Visualization

In the Display and Visualization area, you can view the filtered signals on the Time Scope and Spectrum Analyzer blocks.

Android Outputs

The selected audio signal output from the Audio Oscillator block is converted from single to int16 data type in the convert to stereo and int16 type subsystem and then played on the Android speaker using the Audio Playback block.

Run Simulink Model

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

  2. Change the frequency and amplitude of the sinusoidal, square, and sawtooth signal outputs from the Audio Oscillator blocks and observe the time scope and spectrum analyzer outputs.

Deploy Simulink Model on Android Device

Using this Simulink model, you can observe only one noise signal output on the application.

1. In the Algorithm area, position the manual switch to receive the sinusoidal noise signal output from the Audio Oscillator block.

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

3. On the Dashboard tab of the application, change the frequency and amplitude of the sinusoidal noise signal.

4. On the App tab of the application, observe the corresponding change in the sinusoidal waveform.

5. Connect your headphones to the Android device and notice the change in the tone as you tune the frequency and amplitude of the sinusoidal noise signal.

6. Similarly, position both the manual switches in the Algorithm area to receive the square noise signal output from the Audio Oscillator blocks and redeploy the Simulink model.

7. To change the frequency and amplitude of the square noise signals using the dashboard controls on the application, use Constant blocks as used for Audio Oscillator block for sinusoidal signal output. Connect the frequency and amplitude outputs to display their outputs on the Edit and Slider dashboard blocks, respectively.

8. Connect your headphones to the Android device and notice the change in the tone for the square noise signal.

9. Repeat the steps to observe the change in the tone for the sawtooth noise signal.

See Also