MATLAB Code to Demodulate Broadcast FM Signals

This is the MATLAB code to demodulate FM signals received by RTL-SDR.

clear all
frontEndSampleRate = 228e3;
userInput.Duration = 20;
fmRxParams.isSourceRadio = 1
% fmRxParams.isSourcePlutoSDR = 0
fmRxParams.FrequencyDeviation = 75e3; % Hz
fmRxParams.FilterTimeConstant = 75e-6; % Seconds
fmRxParams.AudioSampleRate = 228000/5; % Hz, make sure rate is friendly with default BB 
%%
sigSrc = comm.SDRRTLReceiver('0',...
      'CenterFrequency',94.6e6,...
      'EnableTunerAGC',true,...
      'SampleRate',228e3,...
      'OutputDataType','single',...
      'FrequencyCorrection',0);

  fmDemod = comm.FMBroadcastDemodulator(...
  'SampleRate', frontEndSampleRate, ...
  'FrequencyDeviation', fmRxParams.FrequencyDeviation, ...
  'FilterTimeConstant', fmRxParams.FilterTimeConstant);
fmInfo = info(fmDemod)

% Frame length of SDRr Receiver and buffer size of FM Broadcast Demodulator
% Frame length must be an integer multiple of FM DecimationFactor
N = 3840; 
frontEndSamplesPerFrame = N*fmInfo.AudioDecimationFactor; 
fmRxParams.BufferSize = frontEndSamplesPerFrame;
fmRxParams.FrontEndFrameTime = ...
frontEndSamplesPerFrame / frontEndSampleRate;
sigSrc.SamplesPerFrame = frontEndSamplesPerFrame;
fmRxParams.FrontEndSampleRate = frontEndSampleRate;
fmRxParams.FrontEndSamplesPerFrame = frontEndSamplesPerFrame;

    
%% 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', false);

player = audioDeviceWriter('SampleRate',fmRxParams.AudioSampleRate);

radioTime = 0;
while radioTime < userInput.Duration
    [rcv,~,lost,late] = sigSrc();
    audioSig = fmBroadcastDemod(rcv);
    player(audioSig);
    radioTime = radioTime + fmRxParams.FrontEndFrameTime + ...
    double(lost)/fmRxParams.FrontEndSampleRate;
end

release(sigSrc)
release(fmBroadcastDemod)
release(player)
displayEndOfDemoMessage(mfilename)
Advertisements

Comments Invited

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s