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

下面把matlab分析的代码记录下来:

  1. %The following program code plots the FFT spectrum of a desired test tone. Test tone based on coherent sampling criteria, and
  2. %computes SNR, SINAD, THD and SFDR.
  3. %This program is believed to be accurate and reliable. This program may get altered without prior notification.;
  4.  
  5. %fid=fopen('F:\pelican_ADC_test\vjtag_prj\data_analysis\single_tone.txt','r');
  6. %numpt=input('Number of Points in FFT? ');
  7. %fclk=input('Sampling Frequency (MHz)? ');
  8. %numbit=input('ADC Resolution (bits)? ');
  9. close all;
  10. clear all;
  11.  
  12. numpt=;
  13. fclk=/;
  14. % fclk=//;
  15. numbit=;
  16.  
  17. % a=textread('dds_data_out.txt','%s')';%以字符形式打开文件
  18. % a=dlmread('sample_data.txt','%s')';%以字符形式打开文件
  19. a=dlmread('sample_data.txt','%s')';%以字符形式打开文件
  20. v1=a'; %16进制转化为10进制数,存储进v1矩阵
  21. % for i = :numpt
  22. % v1(i) = bitxor(v1(i),);
  23. % end
  24.  
  25. %v1 is a column vector(:numpt), and count is its length
  26. %v1=dlmread('F:\pelican_ADC_test\vjtag_prj\data_analysis\single_tone.txt','');
  27. %fclose(fid);
  28. %change v1 into a row vector
  29. code=v1';
  30.  
  31. %Warning: ADC output may be clipping - reduce input amplitude
  32. if (max(code)==2^numbit-1) | (min(code)==0)
  33. disp('WARNING: ADC OUTPUT MAYBE CLIPPING - CHECK INPUT AMPLITUDE!');
  34. end
  35.  
  36. figure;
  37. plot(code);
  38. title('TIME DOMAIN')
  39. xlabel('SAMPLES');
  40. ylabel('DIGITAL OUTPUT CODE');
  41. Dout=code-(2^numbit-1)/2; %Re-center the digitized sinusoidal input
  42. Voltage=Dout./((2^numbit-1)/2)*(0.5);
  43. figure;
  44. plot([1:numpt],Voltage);
  45.  
  46. Doutw=(Dout').*blackmanharris(numpt); %add Minimum -term Blackman-Harris window
  47. Dout_spect=fft(Doutw);
  48. Dout_dB=*log10(abs(Dout_spect));
  49.  
  50. figure;
  51. maxdB=max(Dout_dB(:numpt/)); %numpt points FFT result in numpt/ points spectrum
  52.  
  53. %计算距离满量程的幅度差
  54. max_voltage=max(Voltage);
  55. delta_amplitude=*log10(max_voltage/0.5); %full scale voltage amplitude is .5v
  56.  
  57. plot([:numpt/-].*fclk/numpt,Dout_dB(:numpt/)-maxdB+delta_amplitude);
  58. grid on;
  59. title('SINGLE TONE FFT PLOT');
  60. xlabel('ANALOG INPUT FREQUENCY (MHz)');
  61. ylabel('AMPLITUDE (dBfs)');
  62. a1=axis; axis([a1() a1() - a1()]);
  63. fin=find(Dout_dB(:numpt/)==maxdB); %Find the signal bin (DC represents bin=)
  64. DC_span=; %default DC leakage bins are bins
  65. signal_span = ; %signal leakage bins are ± bins for minumun -term black-harris window
  66. spanh=; %%default harmonic leakage bins are ± bins
  67. spectP=(abs(Dout_spect)).*(abs(Dout_spect));
  68. %Determine power level
  69. Pdc=sum(spectP(:DC_span)); %Determine DC offset power level
  70. Ps=sum(spectP(fin-signal_span:fin+signal_span)); %Determine signal power level
  71. Fh=[];
  72. %Vector storing frequency and power components of signal and harmonics
  73. Ph=[]; %HD1=signal, HD2=2nd harmonic, HD3=3rd harmonic, etc.
  74.  
  75. %Find the harmonic frequencies/power within the FFT plot
  76. for har_num=:
  77. tone=rem((har_num*(fin- )+)/numpt,); %Note: tones > fSAMPLE are aliased back
  78. if tone>0.5
  79. tone=-tone;
  80. end
  81. Fh=[Fh tone];
  82.  
  83. %For this method to work properly, make sure that the folded back high order harmonics do not overlap with DC and signal
  84. %components or lower order harmonics.
  85. har_peak=max(spectP(round(tone*numpt)-spanh:round(tone*numpt)+spanh));
  86. har_bin=find(spectP(round(tone*numpt)-spanh:round(tone*numpt)+spanh)==har_peak);
  87. 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
  88. Ph=[Ph sum(spectP(har_bin-:har_bin+))];
  89. end
  90.  
  91. Pd=sum(Ph(:)); %Total distortion power level
  92. Pn=sum(spectP(:numpt/))-Pdc-Ps-Pd; %Extract noise power level
  93. format;
  94. A=(max(code)-min(code))/(^numbit) %Analog input amplitude in mV
  95. AdB=*log10(A) %Analog input amplitude in dB
  96. SNR=*log10(Ps/Pn) %SNR in dB
  97. SINAD=*log10(Ps/(Pn+Pd)) %SINAD in dB
  98. disp('THD - HD2 through HD9');
  99. THD=*log10(Pd/Ph()) %THD in dB
  100. SFDR=*log10(Ph()/max(Ph(:))) %SFDR in dB
  101. disp('SIGNAL AND HARMONIC POWER (dB)');
  102. HD=*log10(Ph(:)/Ph())
  103.  
  104. hold on;
  105. 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^');
  106. legend('SIGNAL','HD2','HD3','HD4','HD5','HD6','HD7','HD8','HD9');
  107. hold off;

输出结果

  1. A =
  2.  
  3. 0.5432
  4.  
  5. AdB =
  6.  
  7. -5.3006
  8.  
  9. SNR =
  10.  
  11. 54.0005
  12.  
  13. SINAD =
  14.  
  15. 53.4240
  16.  
  17. THD - HD2 through HD9
  18.  
  19. THD =
  20.  
  21. -62.4784
  22.  
  23. SFDR =
  24.  
  25. 63.0618
  26.  
  27. SIGNAL AND HARMONIC POWER (dB)
  28.  
  29. HD =
  30.  
  31. -63.0618 -78.1190 -79.6691 -82.4058 -86.1153 -90.7795 -91.1868 -89.8460 -74.6853

会标记出谐波的位置。

ADC测试matlab代码的更多相关文章

  1. 如何加速MATLAB代码运行

    学习笔记 V1.0 2015/4/17 如何加速MATLAB代码运行 概述 本文源于LDPCC的MATLAB代码,即<CCSDS标准的LDPC编译码仿真>.由于代码的问题,在信息位长度很长 ...

  2. SVM实例及Matlab代码

    ******************************************************** ***数据集下载地址 :http://pan.baidu.com/s/1geb8CQf ...

  3. 数据分析处理之PCA OLSR PCR PLSR(NIPALS)及其Matlab代码实现

    传统的OLS(普通最小二乘)方法无法解决样本数据的共线性(multicollinearity)问题,如果你的数据样本中每个特征变量具有共线性,那么使用基于PCA的PCR和PLSR方法对数据样本进行回归 ...

  4. 测试C++代码与WebBrowser HTML的互动

    testWebBrowserDlg.h // testWebBrowserDlg.h : 头文件 // #pragma once #include "explorer1.h" #i ...

  5. 多分类问题中,实现不同分类区域颜色填充的MATLAB代码(demo:Random Forest)

    之前建立了一个SVM-based Ordinal regression模型,一种特殊的多分类模型,就想通过可视化的方式展示模型分类的效果,对各个分类区域用不同颜色表示.可是,也看了很多代码,但基本都是 ...

  6. 卷积相关公式的matlab代码

    取半径=3 用matlab代码实现上式公式: length=3;for Ki = 1:length for Kj = 1:length for Kk = 1:length Ksigma(Ki,Kj,K ...

  7. 使用JUnit测试java代码

    Junit 单元测试实验报告  一.实验环境 MyEclipse2014.Junit4.10 二.实验目的 学会单元测试,在MyEclipse中进行Junit测试 三.实验步骤 1.写出要测试的类 代 ...

  8. JAVA调用matlab代码

    做实验一直用的matlab代码,需要嵌入到java项目中,matlab代码拼拼凑凑不是很了解,投机取巧采用java调用matlab的方式解决. 1.    matlab版本:matlabR2014a ...

  9. 前端测试框架Jest系列教程 -- Asynchronous(测试异步代码)

    写在前面: 在JavaScript代码中,异步运行是很常见的.当你有异步运行的代码时,Jest需要知道它测试的代码何时完成,然后才能继续进行另一个测试.Jest提供了几种方法来处理这个问题. 测试异步 ...

随机推荐

  1. 浏览器功能记住账号和密码解决方法(HTML解决方式)

    1.在input标签里应用html5的新特性autocomplete="off"  注:对chrome不管用.其他浏览器没试. 2.如果是一个输入框那就在当前input标签后面(一 ...

  2. 毛毛虫学习日记_SQL

    五毛叶的SQL学习: 1.SELECT:(A 表名,a 字段) SELECT A.b, C.c , D.d(a,b,c,d,e...各种自己需要的字段) FROM  A(中心表名) LEFT /INN ...

  3. mysql 完整性约束

    mysql 完整性约束 数据的完整性概述根据完整性实施的方法将完整性约束分为四类:1.实体完整性 实体完整性的实现:通过在表中设置主键约束.唯一约束或标识列来实现 主键约束:应用于表列的一个约束 用法 ...

  4. PHP实例开发(3)PHP中MVC学习之ThinkPHP

    PHP中MVC学习之ThinkPHP 1.什么是MVC MVC本来是存在于Desktop程序中的,M是指数据模型,V是指用户界面,C则是控制器.使用MVC的目的是将M和V的实现代码分离 MVC是一个设 ...

  5. java常用IO流数据流小结

      类名 常用方法 说明 输入流 InputStream int read(); 只能读字节流,虽然返回值是int,但只有低8位起作用. DataInputStream Type readType() ...

  6. Windows环境下npm install常见错误

    Windows环境下npm install安装包依赖时,常出现一些错误,下面为个人解决办法: 错误一 缺少python环境: G:\nodejs\moviesite\node_modules\bcry ...

  7. Ubuntu学习——第一篇

    一. Ubuntu简介 Ubuntu(乌班图)是一个基于Debian的以桌面应用为主的Linux操作系统,据说其名称来自非洲南部祖鲁语或科萨语的“ubuntu”一词,意思是“人性”.“我的存在是因为大 ...

  8. How to create/restore a slave using GTID replication in MySQL 5.6

    MySQL 5.6 is GA! Now we have new things to play with and in my personal opinion the most interesting ...

  9. pt-table-checksum 检查主从数据一致性

    http://www.cnblogs.com/xiaoyanger/p/5584554.html http://www.cnblogs.com/gomysql/p/3662264.html https ...

  10. 实现Cookie跨域共享

    实现原理:cookie是不能跨域访问的,但是在二级域名是可以共享cookie的 概念说明:站点1=a.abc.com   站点2=b.abc.com 实现步骤:1. 配置两个站点的webconfig ...