Main Content

FM Demodulation and Spectrum Analysis with USRP Radio

This example shows how to demodulate and perform wideband and narrowband analysis of the FM radio spectrum using a USRP™ radio. The wideband analysis involves capturing the entire FM band and identifying the strongest station, while the narrowband analysis focuses on real-time processing of a single FM station signal.

To run this example, you require, a USRP radio and Communications Toolbox Support Package for USRP Radio add on.

Select the Acquisition Type

Select the type of acquisition from the drop down menu.

acqType = "Narrowband | 750kSPS";

Set the sample rate, center frequency, and the number of samples per frame depending on the acquisition type.

if acqType == "Wideband | 20MSPS"
    fs = 20e6;
    fc = 98.0e6;
    samplesPerFrame = 65536;

else
    fs = 500e3;
    fc = 101.1e6;
    samplesPerFrame = 5000;
end

Configure SDRu Receiver System Object

Set the receive gain in dB.

rxGain = 30.0;

Create a receiver System object.

rx = comm.SDRuReceiver(Platform="B210",SerialNum='3136D5F',...
    CenterFrequency=fc,ChannelMapping=1,Gain=rxGain,...
    TransportDataType='int16',OutputDataType='Same as transport data type',...
    SamplesPerFrame=samplesPerFrame);

Set the decimation factor.

rx.DecimationFactor = round(rx.MasterClockRate./fs);

Calculate the sample rate by dividing the master clock rate by the decimation factor.

actualSampleRate = rx.MasterClockRate./rx.DecimationFactor;
Ts = 1/actualSampleRate;

Set the desired frame duration.

frameDuration = samplesPerFrame.*(1/actualSampleRate);

Receive and Demodulate FM Signal

Create an FM demodulator System object.

fmDemodulate = comm.FMBroadcastDemodulator( ...
    "SampleRate", actualSampleRate, ...
    "FrequencyDeviation",75e3, ...
    "PlaySound", true, ...
    "Stereo",true, ...
    "AudioSampleRate",48e3);

Create a dsp.spectrumAnalyzer System object to visualize the captured FM signal.

spectrumScope = spectrumAnalyzer("SampleRate",actualSampleRate, ...    
    "ViewType","spectrum", ...
    "SpectrumType","power", ...
    "PlotAsTwoSidedSpectrum",true, ...
    "Method","welch", ...
    "AveragingMethod","exponential", ...
    "SpectrumUnits", "dBFS", ...
    "FullScaleSource", "Property", ...
    "FullScale", 2^11, ...
    "AxesScaling", "Manual", ...
    "YLimits", [-80 +20], ...
    "ForgettingFactor", 0.95, ...
    "FrequencyOffset", fc);

Enable peak finder to identify the strongest FM station.

spectrumScope.PeakFinder.Enabled      = true;
spectrumScope.PeakFinder.NumPeaks     = 1;
spectrumScope.PeakFinder.LabelPeaks   = true;
spectrumScope.PeakFinder.LabelFormat = "x";

Receive the FM signal.

overrun = 0; 
for i=1:1000
     [iqdata,dataLen,overrun] = rx();     
     spectrumScope(iqdata)     
     drawnow    
     if (acqType == "Wideband | 20MSPS")         
         overrun = 0;    
     else               
         fmDemodulate(double(iqdata)./2^11);      
     end
end 
linux; GNU C++ version 10.3.0; Boost_107800; UHD_4.2.0.0-vendor

---------- see libuhd version information above this line ----------

Release the receiver System object rx.

release(rx);