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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2096|回复: 0

[求助] 关于采样开关仿真结果分析

[复制链接]
发表于 2022-3-18 22:30:53 | 显示全部楼层 |阅读模式

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

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

x
求大神指导,第一次接触ADC,8bit 500MHz SAR ADC,目前在做采样开关,第一次仿FFT,很多都不懂,FFT点数是128,下面是仿真结果:主要疑问有:
1、从Cadence提取数据时,具体应该如何设置参数,仿真时间有没有要求?
20220318222601.png
2、FFT的仿真结果为什么只能看见一个点,SFDR等参数是否满足要求?
%***********************************************************************%
% 采样时钟500MHz,输入信号频率86.25MHz,FFT点数64,ADC分辨率10bit,仿真时间400ns。
% 从cadence输出时间隔是4.16666667ns,共计97个点,从第20个点开始取64点做FFT。
% cadence输出的是归一化的结果范围是0-1.6V,需除以1.6再乘以1024,转换为数字码。
%***********************************************************************%

clear all;
clc;
%datafile='m1.csv'
% spectP_file='F:\data\m1.csv';

%***********************************************************************%
% 输入采样时钟、样本点数、分辨率等变量
%***********************************************************************%
fs=500e6;        %采样时钟
Data_Num=128;   %样本点数
numbit=8;       %ADC分辨率
data_start=1; %取点起始位置
fclk=fs/1e6;     %x坐标轴数值显示
numpt=Data_Num;
fres=fclk/numpt; %期望的频率分辨率 of FFT[MHz], fres=fclk/2^N


%***********************************************************************%
% 读取数据
%****************D:\data*******************************************************%
d_in=csvread('F:\data\m1.csv',1,1);
d_in=d_in/1*1024;
code=zeros(1,numpt);
code(1:numpt)=d_in(data_start:data_start+numpt-1);


%***********************************************************************%
% Plot output code
%***********************************************************************%
figure;
plot(code);
title(sprintf('ADC Digital Output'));


%***********************************************************************%
% Recenter the digital sine wave, for 2's complement code
%***********************************************************************%
m_ean=mean(code);
for hk=1:length(code)
    code(hk)=code(hk)-m_ean;
end


%***********************************************************************%
% Display a warning, when the input generates a code greater than
% full-scale, for 2's complement code
%***********************************************************************%
max_code=max(code)
min_code=min(code)
if (max(code)>2^(numbit-1)) | (min(code)<(0-2^(numbit-1)))
%if (max(code)==2numbit -1) | (min(code)==0)
    disp('Warning: ADC may be clipping!');
end


%***********************************************************************%
% Normalize input signal relative to full-scale
%***********************************************************************%
fin_dB=20*log10((max_code-min_code)/(2^numbit));


%***********************************************************************%
% 对数据样本加窗函数处理
%***********************************************************************%
Dout=code';
Doutw=Dout;
% Doutw=Dout.*hanning(numpt);
% Doutw=Dout.*hamming(numpt);
%  Doutw=Dout.*blackman(numpt);


%***********************************************************************%
% Performing the Fast Fourier Transform [FFT]
%***********************************************************************%
span=0; %Span of the input frequency on each side; span=max(round(numpt/200),5);
spanh=0; %Approximate search span for harmonics on each side
%spandc=0; %Approximate search span for DC on right side
Dout_spect=fft(Doutw);
Dout_dB=20*log10(abs(Dout_spect)); %Recalculate to dB abs(Dout_spect)
spectP=(abs(Dout_spect)).*(abs(Dout_spect)); %Determine power spectrum
maxdB=max(Dout_dB(1:numpt/2));
fin=find(Dout_dB(1:numpt/2)==maxdB); %Find the signal bin number, DC=bin1


%***********************************************************************%
% Calculate SNR, SNDR, THD and SFDR values.
%***********************************************************************%
% fw=fopen(spectP_file,'w'); %write the power soectrum to file
% fprintf(fw,'%12.9e\n',spectP);
% fclose('all');
%找到直流偏置功率
Pdc=sum(spectP(1:span));
%提取总信号功率
idx1=fin-span;
idx2=fin+span;
if(idx1<=0)
    idx1 = 1;
