在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 31193|回复: 60

[求助] matlab流水线ADC仿真FFT频谱测试【求高手搭救】

[复制链接]
发表于 2012-5-20 16:52:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
小弟用matlab仿真1.5比特的十位ADC,采样率1e9

做FFT频谱测试时卡住了,求各位高手搭救


我用的FFT程序如下:
%data1=data(:,2);
%Data_in=load('ADC16.txt');
%>> plot(data1, 'DisplayName'; 'data1'; 'YDataSource'; 'data1'); figure(gcf)
%>> Data_in=data1;
fs=100e7;
DOUT_sum_uni=data;

len=length(DOUT_sum_uni);
N=len;
figure;
plot([1:N],DOUT_sum_uni);
title('TIME DOMAIN')
xlabel('SAMPLES');
ylabel('DIGITAL OUTPUT CODE');
zoom xon;

%performing FFT
DOUT_sum_uni=DOUT_sum_uni-mean(DOUT_sum_uni);
x=hann(N);
data_win=x.*DOUT_sum_uni;
x1=norm(x,1);                                 %?????ó??
Dout_spect=fft(data_win,N)/(x1);  
%recalculate to dB
Dout_dB=20*log10(abs(Dout_spect));
%plot([1:N/2],Dout_dB(1:N/2));
%display the results in the frequency domain with FFT plot
figure;
maxdB=max(Dout_dB(2:N/2));

%%for TTIMD,use the following short routine,normalized to -6.5dB
%full scale.
%plot([0:numpt/2-1].*fclk/numpt,Dout_dB(1:numpt/2)-maxdB-6.5);
plot([0:N/2-1].*(fs/N),Dout_dB(1:N/2)-maxdB);
%plot([0:numpt/2-1].*(fclk/numpt),Dout_dB(1:numpt/2));
grid on;
title('FFT PLOT');
xlabel('Analog INPUT FREQUENCY(MHz)');
ylabel('AMPLITUDE(dB)');
%a1=axis;axis([a1(1) a1(2)-120 a1(4)]);

%-----------------------------------------------%
%calculate SNR,SINAD,ENOB,THD and SFDR values
%-----------------------------------------------%
%find the signal bin number, DC=bin 1
fin=find(Dout_dB(1:N/2)==maxdB);

%Span of the input freq on each side
%span=5;
%span=max(round(N/400),5);
span=max(round(N/200),5);
%approximate search span for harmonics on each side
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(span-fin:span+fin));
Ps=sum(spectP(fin-span:fin+span));

%vector/matric to store both freq and power of signals and harmonics
Fh=[];
%the 1st element in the vector/matrix represents the signal,
%the next element reps the 2nd harmonic,etc..
Ph=[];
%find harmonic freq and power components in the FFT spectrum
for har_num=1:10
%input tones greater than fSAMPLE are aliased back into the spectrum
tone=rem((har_num*(fin-1)+1)/N,1);
if tone>0.5
%input tones greater than 0.5*fSAMPLE(after aliasing) are reflected
tone=1-tone;
end
Fh=[Fh tone];
%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*N)-spanh:round(tone*N)+spanh));
har_bin=find(spectP(round(tone*N)-spanh:round(tone*N)+spanh)==har_peak);
har_bin=har_bin+round(tone*N)-spanh-1;
Ph=[Ph sum(spectP(har_bin-1:har_bin+1))];
end

%determine the total distortion power
Pd=sum(Ph(2:5));
%determine the noise power
Pn=sum(spectP(1:N/2))-Pdc-Ps-Pd;

%inband_bin=1:N/2;
%fin_bin=fin-span:fin+span;
%harnoi_bin=setdiff(inband_bin,fin_bin);
%Phn=sum(spectP(harnoi_bin));
%SINAD2=10*log10(Ps/(Phn));
%ENOB2=(SINAD2-1.76)/6.02;
%fprintf('SINAD2=%gdB \n',SINAD2);
%fprintf('ENOB2=%g \n',ENOB2);
%disp('Calculation above is anther way to get SINAD and ENOB');

format;
A=(max(DOUT_sum_uni)-min(DOUT_sum_uni));
AdB=20*log10(A);

