Contenuto principale

frequencyOffset

Apply frequency offset to input signal

Since R2022a

Description

Y = frequencyOffset(X,samplerate,offset) applies the specified frequency offset to the input signal X.

example

Examples

collapse all

Display a rectangular 16-QAM signal frame that has a frequency offset.

Define simulation parameters and create a constellation diagram object to plot the signals.

M = 16;       % 16-QAM
spf = 1e3;    % Number of symbols per frame
fs = 1e5;     % Sample rate (Hz)
fOffset = 50; % Frequency offset (Hz)

refQAM = qammod(0:M-1,M,UnitAveragePower=true);
cd = comm.ConstellationDiagram( ...
    ReferenceConstellation={refQAM}, ...
    ShowLegend=true, ...
    ChannelNames={'Frequency offset signal'});

Generate a frame of random data and apply 16-QAM modulation.

data = randi([0 M-1],spf,1);
modSignal = qammod(data,M,UnitAveragePower=true);

Apply the frequency offset to the modulated signal and plot the constellation diagram. The frequency offset causes the constellation points to rotate tracing circles at the symbol magnitudes.

y = frequencyOffset(modSignal,fs,fOffset);
cd(y)

Define parameters to configure the signal and spectrum analyzer.

fc = 1e6;         % Carrier frequency (Hz)
fs = 4e6;         % Sample rate (Hz)
Nspf = 100e3;     % Number of samples per frame
freqSpan = 400e3; % Frequency span for spectrum computation (Hz)

Create sine wave and spectrum analyzer objects with the specified parameter values.

sinewave = dsp.SineWave(Amplitude=1, ...
    Frequency=fc, ...
    SampleRate=fs, ...
    SamplesPerFrame=Nspf, ...
    ComplexOutput=true);
sascope = spectrumAnalyzer( ...
    SampleRate=fs, ...
    FrequencySpan="Span and center frequency", ...
    CenterFrequency=fc, ...
    Span=freqSpan, ...
    SpectrumType="Power density", ...
    SpectrumUnits="dBW/Hz", ...
    ShowLegend=true, ...
    ChannelNames=["Input sine wave","Frequency-offset sine wave"], ...
    YLimits=[-50 10]);

Generate a sine wave signal.

x = sinewave();

Apply a frequency offset of 100 kHz to the signal.

offset = 100e3;
y = frequencyOffset(x,fs,offset);

Display the input and frequency-shifted signals by using the spectrum analyzer.

sascope(x,y)

When adding frequency offset to the signal, batch mode processing allows you to process input data with a batch dimension.

Initialize simulation parameters and preallocate arrays.

M = 16;                  % 16-QAM
spf = 1000;              % Number of symbols per frame
fs = 10000;              % Sample rate (Hz)
fOffset = [500,200,750]; % Frequency offset (Hz)
numFrames = 1e4;         % Number of frames

modSig = zeros(spf,3,numFrames);
offsetSig = zeros(spf,3,numFrames);
[timeDim,channelDim,batchDim] = size(modSig)
timeDim = 
1000
channelDim = 
3
batchDim = 
10000

Frame Mode Processing

Simulate frame mode processing in a for-loop and display the total run time.

tic
for k = 1:numFrames
    data = randi([0 M-1],spf,3);
    modSig(:,:,k) = qammod(data,M,UnitAveragePower=true);
    offsetSig(:,:,k) = frequencyOffset(modSig(:,:,k),fs,fOffset);
end
frameModeTime = seconds(toc)
frameModeTime = duration
   2.8527 sec

Batch Mode Processing

Simulate batch mode simulation processing and display the total run time.

tic
data = randi([0 M-1],spf,3,numFrames);
modSigB = qammod(data,M,UnitAveragePower=true);
offsetSigB = frequencyOffset(modSigB,fs,fOffset);
batchModeTime = seconds(toc)
batchModeTime = duration
   1.0364 sec

Input Arguments

collapse all

Input signal, specified as a column vector, matrix, or array. An additional Batch Dimension can be added.

Data Types: double | single
Complex Number Support: Yes

Sampling rate of the input signal in Hz, specified as a positive scalar.

Data Types: double

Frequency offset in Hz, specified as a scalar or row vector.

  • If offset is a scalar, the function applies the same frequency offset to each channel.

  • If offset is a vector, then each element specifies the frequency offset that the function applies to the corresponding column (channel) of the input signal. The number of elements in offset must equal the number of columns in X.

Data Types: double

Output Arguments

collapse all

Output signal, returned as a vector or array with the same dimensions and data type as X. The number of columns in Y corresponds to the number of channels.

Data Types: double | single
Complex Number Support: Yes

More About

collapse all

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2022a

expand all