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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 2385|回复: 5

[求助] adc matlab测试

[复制链接]
发表于 2020-4-19 10:48:56 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 kongc 于 2020-4-19 10:51 编辑

在网上找的adc测试代码,加了自己的数据后运行会提示“下标索引必须为正整数类型或逻辑类型。”对代码不熟悉而且matlab也不报出错的位置,所以我一段段地删除代码发现和上面两处有关系,请问这两处代表什么意思?我该怎么改?
源代码如下:
%The following program code plots the FFT spectrum of a desired test tone. Test tone based on coherent sampling criteria, and
%computes SNR, SINAD, THD and SFDR.
%This program is believed to be accurate and reliable. This program may get altered without prior notification.;

%fid=fopen('F:\pelican_ADC_test\vjtag_prj\data_analysis\single_tone.txt','r');
%numpt=input('Number of  Points in FFT? ');
%fclk=input('Sampling Frequency (MHz)? ');
%numbit=input('ADC Resolution (bits)? ');
close all;
clear all;

numpt=4096;
fclk=100000000;
% fclk=455/16/14;
numbit=12;

% a=textread('dds_data_out.txt','%s')';%以字符形式打开文件
% a=dlmread('sample_data.txt','%s')';%以字符形式打开文件
a=dlmread('D:\GUR_PROJECT\SARADC_14bit\matlab\adc_data_0419.csv','%s')';%以字符形式打开文件
b=a*(2^12);v1=b'; %16进制转化为10进制数,存储进v1矩阵
% for i = 1:numpt
%     v1(i) = bitxor(v1(i),15872);
% end

%v1 is a column vector(1:numpt), and count is its length
%v1=dlmread('F:\pelican_ADC_test\vjtag_prj\data_analysis\single_tone.txt','');
%fclose(fid);
%change v1 into a row vector
code=v1';

%Warning: ADC output may be clipping - reduce input amplitude
if (max(code)==2^numbit-1) | (min(code)==0)
  disp('WARNING: ADC OUTPUT MAYBE CLIPPING - CHECK INPUT AMPLITUDE!');
end

figure;
plot(code);
title('TIME DOMAIN')
xlabel('SAMPLES');
ylabel('DIGITAL OUTPUT CODE');
Dout=code-(2^numbit-1)/2; %Re-center the digitized sinusoidal input
Voltage=Dout./((2^numbit-1)/2)*(0.5);
figure;
plot([1:numpt],Voltage);

