%% Frequency Offset Calibration Transmitter with USRP(R) Hardware % % This example shows how to use the Universal Software Radio Peripheral(R) % devices exploiting SDRu (Software Defined Radio USRP(R)) System objects to % measure and calibrate for transmitter/receiver frequency offset at the % receiver using MATLAB(R). % % The USRP(R) Transmitter sends a sine wave at 100Hz with the MATLAB script, % , to the USRP(R) receiver. The USRP(R) % Receiver monitors received signals, calculates the transmitter/receiver % frequency offset and displays it in the MATLAB command window for % calibration with the MATLAB script, % . % Copyright 2013 The MathWorks, Inc. %% Introduction % The example provides the following information about the USRP(R) % transmitter/receiver link: % % * The quantitative value of the frequency offset % * A graphical view of the spur-free dynamic range of the receiver % * A graphical view of the qualitative SNR level of the received signal % % To calibrate the frequency offset between two USRP(R) devices, run % on one USRP(R) radio, while % simultaneously running on another USRP(R) radio. The % CenterFrequency property of the SDRu transmitter and receiver System % objects should have the same value. % % To compensate for a transmitter/receiver frequency offset, add the % displayed frequency offset value to the Center Frequency of the SDRu % Receiver System object. Be sure to use the sign of the offset in your % addition. Once you've done that, the spectrum displayed by the receiver's % spectrum analyzer System object should have its maximum amplitude at % roughly 0 Hz. % % Please refer to the Simulink(R) model for a block diagram view of the system. % % %% Hardware Requirements % To run this example, ensure that the center frequency of the % SDRu Transmitter and Receiver System objects is within the acceptable % range of your USRP(R) daughter board and the antennas you are using. Please % refer to <../../help/index.html Getting Started> for details on % configuring your host computer to work with the SDRu transmitter and % receiver System objects. % % %% Initialization % Set the properties of the sine wave source, the SDRu transmitter, and the % spectrum analyzer System object. % h = UsrpMaskMapiT('192.168.10.3', BoardIdCapiEnumT.MboardId) % c = ClockConfigCapiT % c.refSource = RefSourceCapiEnumT.External % c.ppsSource = PPSSourceCapiEnumT.External % c.ppsPolarity = PPSPolarityCapiEnumT.Positive % h.setClockConfigFull(c); %h1 = UsrpMaskMapiT('192.168.10.4', BoardIdCapiEnumT.MboardId) % c1 = ClockConfigCapiT % c1.refSource = RefSourceCapiEnumT.External % c1.ppsSource = PPSSourceCapiEnumT.External % c1.ppsPolarity = PPSPolarityCapiEnumT.Positive % h1.setClockConfigFull(c1); bbTxFreq = 1e3; % Transmitted baseband frequency rfTxFreq = 2.4e9; % Nominal RF transmit center frequency SineAmp = 1.0; SinePh = pi/4; prmFreqCalibTx_2 = configureFreqCalibTx_2(rfTxFreq, bbTxFreq, SineAmp, SinePh); % hSineSource = dsp.SineWave (... % 'Frequency', prmFreqCalibTx_2.SineFrequency, ... % 'Amplitude', prmFreqCalibTx_2.SineAmplitude,... % 'PhaseOffset', prmFreqCalibTx_2.SinePhase,... % 'ComplexOutput', prmFreqCalibTx_2.SineComplexOutput, ... % 'SampleRate', prmFreqCalibTx_2.Fs, ... % 'SamplesPerFrame', prmFreqCalibTx_2.SineFrameLength, ... % 'OutputDataType', prmFreqCalibTx_2.SineOutputDataType); % The host computer communicates with the USRP(R) radio using the SDRu % transmitter System object. You can supply the IP address of the USRP(R) % radio as an argument when you construct the object. The IP address can be % any address within the same subnet as your host computer. The parameter % structure, prmFreqCalibTx, sets the CenterFrequency, Gain, and % InterpolationFactor arguments. hSDRuTx1 = comm.SDRuTransmitter( ... 'IPAddress', '192.168.10.2', ... 'CenterFrequency', prmFreqCalibTx_2.USRPTxCenterFrequency, ... 'Gain', prmFreqCalibTx_2.USRPGain,... 'InterpolationFactor', prmFreqCalibTx_2.USRPInterpolationFactor) % hSDRuTx2 = comm.SDRuTransmitter( ... % 'IPAddress', '192.168.10.4', ... % 'CenterFrequency', prmFreqCalibTx.USRPTxCenterFrequency, ... % 'Gain', prmFreqCalibTx.USRPGain,... % 'InterpolationFactor', prmFreqCalibTx.USRPInterpolationFactor) % Use dsp.SpectrumAnalyzer to display the spectrum of the transmitted % signal. %hSpectrumAnalyzer1 = dsp.SpectrumAnalyzer(... % 'Name', 'Frequency of the Sine waveform sent out',... % 'Title', 'Frequency of the Sine waveform sent out',... % 'FrequencySpan', 'Full', ... % 'SampleRate', prmFreqCalibTx.Fs, ... % 'YLimits', [-70,30],... % 'SpectralAverages', 50, ... % 'FrequencySpan', 'Start and stop frequencies', ... % 'StartFrequency', -100e3, ... % 'StopFrequency', 100e3,... % 'Position', figposition([50 30 30 40])); %radio = findsdru(hSDRuTx.IPAddress); %if(strcmp(radio.Status, 'Success')) % prmFreqCalibTx_2 = configureFreqCalibTx_2(rfTxFreq, bbTxFreq, SineAmp, SinePh); for iFrame = 1: prmFreqCalibTx_2.TotalFrames SineAmp = iFrame/prmFreqCalibTx_2.TotalFrames SinePh = pi/4 + iFrame/prmFreqCalibTx_2.TotalFrames hSineSource = dsp.SineWave (... 'Frequency', prmFreqCalibTx_2.SineFrequency, ... 'Amplitude', prmFreqCalibTx_2.SineAmplitude,... 'PhaseOffset', prmFreqCalibTx_2.SinePhase,... 'ComplexOutput', prmFreqCalibTx_2.SineComplexOutput, ... 'SampleRate', prmFreqCalibTx_2.Fs, ... 'SamplesPerFrame', prmFreqCalibTx_2.SineFrameLength, ... 'OutputDataType', prmFreqCalibTx_2.SineOutputDataType); % % hSDRuTx1 = comm.SDRuTransmitter( ... % 'IPAddress', '192.168.10.2', ... % 'CenterFrequency', prmFreqCalibTx_2.USRPTxCenterFrequency, ... % 'Gain', prmFreqCalibTx_2.USRPGain,... % 'InterpolationFactor', prmFreqCalibTx_2.USRPInterpolationFactor) sinewave = step(hSineSource); % generate sine wave step(hSDRuTx1, sinewave); % transmit to USRP(R) radio % step(hSDRuTx2, sinewave); % transmit to USRP(R) radio % xt(iFrame)=sinewave; % yt(iFrame)=iFrame; end % Display the spectrum after the simulation. %step(hSpectrumAnalyzer, sinewave); %else % warning(message('sdru:sysobjdemos:MainLoop')) %end % figure(3); % plot(yt,xt); %% Release System Objects release (hSineSource); release (hSDRuTx1); %release (hSDRuTx2); %% Appendix % The following scripts are used in this example. % % * % * % %% Copyright Notice % Universal Software Radio Peripheral(R) and USRP(R) are trademarks of % National Instruments Corp. %displayEndOfDemoMessage(mfilename) displayEndOfDemoMessage(mfilename)