This example shows how to build an FM mono receiver using a Raspberry Pi™ and RTL-SDR radio. You will learn how to deploy a Simulink® model that processes FM broadcast signals and play the audio through the Raspberry Pi's speaker.
To run this example, you need the following hardware:
and the following software
For a full list of Communications Toolbox supported SDR platforms, refer to Supported Hardware section of Software Defined Radio (SDR) discovery page.
Simulink Support Package for Raspberry Pi Hardware enables you to create and run Simulink models on Raspberry Pi hardware. Communications Toolbox Support Package for RTL-SDR Radio enables you to receive radio signals from the RTL-SDR radio. You can use these two support packages together to receive and process RF signals on the Raspberry Pi hardware using Simulink software. In this example, you will learn how to run an FM receiver model as a standalone application on the Raspberry Pi hardware.
The following shows the FM receiver model. The model uses the
RTL-SDR Receiver block to receive radio signals and sends them to the
FM Broadcast Demodulator Baseband block. The FM demodulator block demodulates the received signal and generates mono audio. The mono signals are sent to the
ALSA Audio Playback block optimized for the Raspberry Pi hardware.
The following steps show you how to configure the model to run on the Raspberry Pi hardware.
1. If your Raspberry Pi hardware is not connected to an Ethernet network, follow the instructions in
Configure IP Settings on the Raspberry Pi Hardware.
2. In the model, set simulation stop time to 'inf' to run the simulation until you explicitly pause or stop the model.
3. In the Simulink model, click Tools > Run on Target Hardware> Options....
4. When the Configuration Parameters page opens up, set the Target hardware parameter to Raspberry Pi. Review the other parameters on that page. If you performed a Firmware Update, Board information will be automatically populated with the IP address, user name and password of your Raspberry Pi hardware. Also, notice the TCP/IP port edit box under Signal monitoring and parameter tuning. The default value of TCP/IP port is 17725. Simulink uses this TCP/IP port to communicate with Raspberry Pi hardware. Leave the TCP/IP port parameter at its default value. Click OK when you are done.
5. In the Simulink model, click the Deploy to Hardware button on the toolbar or press Ctrl+B.
6. The model will now run on the Raspberry Pi hardware. A system command window will open that shows the messages coming from the model running on Raspberry Pi hardware.
7. Connect speakers to the audio output of the Raspberry Pi hardware to listen to the radio.
8. Stop the model running on the Raspberry Pi hardware by executing the following on the MATLAB® command line
h = raspberrypi; stopModel(h,'FMReceiverRaspberryPiSimulinkExample');
Simulink Support Package for Raspberry Pi Hardware generates a Linux® executable for each Simulink model you run on the Raspberry Pi hardware.
1. To run/stop a Simulink model, you use the run and stop methods of the raspberrypi communication object. First, create a communication object to the Raspberry Pi hardware:
rpi = raspberrypi;
This command generates a Raspberry Pi object that is your gateway to communicating with your Raspberry Pi hardware from MATLAB command line.
2. Execute the following on the MATLAB command line to stop the Simulink model you ran in previous section:
3. To run a previously built Simulink model on your board, you use runModel method. In order to run the FMReceiverRaspberryPiSimulinkExample model, execute the following on the MATLAB command line:
This example introduced the workflow for receiving radio signals with an RTL-SDR radio and processing the received signals using a Simulink model running on Raspberry Pi hardware.