frequencyOffset
Description
applies the specified frequency offset to the input signal Y = frequencyOffset(X,samplerate,offset)X.
Examples
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
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
offsetis a scalar, the function applies the same frequency offset to each channel.If
offsetis 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 inoffsetmust equal the number of columns inX.
Data Types: double
Output Arguments
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
The input signal X can be an array
of up to three dimensions, specified as
NS-by-NC-by-NB array.
NS is the number of samples.
NC is the number of channels.
NB is the number of batch observations. NB is an optional dimension that can be added to the input signal for all supported data types.
The same frequency offset is applied to each frame within the batched input.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2022aThe frequencyOffset function adds support of a batch dimension. When
adding frequency offset to a signal, batch mode processing allows you to process multiple
frames of input data with a batch dimension.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)