rcyang 发表于 2007-5-21 16:15

Defining and Testing Dynamic Parameters in High-Speed ADCs

请信号处理方面的高手帮忙调试一下程序

以下代码是maxic网上提供的测试高速adc动态参数的matlab代码,计算snr sinad
thd sfdr

我现在加的信号是采样频率40MHz 输入信号5MHz 得出来结果不对
如果我把输入频率改为20kHz,需要作什么调整?
采样频率40MHz是固定的,采样时间102.4us最好不要变,因为多100us,机器至少要多跑3天!


fclk=40e6; %fclk采样频率
ts=102.4e-6;
numpt=fclk*ts;%numpt 采样点数
f=5e6 % the input signal is 5Mhz!!

format long;
t=linspace(0,ts,numpt);%the total simulation time is 102.4us,M=4096
w=2*pi*f;                  
Dout=zeros(numpt,1);
for i=1:numpt         
Dout(i)=sin(w*t(i));            
end


%If no window function is used, the input tone must be chosen to be unique and with
%regard to the sampling frequency. To achieve this prime numbers are introduced and the
%input tone is determined by fIN = fSAMPLE * (Prime Number / Data Record Size).
%To relax this requirement, window functions such as HANNING and HAMING (see below) can
%be introduced, however the fundamental in the resulting FFT spectrum appears 'sharper'
%without the use of window functions.
Doutw=Dout;
%Doutw=Dout.*hanning(numpt);
%Doutw=Dout.*hamming(numpt);
%Performing the Fast Fourier Transform
Dout_spect=fft(Doutw);

%Recalculate to dB
Dout_dB=20*log10(abs(Dout_spect));

%Display the results in the frequency domain with an FFT plot
figure; %建立图形
maxdB=max(Dout_dB(1:numpt/2));
%For TTIMD, use the following short routine, normalized to —6.5dB full-scale.
%plot(.*fclk/numpt,Dout_dB(1:numpt/2)-maxdB-6.5);
plot(.*fclk/numpt,Dout_dB(1:numpt/2)-maxdB);
grid on;

title('FFT PLOT');
xlabel('ANALOG INPUT FREQUENCY (Hz)');
ylabel('AMPLITUDE (dB)');
a1=axis; axis();

%Calculate SNR, SINAD, THD and SFDR values
%Find the signal bin number, DC = bin 1
fin=find(Dout_dB(1:numpt/2)==maxdB);   %找出非零元素的索引号
%Span of the input frequency on each side
span=max(round(numpt/200),5);%span=max(round(numpt/200),5);
%Approximate search span for harmonics on each side
spanh=2;%spanh=2;
%Determine power spectrum
spectP=(abs(Dout_spect)).*(abs(Dout_spect));
%Find DC offset power
Pdc=sum(spectP(1:span));
%Extract overall signal power
Ps=sum(spectP(fin-span:fin+span));
%Vector/matrix to store both frequency and power of signal and harmonics
Fh=[];
%The 1st element in the vector/matrix represents the signal, the next element represents
%the 2nd harmonic, etc.
Ph=[];
%Find harmonic frequencies and power components in the FFT spectrum
for har_num=1:10 %har_num谐波总数
%Input tones greater than fSAMPLE are aliased back into the spectrum
tone=rem((har_num*(fin-1)+1)/numpt,1); %rem(x,y)x除以y的余数numpt(Number of Points)
if tone>0.5
%Input tones greater than 0.5*fSAMPLE (after aliasing) are reflected
tone=1-tone;
end
Fh=;
%For this procedure to work, ensure the folded back high order harmonics do not overlap
%with DC or signal or lower order harmonics
har_peak=max(spectP(round(tone*numpt)-spanh:round(tone*numpt)+spanh));
har_bin=find(spectP(round(tone*numpt)-spanh:round(tone*numpt)+spanh)==har_peak);
har_bin=har_bin+round(tone*numpt)-spanh-1;
Ph=;
end
%Determine the total distortion power
Pd=sum(Ph(2:5)); %Pd总失真功率Ph(1) is fundamental harmonic谐波 power
%Determine the noise power
Pn=sum(spectP(1:numpt/2))-Pdc-Ps-Pd;%Pn噪声功率Ps信号功率

format;%设置输出格式
A=(Dout+1)/2;%A=(max(code)-min(code))/2^numbit%A幅度
AdB=20*log10(A)%A幅度的db表示形式
SINAD=10*log10(Ps/(Pn+Pd)) % SINAD = 10*log10(Ps/(Pn+Pd))信号与噪声失真比
SNR=10*log10(Ps/Pn)% SNR = 10*log10(Ps/Pn)信噪比
disp('THD is calculated from 2nd through 5th order harmonics');
THD=10*log10(Pd/Ph(1)) % THD总谐波失真Pd总失真功率 Ph(1) 基波能量
SFDR=10*log10(Ph(1)/max(Ph(2:10)))%SFDR无杂散动态范围
disp('Signal & Harmonic Power Components:');
HD=10*log10(Ph(1:10)/Ph(1))
%Distinguish all harmonics locations within the FFT plot
hold on;
plot(Fh(2)*fclk,0,'mo',Fh(3)*fclk,0,'cx',Fh(4)*fclk,0,'r+',Fh(5)*fclk,0,'g*',...
Fh(6)*fclk,0,'bs',Fh(7)*fclk,0,'bd',Fh(8)*fclk,0,'kv',Fh(9)*fclk,0,'y^');
legend('1st','2nd','3rd','4th','5th','6th','7th','8th','9th');
hold off;
%For TTIMD, use the following short routine, normalized to -6.5dB full-scale.
%plot(.*fclk/numpt,Dout_dB(1:numpt/2)-maxdB-6.5);
plot(.*fclk/numpt,Dout_dB(1:numpt/2)-maxdB);
grid on;
title('FFT PLOT');
xlabel('ANALOG INPUT FREQUENCY (MHz)');
ylabel('AMPLITUDE (dB)');
a1=axis; axis();

rcyang 发表于 2007-5-21 16:23

A=(Dout+1)/2;%A=(max(code)-min(code))/2^numbit%A幅度

Dout是sin函数,范围-1~+1,我把输入范围移到0~2,然后除于满幅值2

频谱图没问题,是计算后面的参数出了问题

rcyang 发表于 2007-5-21 16:29

原文的输入数据被存成一个文件,我现在的输入数据直接对sin函数抽样产生

还有,我对信号处理很外行

这是调试的时候出现的问题

f =

   5000000

??? Subscript indices must either be real positive integers or logicals.

Error in ==> snr0521 at 81
har_peak=max(spectP(round(tone*numpt)-spanh:round(tone*numpt)+spanh));
页: [1]
查看完整版本: Defining and Testing Dynamic Parameters in High-Speed ADCs