This example shows how to build an FM mono or stereo receiver using MATLAB® and Communications System Toolbox™. You can either use captured signals or receive signals in real time using the Communications System Toolbox Support Package for RTL-SDR Radio.
To run this example using captured signals, you need the following software:
To receive signals in real time, you also need the following hardware:
and the following software
For a full list of Communications System Toolbox supported SDR platforms, refer to Supported Hardware section of Software Defined Radio (SDR) discovery page.
FM broadcasting uses frequency modulation (FM) to provide high-fidelity sound transmission over broadcast radio channels. Pre-emphasis and de-emphasis filters are used to reduce the effect of noise on high audio frequencies. Stereo encoding enables simultaneous transmission of both left and right audio channels over the same FM channel .
Type FMReceiverExample in the MATLAB Command Window or click the link to run the example. You need to enter the following information when you run the example:
Reception duration in seconds
Signal source (captured data or RTL-SDR radio)
FM channel frequency
The example plays the received audio over your computer's speakers.
The FM Broadcast Demodulator Baseband System object™ converts the sampling rate of 240 kHz to 48 kHz, a native sampling rate for your host computer's audio device. According to the FM broadcast standard in the United States, the de-emphasis lowpass filter time constant is set to 75 microseconds. This example processes received stereo signals. The demodulator can also process mono signals.
To perform stereo decoding, the FM Broadcast Demodulator Baseband object uses a peaking filter which picks out the 19 kHz pilot tone from which the 38 kHz carrier is created. Using the obtained carrier signal, the FM Broadcast Demodulator Baseband block downconverts the L-R signal, centered at 38 kHz, to baseband. Afterwards, the L-R and L+R signals pass through a 75 microsecond de-emphasis filter . The FM Broadcast Demodulator Baseband block separates the L and R signals and converts them to the 48 kHz audio signal.
The receiver asks for user input and initializes variables. Then, it calls the signal source and FM broadcast receiver in a loop. The loop also keeps track of the radio time using the frame duration and lost samples reported by the signal source.
The latency output of the signal source is an indication of when the samples were actually received and can be used to determine how close to real time the receiver is running. A latency value of 1 and a lost samples value of 0 indicates that the system is running in real-time. A latency value of greater than one indicates that the receiver was not able to process the samples in real time. Latency is reported in terms of the number of frames. It can be between 1 and 128. If latency is greater than 128, then samples are lost.
% Request user input from the command-line for application parameters userInput = helperFMUserInput; % Calculate FM system parameters based on the user input [fmRxParams,sigSrc] = helperFMConfig(userInput); % Create FM broadcast receiver object and configure based on user input fmBroadcastDemod = comm.FMBroadcastDemodulator(... 'SampleRate', fmRxParams.FrontEndSampleRate, ... 'FrequencyDeviation', fmRxParams.FrequencyDeviation, ... 'FilterTimeConstant', fmRxParams.FilterTimeConstant, ... 'AudioSampleRate', fmRxParams.AudioSampleRate, ... 'Stereo', true); % Create audio player player = audioDeviceWriter('SampleRate',fmRxParams.AudioSampleRate); % Initialize radio time radioTime = 0; % Main loop while radioTime < userInput.Duration % Receive baseband samples (Signal Source) if fmRxParams.isSourceRadio [rcv,~,lost,late] = sigSrc(); else rcv = sigSrc(); lost = 0; late = 1; end % Demodulate FM broadcast signals and play the decoded audio audioSig = fmBroadcastDemod(rcv); player(audioSig); % Update radio time. If there were lost samples, add those too. radioTime = radioTime + fmRxParams.FrontEndFrameTime + ... double(lost)/fmRxParams.FrontEndSampleRate; end % Release the audio and the signal source release(sigSrc) release(fmBroadcastDemod) release(player)
To further explore the example, you can vary the center frequency of the RTL-SDR radio and listen to other radio stations.
You can set the Stereo property of the FM demodulator object to false to process the signals in mono fashion and compare the sound quality.
You can explore following function for details of the system parameters: