首页 技术 正文
技术 2022年11月7日
0 收藏 775 点赞 697 浏览 3781 个字

前面有做过ADC性能测试,测试方式是先使用ADC采集一个单频信号,然后利用matlab进行性能分析。

下面把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=;
fclk=/;
% fclk=//;
numbit=; % a=textread('dds_data_out.txt','%s')';%以字符形式打开文件
% a=dlmread('sample_data.txt','%s')';%以字符形式打开文件
a=dlmread('sample_data.txt','%s')';%以字符形式打开文件
v1=a'; %16进制转化为10进制数,存储进v1矩阵
% for i = :numpt
% v1(i) = bitxor(v1(i),);
% end %v1 is a column vector(: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 -term Blackman-Harris window
Dout_spect=fft(Doutw);
Dout_dB=*log10(abs(Dout_spect)); figure;
maxdB=max(Dout_dB(:numpt/)); %numpt points FFT result in numpt/ points spectrum %计算距离满量程的幅度差
max_voltage=max(Voltage);
delta_amplitude=*log10(max_voltage/0.5); %full scale voltage amplitude is .5v plot([:numpt/-].*fclk/numpt,Dout_dB(:numpt/)-maxdB+delta_amplitude);
grid on;
title('SINGLE TONE FFT PLOT');
xlabel('ANALOG INPUT FREQUENCY (MHz)');
ylabel('AMPLITUDE (dBfs)');
a1=axis; axis([a1() a1() - a1()]);
fin=find(Dout_dB(:numpt/)==maxdB); %Find the signal bin (DC represents bin=)
DC_span=; %default DC leakage bins are bins
signal_span = ; %signal leakage bins are ± bins for minumun -term black-harris window
spanh=; %%default harmonic leakage bins are ± bins
spectP=(abs(Dout_spect)).*(abs(Dout_spect));
%Determine power level
Pdc=sum(spectP(:DC_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=:
tone=rem((har_num*(fin- )+)/numpt,); %Note: tones > fSAMPLE are aliased back
if tone>0.5
tone=-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- ; %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-:har_bin+))];
end Pd=sum(Ph(:)); %Total distortion power level
Pn=sum(spectP(:numpt/))-Pdc-Ps-Pd; %Extract noise power level
format;
A=(max(code)-min(code))/(^numbit) %Analog input amplitude in mV
AdB=*log10(A) %Analog input amplitude in dB
SNR=*log10(Ps/Pn) %SNR in dB
SINAD=*log10(Ps/(Pn+Pd)) %SINAD in dB
disp('THD - HD2 through HD9');
THD=*log10(Pd/Ph()) %THD in dB
SFDR=*log10(Ph()/max(Ph(:))) %SFDR in dB
disp('SIGNAL AND HARMONIC POWER (dB)');
HD=*log10(Ph(:)/Ph()) hold on;
plot(Fh()*fclk,-,'bo',Fh()*fclk,-,'bx',Fh()*fclk,-,'b+',Fh()*fclk,-,'b*',Fh()*fclk,-,'bs',Fh()*fclk,-,'bd',Fh()*fclk,-,'bv',Fh()*fclk,-,'b^');
legend('SIGNAL','HD2','HD3','HD4','HD5','HD6','HD7','HD8','HD9');
hold off;

输出结果

 A =     0.5432 AdB =    -5.3006 SNR =    54.0005 SINAD =    53.4240 THD - HD2 through HD9 THD =   -62.4784 SFDR =    63.0618 SIGNAL AND HARMONIC POWER (dB) HD =            -63.0618  -78.1190  -79.6691  -82.4058  -86.1153  -90.7795  -91.1868  -89.8460  -74.6853

ADC测试matlab代码

会标记出谐波的位置。

上一篇: Linux shell相关
下一篇: 更新程序基于IIS
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,497
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298