Main Content

Implement Bandpass Filter Using Android Devices

This example shows how to use the Simulink® Support Package for Android® Devices to design a bandpass filter using DSP System Toolbox™.

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 androidAudioDesignFilter Simulink model.

In simulation mode, you can use the slider on the dashboard panel to adjust the frequency of the sine wave from 1000 Hz to 6000 Hz. In deployment mode, you can deploy the Simulink model on your Android device and interface a microphone.

Simulation Sources

The Sine Wave block outputs a sinusoidal signal for simulation purposes. Use the Sine Wave:Frequency dashboard panel to control the frequency of this sinusoidal output.

Configure these parameters in the Block Parameters dialog box of the Sine Wave block.

  1. Set Amplitude to 1.

  2. Set Frequency to 2882.

  3. Set Sample time to 1/48000.

  4. Set Samples per frame to 960.

To adjust the frequency of the sinusoidal signal, set either the Frequency parameter in the Block Parameters dialog box of the Sine Wave block or use the slider on the dashboard panel.

Android Inputs

Use the Audio Capture block to capture audio from the microphone in the deployment mode. Configure these parameters in the Block Parameters dialog box of the Audio Capture block.

  1. Set Audio sampling frequency (Hz) to 48000.

  2. Set Frame size (N) to 960.

Algorithm

The default position of the manual switch is to receive sine wave data from the Simulation Sources area.

Design a bandpass filter using the Digital Filter Design (DSP System Toolbox) block. This filter has an order of 260 and allows a range of frequencies to pass above 3500 Hz and below 5500 Hz.

Configure these parameters in the Block Parameters dialog box of the Digital Filter Design (DSP System Toolbox) block.

1. In the Response Type section, select Bandpass.

2. In the Frequency Specifications section, set these parameters.

a. Units to Hz

b. Fs to 48000

c. Fstop1 to 3000

d. Fpass1 to 3500

e. Fpass2 to 5500

f. Fstop2 to 6000

In the Magnitude Specifications section, set these parameters.

a. Astop1 to 95

b. Apass to 1

c. Astop2 to 95

The Current Filter Information section shows information on the structure, order, stability, and source for the designed filter. The Magnitude Response (dB) section shows the filter corresponding to the above specifications.

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 audio signal output from the Digital Filter Design (DSP System Toolbox) 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. In the Simulation Sources area, position the manual switch to receive output from the Sine Wave block.

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

3. Change the frequency of the audio signal to 2882 Hz and observe the output on the time scope and spectrum analyzer. The signal does not pass through the bandpass filter.

4. Change the frequency of the audio signal to 4000 Hz and observe the output on the time scope and spectrum analyzer. The signal passes through the bandpass filter.

Deploy Simulink Model

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 androidAudioDesignFilter application launches automatically on your Android device.

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

4. On the App tab of the application, observe how the signal with frequency within the range of 3500 Hz and 5500 Hz pass through the filter while all the other frequencies are attenuated. Observe the output on the androidAudioDesignFilter application for a signal with frequency 4000 Hz and 2882 Hz. Connect your headphones to the Android device and observe that you cannot hear any tone for the audio signal when you set the frequency outside the bandpass filter range.

Application Output for 4000-Hz Signal

Application Output for 2882-Hz Signal

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. 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 androidAudioGettingStarted application launches automatically on your Android device.

7. Connect to your headphones to the Android device and listen to the audio signal output.

Other Things to Try

  • Design a filter other than a bandpass filter using the Digital Filter Design block.

  • Design a filter with different stop and pass frequencies for the bandpass filter.

  • Change the order of the bandpass filter and observe the output on spectrum analyzer and time scope for different input frequencies.

See Also