%SINAD=10*log10(Ps/(Pn+Pd));
%SNR=10*log10(Ps/Pn);
SINAD=10*log10(Ps/(Pn+Pd));
SNR=10*log10(Ps/(Pn));
disp('THD is calculated from 2nd through 5th order harmonics');
THD=10*log10(Pd/Ph(1));
SFDR=10*log10(Ph(1)/max(Ph(2:10)));
disp('Signal & Harmonic power components:');
HD=10*log10(Ph(1:10)/Ph(1));
ENOB =(SINAD-1.76)/6.0206;
%distinguish all harmonics locations within the FFT plot
hold on;
plot(Fh(2)*fs,0,'mo',Fh(3)*fs,0,'cx',Fh(4)*fs,0,'r+',Fh(5)*fs,0,'g*',Fh(6)*fs,0,'bs',Fh(7)*fs,0,'bd',Fh(8)*fs,0,'kv',Fh(9)*fs,0,'y^');
legend('1st','2nd','3rd','4th','5th','6th','7th','8th','9th');

fprintf('SINAD=%gdB \n',SINAD);
fprintf('SNR=%gdB \n',SNR);
fprintf('THD=%gdB \n',THD);
fprintf('SFDR=%gdB \n',SFDR);
fprintf('ENOB=%g \n',ENOB);





报错信息为:
??? Subscript indices must either be real positive integers or logicals.
Error in ==> fft at 59
Ps=sum(spectP(fin-span:fin+span));

能出图,但数据计算不了。。。求教!求教!
发表于 2012-5-20 17:17:49 | 显示全部楼层
本帖最后由 半支烟 于 2012-5-20 17:21 编辑

你取了多少个点啊?是不是64个?这是因为fin-span小于等于0了。你点取多点试试。至少得256个吧。这个程序正确运行是有条件的。
 楼主| 发表于 2012-5-20 22:13:17 | 显示全部楼层
回复 2# 半支烟


    谢谢您的回答,
不知您说的是不是  data=simout(500:8691)     这个数值应该够了吧...试了data=simout(500:18691) 结果还是一样==
发表于 2012-5-20 23:14:22 | 显示全部楼层
我以前是认真看过这段代码的,参考美信的吧,他那个代码是没有问题的,你取点取好了是可以正确运行的。
发表于 2012-5-20 23:19:27 | 显示全部楼层
本帖最后由 半支烟 于 2012-5-20 23:20 编辑

对了,你有没有减掉DC分量呢?你在命令行输入fin看看等于几
发表于 2012-5-21 12:25:08 | 显示全部楼层
回复 1# xiamixiami

这个程序不是用来给你ADC仿真做频谱分析的
是实际测试的raw data 做分析用的
发表于 2012-5-22 07:39:53 | 显示全部楼层
回复 6# fuyibin


    这两种有啥区别呢?我平时没有想到测试与仿真的程序还有不同,都用了一种。
而且,我试了试这段程序,用了一千多个点及三千多个点,都能运行完程序,没出现那个错误。
发表于 2012-5-22 08:03:16 | 显示全部楼层
回复 7# fayfay

这个程序定义span / bin等参数 ,是针对实际测试中信号频率不集中等
实际测试时候我们通常取点非常多,比如65536,至少也要8192
那么信号频率不可能再一个bin上,可能会分散在信号频率左右个几个bin上,这些都要算成信号能量
谐波也是一样的道理
而你仿真不会这么长,去做8192或者更多点的dft,而且仿真加的是理想信号,非相干采样
应该就是取信号频率这一个频点的能量来计算snr/sfdr/thd
试试这个程序256point dft可以做么?一直都是cadence里直接做analysis的,matlab没试过,不知道
 楼主| 发表于 2012-5-22 10:26:16 | 显示全部楼层
回复 5# 半支烟


    再次感谢,谢谢
我输fin也报错。。。可能本身的结构有些问题,我再试试,不知您那有美信的代码吗?
 楼主| 发表于 2012-5-22 10:34:34 | 显示全部楼层
回复 8# fuyibin


    学习了,谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-12 22:56 , Processed in 0.102937 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表