How to transmit and receive a sinusoid using BPSK modulation and demodulation schemes utilizing the built in Family Radio Service (FRS) Full-Duplex Transceiver with USRP® Hardware?

10 views (last 30 days)
Hi, I am trying to utilize the built in code for the Family Radio Service (FRS) Full-Duplex Transceiver with USRP® Hardware environment. I want to run the tests for several modulation and demodulation schemes. I am using USRP N210 Loop back connection. I believe the transmitter end works well and I am facing problems in recovering the data from the receiver side. I am copying the code below. I will be very grateful if someone can help me with this. Thank you.
clear all
close all
clc
%Discover Radio
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
% Transmitter Initialization
rfTxFreq = 15e6; % RF Transmitter Center Frequency (Hz)
frsFDTxParams = configureFDTx(platform, rfTxFreq);
% Receiver Initialization
rfRxFreq = 15e6; % RF Receiver Center Frequency (Hz)
rfRxFreqCorrection = -4e3; % Frequency calibration compensation value (Hz)
rfRxFreqActual = rfRxFreq + rfRxFreqCorrection;
frsFDRxParams = configureFDRx(platform, rfRxFreqActual);
% Create a data source to transmit the contents of a sound file at a
% sampling frequency of 8 kHz.
% source = FRSGMRSDemoSource('Sound file', frsFDTxParams.SourceSampleRate);
% source.AudioFileName = 'speech_dft.avi';
source = FRSGMRSDemoSource('Pure Tone', frsFDTxParams.SourceSampleRate);
% PP=source();
% source.AudioFileName = 'speech_dft.avi';
% The Continuous Tone-Coded Squelch System (CTCSS) filters out
% undesired communication or interference from these other users by
% generating a tone between 67 Hz and 250 Hz and transmitting it along with
% the source signal.
ctcss = dsp.SineWave(frsFDTxParams.CTCSSAmplitude, ...
frsFDTxParams.CTCSSToneFrequencies(frsFDTxParams.CTCSSCode), ...
'SampleRate', frsFDTxParams.SourceSampleRate, ...
'SamplesPerFrame', frsFDTxParams.SourceFrameLength, ...
'OutputDataType', 'single');
% The interpolator and BPSK modulator convert the sampling rate of the sum of
% the modulating signal and the CTCSS tone to match the USRP(R) hardware
% sampling rate of 200 kHz.
interpolator = dsp.FIRInterpolator(frsFDTxParams.InterpolationFactor, ...
frsFDTxParams.InterpolationNumerator);
BPSKMod = comm.BPSKModulator;
BPSKMod.PhaseOffset = pi/4;
% Set up transmitter radio object to use the found radio
switch platform
case {'B200','B210'}
radioTx = comm.SDRuTransmitter('Platform', platform, ...
'SerialNum', address, ...
'MasterClockRate', frsFDTxParams.RadioMasterClockRate, ...
'CenterFrequency', frsFDTxParams.CenterFrequency,...
'Gain', frsFDTxParams.RadioGain, ...
'InterpolationFactor', frsFDTxParams.RadioInterpolationFactor)
case {'X300','X310'}
radioTx = comm.SDRuTransmitter('Platform', platform, ...
'IPAddress', address, ...
'MasterClockRate', frsFDTxParams.RadioMasterClockRate, ...
'CenterFrequency', frsFDTxParams.CenterFrequency,...
'Gain', frsFDTxParams.RadioGain, ...
'InterpolationFactor', frsFDTxParams.RadioInterpolationFactor)
case {'N200/N210/USRP2'}
radioTx = comm.SDRuTransmitter('Platform', platform, ...
'IPAddress', address, ...
'CenterFrequency', frsFDTxParams.CenterFrequency,...
'Gain', frsFDTxParams.RadioGain, ...
'InterpolationFactor', frsFDTxParams.RadioInterpolationFactor)
end
% Set up transmitter radio object to use the found radio
switch platform
case {'B200','B210'}
radioRx = comm.SDRuReceiver('Platform', platform, ...
'SerialNum', address, ...
'MasterClockRate', frsFDRxParams.RadioMasterClockRate, ...
'CenterFrequency', frsFDRxParams.CenterFrequency,...
'Gain', frsFDRxParams.RadioGain, ...
'DecimationFactor', frsFDRxParams.RadioDecimationFactor, ...
'SamplesPerFrame', frsFDRxParams.RadioFrameLength, ...
'OutputDataType', 'single')
case {'X300','X310'}
radioRx = comm.SDRuReceiver('Platform', platform, ...
'IPAddress', address, ...
'MasterClockRate', frsFDRxParams.RadioMasterClockRate, ...
'CenterFrequency', frsFDRxParams.CenterFrequency,...
'Gain', frsFDRxParams.RadioGain, ...
'DecimationFactor', frsFDRxParams.RadioDecimationFactor, ...
'SamplesPerFrame', frsFDRxParams.RadioFrameLength, ...
'OutputDataType', 'single')
case {'N200/N210/USRP2'}
radioRx = comm.SDRuReceiver('Platform', platform, ...
'IPAddress', address, ...
'CenterFrequency', frsFDRxParams.CenterFrequency,...
'Gain', frsFDRxParams.RadioGain, ...
'DecimationFactor', frsFDRxParams.RadioDecimationFactor, ...
'SamplesPerFrame', frsFDRxParams.RadioFrameLength, ...
'OutputDataType', 'single')
end
% AGC
agc = comm.AGC;
% Low pass filter for channel separation
channelFilter = frsFDRxParams.ChannelFilter;
% BPSK demodulator
% Decimation filter to resample to 8 kHz
decimator = dsp.FIRDecimator(frsFDRxParams.DecimationFactor, ...
frsFDRxParams.DecimationNumerator);
% The CTCSS decoder compares the estimated received code with the
% preselected code and then sends the signal to the audio device if the two
% codes match.
decoder = FRSGMRSDemoCTCSSDecoder(...
'MinimumBlockLength', frsFDRxParams.CTCSSDecodeBlockLength, ...
'SampleRate', frsFDRxParams.AudioSampleRate);
% High pass filter to filter out CTCSS tones
audioFilter = frsFDRxParams.AudioFilter;
% Audio device writer
audioPlayer = audioDeviceWriter(frsFDRxParams.AudioSampleRate);
% Perform stream processing if a radio is found.
if radioFound
% Loop until the example reaches the target stop time.
timeCounter = 0;
while timeCounter < frsFDTxParams.StopTime
% Transmitter stream processing
% -----------------------------------------------------------------
dataTx = step(source); % Generate audio waveform
dataWTone = dataTx + step(ctcss); % Add CTCSS tones
% Interpolation BPSK modulation
outResamp = step(interpolator, dataWTone); % Resample to 200 kHz
KK=zeros(1,length(outResamp));
NN=KK';
for i=1:length(outResamp)
if outResamp(i)>0
NN(i)=1;
else NN(i)=0;
end
end
outMod = step(BPSKMod, NN);
% plot(outMod)
step(radioTx, outMod); % Transmit to USRP(R) radio
% Receiver stream processing
% -----------------------------------------------------------------
[dataRx, lenRx] = step(radioRx);
if lenRx > 0
outAGC = step(agc, dataRx); % AGC
outChanFilt = step(channelFilter, outAGC); % Adjacent channel filtering
rxAmp = mean(abs(outChanFilt));
if rxAmp > frsFDRxParams.DetectionThreshold
outThreshold = outChanFilt;
else
outThreshold = complex(single(zeros(frsFDRxParams.RadioFrameLength, 1)));
end
BPSKDemod=comm.BPSKDemodulator;
BPSKDemod.PhaseOffset = pi/4;
% BPSK demodulation and decimation
outBPSKDemod = step(BPSKDemod, outThreshold); % BPSK demodulate
outDecim = step(decimator, outBPSKDemod); % Resample to 8 kHz
% CTCSS decode and conditionally send to audio output
rcvdCode = step(decoder, outDecim);
if (rcvdCode == frsFDRxParams.CTCSSCode) || (frsFDRxParams.CTCSSCode == 0)
rcvdSig = outDecim;
else
rcvdSig = single(zeros(frsFDRxParams.AudioFrameLength, 1));
end
audioSig = step(audioFilter, rcvdSig); % Filter out CTCSS tones
step(audioPlayer, audioSig); % Audio output
timeCounter = timeCounter + frsFDRxParams.RadioFrameTime;
end
end
else
warning(message('sdru:sysobjdemos:MainLoop'))
end
% Release all SDRu and audio resources, FM Modulator and Demodulator
release(BPSKMod)
release(radioTx)
release(BPSKDemod)
release(radioRx)
release(audioPlayer)

Answers (0)

Categories

Find more on Communications Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!