Generating chirp with dsp.NCO system object in frame-based processing mode

5 次查看(过去 30 天)
Dear all,
I want to generate a chirp with a dsp.NCO instance by inputting a column vector of phase increments in order to achieve frame-based processing. Most of the code I took from the example. The phase offset is constant and therefor set as property.
Fstart = 50; % start freq of chirp
Fstop = 1500; % stop freq of chirp
df = 0.05; % Frequency resolution = 0.05 Hz
minSFDR = 96; % Spurious free dynamic range >= 96 dB
Ts = 1/8000; % Sample period = 1/8000 sec
dphi = pi/2; % Desired phase offset = pi/2;
Fmom = linspace(Fstart,Fstop,1/Ts)'; % Momentary frequency
% Design the NCO source.
Nqacc = ceil((minSFDR-12)/6);
Nacc = ceil(log2(1/(df*Ts)));
phOffset = 2^Nacc*dphi/(2*pi);
nco = dsp.NCO('PhaseOffsetSource','Property',...
'PhaseOffset', phOffset,...
'NumQuantizerAccumulatorBits', 14,...
'SamplesPerFrame', 1/Ts, ...
'CustomAccumulatorDataType', numerictype([],Nacc));
% convert freqs to phase increments
phIncr = int32(round(Fmom.*Ts.*2.^Nacc));
% generate chirp signal with colomn input, one step only
y = nco(phIncr);
%plot chirp
t = 0:Ts:(1/Ts-1)*Ts;
plot(t,y)
In the plot you'll see that the output of the NCO remains at the start freq and does not provide the chirp.
Who can help me to get the dsp.NCO instance work with variable freqs in framebased mode?
Patrick

回答(1 个)

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU 2024-8-20
Hi Patrick,
you can try using the following code:
Fstart = 50; % Start frequency of chirp
Fstop = 1500; % Stop frequency of chirp
df = 0.05; % Frequency resolution = 0.05 Hz
minSFDR = 96; % Spurious free dynamic range >= 96 dB
Ts = 1/8000; % Sample period = 1/8000 sec
dphi = pi/2; % Desired phase offset = pi/2;
Fmom = linspace(Fstart, Fstop, 1/Ts)'; % Momentary frequency
% Design the NCO source
Nqacc = ceil((minSFDR-12)/6);
Nacc = ceil(log2(1/(df*Ts)));
phOffset = 2^Nacc * dphi / (2 * pi);
nco = dsp.NCO('PhaseOffsetSource', 'Property', ...
'PhaseOffset', phOffset, ...
'NumQuantizerAccumulatorBits', 14, ...
'SamplesPerFrame', 1, ... % Process one sample at a time
'CustomAccumulatorDataType', numerictype([], Nacc));
% Convert frequencies to phase increments
phIncr = int32(round(Fmom .* Ts .* 2.^Nacc));
% Generate chirp signal
y = zeros(length(phIncr), 1);
for k = 1:length(phIncr)
y(k) = nco(phIncr(k));
end
% Plot chirp
t = (0:length(y)-1) * Ts;
plot(t, y);
xlabel('Time (s)');
ylabel('Amplitude');
title('Generated Chirp Signal');
Key Changes:
  • Changed "SamplesPerFrame" to 1 to process one sample at a time, ensuring the phase increment is updated for each sample.
  • Added a loop to generate the chirp signal sample-by-sample using the "nco" object.
  • Adjusted the plot to reflect the entire duration of the chirp signal.

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by