end
Ps=sum(spectP(idx1:idx2));
%向量/矩阵,储存信号和谐波的频率和功率
Fh=[];
%向量/矩阵的第一个元素代表信号,下一个元素代表二次谐波
Ph=[];
%Vector/matrix to store the sampling points responding to the harmonics
Nh=[];
%Ah represents signal and harmonic amplitude
Ah=[];
for har_num=1:5
    tone=rem((har_num*(fin-1)+1)/numpt,1); %Input tones greater than fSAMPLE are aliased back into the spectrum
    if tone>0.5
        tone=1-tone; %Input tones greater than 0.5*Fsample (after aliasing) are reflected
    end
    Fh=[Fh tone];
    %Check Nh to see the bin of the harmonics
    Nh=[Nh round(tone*numpt)];
    %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=[Ph sum(spectP(har_bin-spanh:har_bin+spanh))];
    Ah=[Ah Dout_dB(har_bin)];
end
%Determine the total distortion power, it should be modified according to the actual condition.
Pd=sum(Ph(2:5));
%Determine the noise power
Pn=sum(spectP(1:numpt/2))-Pdc-Ps-Pd;
%**********************计算动态特性结果**********************%
format; %设置输出格式
SFDR = 10*log10(Ph(1)/max(Ph(2:5))); %-fin_dB
THD = 10*log10(Pd/Ph(1)); %+fin_dB
SNR = 10*log10(Ps/Pn); %-fin_dB
SNDR = 10*log10(Ps/(Pn+Pd)); %-fin_dB
ENOB = (SNDR-1.76)/6.02;
%disp('Note: THD is calculated from 2nd through 10th order harmonics.');
%*********************标示信号和谐波位置*********************%
%hold on;
%plot((Nh(2:10)-1).*fres,Ah(2:10)-maxdB+fin_dB,'rs');
% 标示信号
bins=(Nh(1)-1)*fres;
Ahs=Ah(1)-maxdB+fin_dB;
% 标示2次谐波
bin2=(Nh(2)-1)*fres;
Ah2=Ah(2)-maxdB+fin_dB;
% 标示3次谐波
bin3=(Nh(3)-1)*fres;
Ah3=Ah(3)-maxdB+fin_dB;
% 标示4次谐波
bin4=(Nh(4)-1)*fres;
Ah4=Ah(4)-maxdB+fin_dB;
% 标示5次谐波
bin5=(Nh(5)-1)*fres;
Ah5=Ah(5)-maxdB+fin_dB;
% 在FFT频谱图中追加标示
figure;
plot(bins,Ahs,'rs',bin2,Ah2,'rd',bin3,Ah3,'r^',bin4,Ah4,'r*',bin5,Ah5,'rx');
legend('SINGAL','HD2','HD3','HD4','HD5');
%**********************图表显示**********************%
ylabel('Full-Scale Normalized Magnitude[dB]')
xlabel('Frequency [MHz]')
title(sprintf('ADC FFT Spectrum (%g points)\nFs = %g MSps, Fin = %g MHz (%1.2gdBFS)', Data_Num,fs/1e6,(fin-1)*fres,fin_dB));
grid on;
box on;
ylim([-110 10]);
set(gca,'xgrid', 'off');
set(gca, 'GridLineStyle' ,'-');
set(gca,'yTick',[-110:10:10]);
%****************************************************%
%Display the results in the frequency domain with an FFT plot.
for i=0:1(numpt/2-1)
    hold on;
    line([i*fres,i*fres],[-110,Dout_dB(i+1)-maxdB+fin_dB],'LineWidth',2);
    hold off;
end
%***********************在图中打印结果***********************%
hold on;
s1=sprintf('SFDR = %4.1fdB\n',SFDR);
s2=sprintf('THD = %4.1fdB\n',THD);
s3=sprintf('SNR   = %4.1fdB\n',SNR);
s4=sprintf('SNDR = %4.1fdB\n',SNDR);
s5=sprintf('ENOB = %4.2fbit\n',ENOB);
text(25,-10,s1);
text(25,-20,s2);
text(25,-30,s3);
text(25,-40,s4);
text(25,-50,s5);
hold off;

