MATLAB Examples

FM Receiver with USRP® Hardware

This example shows how to use the Universal Software Radio Peripheral® (USRP®) device with MATLAB® to build an FM broadcast receiver.

In order to run this example, you need a USRP® board with an appropriate receiver daughterboard that supports the FM band (e.g., TVRX or WBX). Please refer to the Setup and Configuration section of Documentation for USRP® Radio for details on configuring your host computer to work with the SDRu Receiver System object™.

Contents

Discover Radio

Discover radio(s) connected to your computer. This example uses the first USRP® radio found using the findsdru function. Check if the radio is available and record the radio type. If no available radios are found, the example uses a default configuration for the system but does not run the main loop.

connectedRadios = findsdru;
if strncmp(connectedRadios(1).Status, 'Success', 7)
  radioFound = true;
  platform = connectedRadios(1).Platform;
  switch connectedRadios(1).Platform
    case {'B200','B210'}
      address = connectedRadios(1).SerialNum;
    case {'N200/N210/USRP2','X300','X310'}
      address = connectedRadios(1).IPAddress;
  end
else
  radioFound = false;
  address = '192.168.10.2';
  platform = 'N200/N210/USRP2';
end

Initialization

The getParamsSdruFMExamples.m function initialize some simulation parameters and generates a structure, fmRxParams. The fields of this structure are the parameters of the FM receiver system at hand.

fmRxParams = getParamsSdruFMExamples(platform)

Configuration of Receiver Object

The script communicates with the USRP® board using the SDRu System object. B200 and B210 series USRP® radios are addressed using a serial number while USRP2, N200, N210, X300 and X310 radios are addressed using an IP address. Master clock rate is configurable for B2xx and X3xx series radios.

% Set up radio object to use the found radio
switch platform
  case {'B200','B210'}
    radio = comm.SDRuReceiver(...
      'Platform', platform, ...
      'SerialNum', address, ...
      'MasterClockRate', fmRxParams.RadioMasterClockRate);
  case {'X300','X310'}
    radio = comm.SDRuReceiver(...
      'Platform', platform, ...
      'IPAddress', address, ...
      'MasterClockRate', fmRxParams.RadioMasterClockRate);
  case {'N200/N210/USRP2'}
    radio = comm.SDRuReceiver(...
      'Platform', platform, ...
      'IPAddress', address);
end

Set the center frequency to 102.5 MHz and the gain to 30 dB. Set the master clock rate and decimation factor to obtain a sample rate of 200 kHz at the output of the SDRu receiver object. For example, for a B210 radio, set MasterClockRate to 20 MHz and DecimationRate to 100. For N200, N210, and USRP2 radios master clock rate is fixed at 100 MHz. The 200 kHz sample rate is not aliased the audio signal, however, it enables real time operation on desktop. Set the frame length to 4000 samples. Select the output data type as single to reduce the required memory and speed up execution.

radio.CenterFrequency  = 102.5e6;
radio.Gain = fmRxParams.RadioGain;
radio.DecimationFactor = fmRxParams.RadioDecimationFactor;
radio.SamplesPerFrame = fmRxParams.RadioFrameLength;
radio.OutputDataType = 'single'

You can obtain information about the daughterboard using the info method of the object. This method returns a structure with fields that specify the valid range of SDRu properties. You can verify that the daughterboard covers the FM broadcast frequency range, which is 88 MHZ to 108 MHz.

hwInfo = info(radio)

FM Demodulation

This example uses the FM Broadcast Demodulator Baseband System object to demodulate the received signal. The block also 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 deemphasis lowpass filter time constant is set to 75 microseconds. Set up the demodulator to process stereo signals. The demodulator can also process the signals in a mono fashion.

fmBroadcastDemod = comm.FMBroadcastDemodulator(...
    'SampleRate', fmRxParams.RadioSampleRate, ...
    'FrequencyDeviation', fmRxParams.FrequencyDeviation, ...
    'FilterTimeConstant', fmRxParams.FilterTimeConstant, ...
    'AudioSampleRate', fmRxParams.AudioSampleRate, ...
    'PlaySound', true, ...
    'BufferSize', fmRxParams.BufferSize, ...
    'Stereo', true);

To perform stereo decoding, the FM Broadcast Demodulator Baseband block 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 deemphasis filter . The FM Broadcast Demodulator Baseband block separates the L and R signals and converts them to the 48 kHz audio signal.

Stream Processing Loop

Capture FM signals and apply FM demodulation for 10 seconds, which is specified by fmRxParams.StopTime. The SDRu object returns a column vector, x. Because the MATLAB script may run faster than the hardware, the object also returns the actual size of the valid data in x using the second output argument, len. If len is zero, then there is no new data for the demodulator code to process. The demodulator downconverts the sampling rate to 152 kHz and than performs FM demodulation. The stereo decoder extracts the 19 kHz pilot signal and generates a 38 kHz reference tone to convert the L-R channel to baseband. After compensating for the loss in the L-R channel, both L-R and L+R channels pass through a rate converter and deemphasis filter. The resulting 48 kHz signal is separated into the left and right channels and sent to the audio device.

Check for the status of the USRP® radio

if radioFound
  % Loop until the example reaches the target stop time, which is 10
  % seconds.
  timeCounter = 0;
  while timeCounter < fmRxParams.StopTime
    [x, len] = step(radio);
    if len > 0
      % FM demodulation
      step(fmBroadcastDemod, x);
      % Update counter
      timeCounter = timeCounter + fmRxParams.AudioFrameTime;
    end
  end
else
  warning(message('sdru:sysobjdemos:MainLoop'))
end

Release the FM Broadcast Demodulator Baseband and USRP® resources.

release(fmBroadcastDemod)
release(radio)

Conclusion

In this example, you used Communications System Toolbox™ System objects to build an FM receiver utilizing the USRP® device. The example showed that the MATLAB script can process signals captured by the USRP® device in real time.

Further Exploration

To further explore the example, you can vary the center frequency of the USRP® device and listen to other radio stations.

If you have your own FM transmitter that can transmit .wma files, you can duplicate the test that shows the channel separation result above. Load the sdruFMStereoTestSignal.wma file into your transmitter. The channel separation can be easily observed from the spectrum and heard from the audio device. You can also adjust the gain compensation to see its effect on stereo separation.

You can set the Stereo property of the FM demodulator object to false to process the signals in a mono fashion and compare the sound quality.

Appendix

The following function is used in this example.

Selected Bibliography

Copyright Notice

Universal Software Radio Peripheral® and USRP® are trademarks of National Instruments Corp.