www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/DesignanNCOSourceExample.m
%% Design an NCO Source % Design an NCO source according to specifications. % % Specifications: F0 = 510; % Output frequency = 510 Hz df = 0.05; % Frequency resolution = 0.05 Hz minSFDR = 96; % Spurious free dynamic range >= 96 dB Ts = 1/4000; % Sample period = 1/4000 seconds dphi = pi/2; % Desired phase offset = pi/2; %% % Calculate number of accumulator bits required for the frequency resolution. Nacc = ceil(log2(1/(df*Ts))); actdf = 1/(Ts*2^Nacc); % Actual frequency resolution achieved %% % Calculate number of quantized accumulator bits required from the SFDR % requirement. Nqacc = ceil((minSFDR-12)/6); %% % Calculate the phase increment. phIncr = round(F0*Ts*2^Nacc); %% % Calculate the phase offset. phOffset = 2^Nacc*dphi/(2*pi); %% % Construct NCO HDL System object(TM). hdlnco = dsp.HDLNCO('PhaseIncrementSource','Property', ... 'PhaseIncrement',phIncr,... 'PhaseOffset',phOffset,... 'NumDitherBits',4, ... 'NumQuantizerAccumulatorBits',Nqacc,... 'AccumulatorWL',Nacc) for k = 1:1/Ts y(k) = step(hdlnco,true); end %% % Plot the mean-square spectrum of the 510 Hz sine wave generated by the % NCO. sa = dsp.SpectrumAnalyzer('SampleRate',1/Ts); sa.SpectrumType = 'Power density'; sa.PlotAsTwoSidedSpectrum = false; step(sa,y');