代码主要是用的别人的,不知道是不是代码哪里还需要修改?
%***********************************************************************%
% 采样时钟500MHz,输入信号频率11.7188MHz,FFT点数128,ADC分辨率8bit,仿真时间456ns。
% cadence输出的是归一化的结果范围是0.5-1.5V,需除以1再乘以1024,转换为数字码。
%***********************************************************************%

clear all;
clc;

%***********************************************************************%
% 输入采样时钟、样本点数、分辨率等变量
%***********************************************************************%
fs=500e6;        %采样时钟
Data_Num=128;   %样本点数
numbit=8;       %ADC分辨率
data_start=1; %取点起始位置
fclk=fs/1e6;     %x坐标轴数值显示
numpt=Data_Num;
fres=fclk/numpt; %期望的频率分辨率 of FFT[MHz], fres=fclk/2^N


%***********************************************************************%
% 读取数据
%****************D:\data*******************************************************%
d_in=csvread('F:\data\m1.csv',1,1);
d_in=d_in/1*1024;
code=zeros(1,numpt);
code(1:numpt)=d_in(data_start:data_start+numpt-1);


%***********************************************************************%
% Plot output code
%***********************************************************************%
figure;
plot(code);
title(sprintf('ADC Digital Output'));


%***********************************************************************%
% Recenter the digital sine wave, for 2's complement code
%***********************************************************************%
m_ean=mean(code);
for hk=1:length(code)
    code(hk)=code(hk)-m_ean;
end


%***********************************************************************%
% Display a warning, when the input generates a code greater than
% full-scale, for 2's complement code
%***********************************************************************%
max_code=max(code)
min_code=min(code)
if (max(code)>2^(numbit-1)) | (min(code)<(0-2^(numbit-1)))
%if (max(code)==2numbit -1) | (min(code)==0)
    disp('Warning: ADC may be clipping!');
end


%***********************************************************************%
% Normalize input signal relative to full-scale
%***********************************************************************%
fin_dB=20*log10((max_code-min_code)/(2^numbit));


%***********************************************************************%
% 对数据样本加窗函数处理
%***********************************************************************%
Dout=code';
Doutw=Dout;
% Doutw=Dout.*hanning(numpt);
% Doutw=Dout.*hamming(numpt);
%  Doutw=Dout.*blackman(numpt);


%***********************************************************************%
% Performing the Fast Fourier Transform [FFT]
%***********************************************************************%
span=0; %Span of the input frequency on each side; span=max(round(numpt/200),5);
spanh=0; %Approximate search span for harmonics on each side
%spandc=0; %Approximate search span for DC on right side
Dout_spect=fft(Doutw);
Dout_dB=20*log10(abs(Dout_spect)); %Recalculate to dB abs(Dout_spect)
spectP=(abs(Dout_spect)).*(abs(Dout_spect)); %Determine power spectrum
maxdB=max(Dout_dB(1:numpt/2));
fin=find(Dout_dB(1:numpt/2)==maxdB); %Find the signal bin number, DC=bin1


%***********************************************************************%
% Calculate SNR, SNDR, THD and SFDR values.
%***********************************************************************%
% fw=fopen(spectP_file,'w'); %write the power soectrum to file
% fprintf(fw,'%12.9e\n',spectP);
% fclose('all');
%找到直流偏置功率
Pdc=sum(spectP(1:span));
%提取总信号功率
idx1=fin-span;
idx2=fin+span;
if(idx1<=0)
    idx1 = 1;