Doutw=(Dout').*blackmanharris(numpt);               %add Minimum 4-term Blackman-Harris window
Dout_spect=fft(Doutw);
Dout_dB=20*log10(abs(Dout_spect));

figure;
maxdB=max(Dout_dB(1:numpt/2));     %numpt points FFT result in numpt/2 points spectrum

%计算距离满量程的幅度差
max_voltage=max(Voltage);
delta_amplitude=20*log10(max_voltage/0.5);      %full scale voltage amplitude is 0.5v

plot([0:numpt/2-1].*fclk/numpt,Dout_dB(1:numpt/2)-maxdB+delta_amplitude);
grid on;
title('SINGLE TONE FFT PLOT');
xlabel('ANALOG INPUT FREQUENCY (MHz)');
ylabel('AMPLITUDE (dBfs)');
a1=axis; axis([a1(1) a1(2) -140 a1(4)]);
fin=find(Dout_dB(1:numpt/2)==maxdB); %Find the signal bin (DC represents bin=1)
DC_span=0;              %default DC leakage bins are 6 bins   
signal_span = 0;       %signal leakage bins are ±10 bins for minumun 4-term black-harris window
spanh=0;                %%default harmonic leakage bins are ±3 bins
spectP=(abs(Dout_spect)).*(abs(Dout_spect));
%Determine power level
Pdc=sum(spectP(1C_span)); %Determine DC offset power level
Ps=sum(spectP(fin-signal_span:fin+signal_span)); %Determine signal power level
Fh=[];
%Vector storing frequency and power components of signal and harmonics
Ph=[]; %HD1=signal, HD2=2nd harmonic, HD3=3rd harmonic, etc.

%Find the harmonic frequencies/power within the FFT plot
for har_num=1:10
  tone=rem((har_num*(fin- 1)+1)/numpt,1);   %Note: tones > fSAMPLE are aliased back
  if tone>0.5
     tone=1-tone;
  end
  Fh=[Fh tone];

%For this method to work properly, make sure that the folded back high order harmonics do not overlap with DC and signal
%components 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;     %make sure that the folded back high order harmonics do not overlap with DC and signal components or lower order harmonics
  Ph=[Ph sum(spectP(har_bin-3:har_bin+3))];
end

Pd=sum(Ph(2:10)); %Total distortion power level
Pn=sum(spectP(1:numpt/2))-Pdc-Ps-Pd; %Extract noise power level
format;
A=(max(code)-min(code))/(2^numbit) %Analog input amplitude in mV
AdB=20*log10(A) %Analog input amplitude in dB
SNR=10*log10(Ps/Pn) %SNR in dB
SINAD=10*log10(Ps/(Pn+Pd))  %SINAD in dB
disp('THD - HD2 through HD9');
THD=10*log10(Pd/Ph(1)) %THD in dB
SNDR = 10*log10(Ps/(Pn+Pd)) %-fin_dB
ENOB = (SNDR-1.76)/6.02
SFDR=10*log10(Ph(1)/max(Ph(2:10))) %SFDR in dB
disp('SIGNAL AND HARMONIC POWER (dB)');
HD=10*log10(Ph(1:10)/Ph(1))

hold on;
plot(Fh(2)*fclk,-70,'bo',Fh(3)*fclk,-70,'bx',Fh(4)*fclk,-70,'b+',Fh(5)*fclk,-70,'b*',Fh(6)*fclk,-70,'bs',Fh(7)*fclk,-70,'bd',Fh(8)*fclk,-70,'bv',Fh(9)*fclk,-70,'b^');
legend('SIGNAL','HD2','HD3','HD4','HD5','HD6','HD7','HD8','HD9');
hold off;

9965de81f740d8f266614ddae9d4fe5.png
e145fd026e54a476238abbbc92e51a8.png
 楼主| 发表于 2020-4-19 10:50:09 | 显示全部楼层
源代码如下:
%The following program code plots the FFT spectrum of a desired test tone. Test tone based on coherent sampling criteria, and
%computes SNR, SINAD, THD and SFDR.
%This program is believed to be accurate and reliable. This program may get altered without prior notification.;

%fid=fopen('F:\pelican_ADC_test\vjtag_prj\data_analysis\single_tone.txt','r');
%numpt=input('Number of  Points in FFT? ');
%fclk=input('Sampling Frequency (MHz)? ');
%numbit=input('ADC Resolution (bits)? ');
close all;
clear all;

numpt=4096;
fclk=100000000;
% fclk=455/16/14;
numbit=12;

% a=textread('dds_data_out.txt','%s')';%以字符形式打开文件
% a=dlmread('sample_data.txt','%s')';%以字符形式打开文件
a=dlmread('D:\GUR_PROJECT\SARADC_14bit\matlab\adc_data_0419.csv','%s')';%以字符形式打开文件
b=a*(2^12);v1=b'; %16进制转化为10进制数,存储进v1矩阵
% for i = 1:numpt
%     v1(i) = bitxor(v1(i),15872);
% end

%v1 is a column vector(1:numpt), and count is its length
%v1=dlmread('F:\pelican_ADC_test\vjtag_prj\data_analysis\single_tone.txt','');
%fclose(fid);
%change v1 into a row vector
code=v1';

%Warning: ADC output may be clipping - reduce input amplitude
if (max(code)==2^numbit-1) | (min(code)==0)
  disp('WARNING: ADC OUTPUT MAYBE CLIPPING - CHECK INPUT AMPLITUDE!');
end

figure;
plot(code);
title('TIME DOMAIN')
xlabel('SAMPLES');
ylabel('DIGITAL OUTPUT CODE');
Dout=code-(2^numbit-1)/2; %Re-center the digitized sinusoidal input
Voltage=Dout./((2^numbit-1)/2)*(0.5);
figure;
plot([1:numpt],Voltage);

Doutw=(Dout').*blackmanharris(numpt);               %add Minimum 4-term Blackman-Harris window
Dout_spect=fft(Doutw);
Dout_dB=20*log10(abs(Dout_spect));

figure;
maxdB=max(Dout_dB(1:numpt/2));     %numpt points FFT result in numpt/2 points spectrum

%计算距离满量程的幅度差
max_voltage=max(Voltage);
delta_amplitude=20*log10(max_voltage/0.5);      %full scale voltage amplitude is 0.5v

plot([0:numpt/2-1].*fclk/numpt,Dout_dB(1:numpt/2)-maxdB+delta_amplitude);
grid on;
title('SINGLE TONE FFT PLOT');
xlabel('ANALOG INPUT FREQUENCY (MHz)');
ylabel('AMPLITUDE (dBfs)');
a1=axis; axis([a1(1) a1(2) -140 a1(4)]);
fin=find(Dout_dB(1:numpt/2)==maxdB); %Find the signal bin (DC represents bin=1)
DC_span=0;              %default DC leakage bins are 6 bins   
signal_span = 0;       %signal leakage bins are ±10 bins for minumun 4-term black-harris window
spanh=0;                %%default harmonic leakage bins are ±3 bins
spectP=(abs(Dout_spect)).*(abs(Dout_spect));
%Determine power level
Pdc=sum(spectP(1C_span)); %Determine DC offset power level
Ps=sum(spectP(fin-signal_span:fin+signal_span)); %Determine signal power level
Fh=[];
%Vector storing frequency and power components of signal and harmonics
Ph=[]; %HD1=signal, HD2=2nd harmonic, HD3=3rd harmonic, etc.

%Find the harmonic frequencies/power within the FFT plot
for har_num=1:10
  tone=rem((har_num*(fin- 1)+1)/numpt,1);   %Note: tones > fSAMPLE are aliased back
  if tone>0.5
     tone=1-tone;
  end
  Fh=[Fh tone];

%For this method to work properly, make sure that the folded back high order harmonics do not overlap with DC and signal
%components 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;     %make sure that the folded back high order harmonics do not overlap with DC and signal components or lower order harmonics
  Ph=[Ph sum(spectP(har_bin-3:har_bin+3))];
end

Pd=sum(Ph(2:10)); %Total distortion power level
Pn=sum(spectP(1:numpt/2))-Pdc-Ps-Pd; %Extract noise power level
format;
A=(max(code)-min(code))/(2^numbit) %Analog input amplitude in mV
AdB=20*log10(A) %Analog input amplitude in dB
SNR=10*log10(Ps/Pn) %SNR in dB
SINAD=10*log10(Ps/(Pn+Pd))  %SINAD in dB
disp('THD - HD2 through HD9');
THD=10*log10(Pd/Ph(1)) %THD in dB
SNDR = 10*log10(Ps/(Pn+Pd)) %-fin_dB
ENOB = (SNDR-1.76)/6.02
SFDR=10*log10(Ph(1)/max(Ph(2:10))) %SFDR in dB
disp('SIGNAL AND HARMONIC POWER (dB)');
HD=10*log10(Ph(1:10)/Ph(1))

hold on;
plot(Fh(2)*fclk,-70,'bo',Fh(3)*fclk,-70,'bx',Fh(4)*fclk,-70,'b+',Fh(5)*fclk,-70,'b*',Fh(6)*fclk,-70,'bs',Fh(7)*fclk,-70,'bd',Fh(8)*fclk,-70,'bv',Fh(9)*fclk,-70,'b^');
legend('SIGNAL','HD2','HD3','HD4','HD5','HD6','HD7','HD8','HD9');
hold off;

发表于 2020-4-19 14:26:45 | 显示全部楼层
贴代码时可选:
2020-04-19_142426.png
这样贴入的代码不会被误解析为表情符号。

 楼主| 发表于 2020-4-19 20:15:24 | 显示全部楼层


z1314007 发表于 2020-4-19 14:26
贴代码时可选:

这样贴入的代码不会被误解析为表情符号。


好的,谢谢
发表于 2020-4-20 11:15:35 | 显示全部楼层
你应该贴出错的warning/error信息
盲猜是因为频谱peak在接近DC或fs/2的地方,然后积分能量的时候,下标越界了
发表于 2021-8-26 09:10:22 | 显示全部楼层
thank  u
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

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

GMT+8, 2025-2-26 08:26 , Processed in 0.021000 second(s), 8 queries , Gzip On, Redis On.

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