|
楼主 |
发表于 2014-8-16 10:34:54
|
显示全部楼层
回复 2# analogtracking 直接将代码贴上来了,请多指教
clear
fs=26e6; % sample clock
NumberSamples=2^12;
BusSize=28; %bits
Fraction=0.61; % usable 0 to 1
FractionInternal=2^BusSize*Fraction;
AccumulatorBits=28 ; %bits
AccumulatorSize=2^AccumulatorBits;
% adither=2^3/(2^AccumulatorBits);
% dither_array=FractionInternal*adither*randn(1,NumberSamples);
dither_array=zeros(1,NumberSamples);
C1(1:NumberSamples)=0;%Carry out of the first accumulator
C2(1:NumberSamples)=0;%Carry out of the 2nd accumulator
C3(1:NumberSamples)=0;%Carry out of the 3rd accumulator
U1(1:NumberSamples)=0;%output of the 1st accum
U2(1:NumberSamples)=0;%output of the 2nd accum
U3(1:NumberSamples)=0;%output of the 3rd accum
for index=2:NumberSamples
U1(index)=FractionInternal+dither_array(index)+U1(index-1); % adder model
U2(index)=U1(index-1)+U2(index-1);
U3(index)=U2(index-1)+U3(index-1);
if U1(index)>AccumulatorSize
C1(index)=1;
U1(index)=U1(index)-AccumulatorSize;
end
if U2(index)>AccumulatorSize
C2(index)=1;
U2(index)=U2(index)-AccumulatorSize;
end
if U3(index)>AccumulatorSize
C3(index)=1;
U3(index)=U3(index)-AccumulatorSize;
end
Y1(index)=C2(index)+C3(index)-C3(index-1);% feedback from the 2nd & 3rd stage
Yout(index)=C1(index)+Y1(index)-Y1(index-1);% output to the divider
end
MeanFrac=mean(Yout);
fprintf('\nMeanFracMASH= %1.4f\n',MeanFrac);
x_legend=fs/NumberSamples*linspace(0,NumberSamples-1,NumberSamples);
Yout_sp=20*log10(abs(fft(Yout)));
% plot(20*log10(abs(fft(Yout))));
semilogx(x_legend(1:NumberSamples/2),Yout_sp(1:NumberSamples/2),'b'); |
|