end
Ps=sum(spectP(idx1:idx2));
%向量/矩阵,储存信号和谐波的频率和功率
Fh=[];
%向量/矩阵的第一个元素代表信号,下一个元素代表二次谐波
Ph=[];
%Vector/matrix to store the sampling points responding to the harmonics
Nh=[];
%Ah represents signal and harmonic amplitude
Ah=[];
for har_num=1:5
    tone=rem((har_num*(fin-1)+1)/numpt,1); %Input tones greater than fSAMPLE are aliased back into the spectrum
    if tone>0.5
        tone=1-tone; %Input tones greater than 0.5*Fsample (after aliasing) are reflected
    end
    Fh=[Fh tone];
    %Check Nh to see the bin of the harmonics
    Nh=[Nh round(tone*numpt)];
    %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=[Ph sum(spectP(har_bin-spanh:har_bin+spanh))];
    Ah=[Ah Dout_dB(har_bin)];
end
%Determine the total distortion power, it should be modified according to the actual condition.
Pd=sum(Ph(2:5));
%Determine the noise power
Pn=sum(spectP(1:numpt/2))-Pdc-Ps-Pd;
%**********************计算动态特性结果**********************%
format; %设置输出格式
SFDR = 10*log10(Ph(1)/max(Ph(2:5))); %-fin_dB
THD = 10*log10(Pd/Ph(1)); %+fin_dB
SNR = 10*log10(Ps/Pn); %-fin_dB
SNDR = 10*log10(Ps/(Pn+Pd)); %-fin_dB
ENOB = (SNDR-1.76)/6.02;
%disp('Note: THD is calculated from 2nd through 10th order harmonics.');
%*********************标示信号和谐波位置*********************%
%hold on;
%plot((Nh(2:10)-1).*fres,Ah(2:10)-maxdB+fin_dB,'rs');
% 标示信号
bins=(Nh(1)-1)*fres;
Ahs=Ah(1)-maxdB+fin_dB;
% 标示2次谐波
bin2=(Nh(2)-1)*fres;
Ah2=Ah(2)-maxdB+fin_dB;
% 标示3次谐波
bin3=(Nh(3)-1)*fres;
Ah3=Ah(3)-maxdB+fin_dB;
% 标示4次谐波
bin4=(Nh(4)-1)*fres;
Ah4=Ah(4)-maxdB+fin_dB;
% 标示5次谐波
bin5=(Nh(5)-1)*fres;
Ah5=Ah(5)-maxdB+fin_dB;
% 在FFT频谱图中追加标示
figure;
plot(bins,Ahs,'rs',bin2,Ah2,'rd',bin3,Ah3,'r^',bin4,Ah4,'r*',bin5,Ah5,'rx');
legend('SINGAL','HD2','HD3','HD4','HD5');
%**********************图表显示**********************%
ylabel('Full-Scale Normalized Magnitude[dB]')
xlabel('Frequency [MHz]')
title(sprintf('ADC FFT Spectrum (%g points)\nFs = %g MSps, Fin = %g MHz (%1.2gdBFS)', Data_Num,fs/1e6,(fin-1)*fres,fin_dB));
grid on;
box on;
ylim([-110 10]);
set(gca,'xgrid', 'off');
set(gca, 'GridLineStyle' ,'-');
set(gca,'yTick',[-110:10:10]);
%****************************************************%
%Display the results in the frequency domain with an FFT plot.
for i=0:1(numpt/2-1)
    hold on;
    line([i*fres,i*fres],[-110,Dout_dB(i+1)-maxdB+fin_dB],'LineWidth',2);
    hold off;
end
%***********************在图中打印结果***********************%
hold on;
s1=sprintf('SFDR = %4.1fdB\n',SFDR);
s2=sprintf('THD = %4.1fdB\n',THD);
s3=sprintf('SNR   = %4.1fdB\n',SNR);
s4=sprintf('SNDR = %4.1fdB\n',SNDR);
s5=sprintf('ENOB = %4.2fbit\n',ENOB);
text(25,-10,s1);
text(25,-20,s2);
text(25,-30,s3);
text(25,-40,s4);
text(25,-50,s5);
hold off;







QQ图片20220318221431.png
QQ图片20220318221439.png
VTGN$(Y$1NK2F{0~L`ZLSF0.png
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

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

GMT+8, 2024-11-6 09:39 , Processed in 0.015978 second(s), 8 queries , Gzip On, Redis On.

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