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

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

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 13642|回复: 33

[资料] 自己在做adc的仿真,分享一下仿真adc静态参数和动态参数的matlab代码

[复制链接]
发表于 2020-12-31 10:26:57 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 kongc 于 2020-12-31 10:30 编辑

代码是网上找的资料,然后又改的,有需要的可以参考一下。输入的文件都是numpt行,N列的数字输出数据。
静态参数






  1. %Code density/histofgram test to calculate INL and DNL require a large number of samples.
  2. %Step 1: Apply a close to full-scale sine wave (but not clipping) and find the mid-code for the applied signal.
  3. %Step 2: Apply the same sine wave input, but slightly larger amplitude to clip the ADC slightly.
  4. %Run the following program, enter the number of samples, resolution and mid-code from Step 1and continue.
  5. %Copyright Au/Hofner, Maxim Integrated Products, 120 San Gabriel Drive, Sunnyvale, CA94086
  6. %This program is believed to be accurate and reliable. This program may get altered without prior notification.

  7. %用于计算INL和DNL的%代码密度/直方图测试需要大量样本。
  8. %步骤1:施加接近满量程的正弦波(但不削波),并找到所施加信号的中间码。
  9. %步骤2:施加相同的正弦波输入,但幅度稍大些,以对ADC进行稍稍削波。
  10. %运行以下程序,输入步骤1中的样本数量,分辨率和中间代码,然后继续。版权所有Au / Hofner,Maxim Integrated Products,120 San Gabriel Drive,Sunnyvale,CA94086
  11. %该程序被认为是准确和可靠的。 该程序可能会更改,恕不另行通知。


  12. filename=csvread('adc_data.csv');
  13. adc_data=round(filename);

  14. numpt=32768;
  15. numbit=12;
  16. mid_code=2048;
  17. d11=1;d10=2;d9=3;d8=4;d7=5;d6=6;d5=7;d4=8;d3=9;d2=10;d1=11;d0=12;

  18. for i=1:numpt
  19.     dout(i)=adc_data(i,d11)*2048+adc_data(i,d10)*1024+adc_data(i,d9)*512 ...
  20.     +adc_data(i,d8)*256+adc_data(i,d7)*128+adc_data(i,d6)*64 ...
  21.     +adc_data(i,d5)*32+adc_data(i,d4)*16+adc_data(i,d3)*8 ...
  22.     +adc_data(i,d2)*4+adc_data(i,d1)*2+adc_data(i,d0)*1;%通过转换器出来的结果,恢复原来的波形
  23.     doute(i)=dout(i)-0.5;%将正弦波的共模电平偏置为0
  24.     %doute(i)=dout(i)-mean(dout(i));
  25. end

  26. [a,b]=size(dout);
  27. if(a>b)
  28.     dout=dout(:,1)';
  29. else
  30.     dout=dout(1,:);
  31. end

  32. mid_file=[dout ; dout];
  33. mid_file=double(mid_file);


  34. v1=mid_file';
  35. code=v1(:,2);
  36. code_count=zeros(1,2^numbit);

  37. for i=1:2^numbit
  38.     count=0;%附值
  39.     for j=1:numpt
  40.         if code(j)==i-1
  41.             count=count+1;
  42.         else count=count;
  43.         end
  44.     end
  45.     code_count(i)=count;
  46. end

  47. if code_count(1) == 0 | code_count(2^numbit) == 0 | ...
  48.   (code_count(1) < code_count(2)) | (code_count(2^numbit-1) > code_count(2^numbit))
  49.    disp('ADC not clipping ... Increase sinewave amplitude!');
  50.   % break;
  51. end

  52. A=max(mid_code,2^numbit-1-mid_code)+0.1;
  53. vin=(0:2^numbit-1)-mid_code;        
  54. sin2ramp=1./(pi*sqrt(A^2*ones(size(vin))-vin.*vin));

  55. while sum(code_count(2:2^numbit-1)) < numpt*sum(sin2ramp(2:2^numbit-1))
  56.   A=A+0.1;
  57.   sin2ramp=1./(pi*sqrt(A^2*ones(size(vin))-vin.*vin));
  58. end

  59. disp('You Have Applied a Sine Wave of (dBFS): ');
  60. Amplitude=A/(2^numbit/2)
  61. figure;
  62. plot([0:2^numbit-1],code_count,[0:2^numbit-1],sin2ramp*numpt);
  63. title('CODE HISTOGRAM - SINE WAVE');
  64. xlabel('DIGITAL OUTPUT CODE');
  65. ylabel('COUNTS');
  66. axis([0 2^numbit-1 0 max(code_count)]);
  67. code_countn=code_count(2:2^numbit-1)./(numpt*sin2ramp(2:2^numbit-1));
  68. figure;
  69. plot([1:2^numbit-2],code_countn);
  70. title('CODE HISTOGRAM - NORMALIZED')
  71. xlabel('DIGITAL OUTPUT CODE');
  72. ylabel('NORMALIZED COUNTS');

  73. dnl=code_countn-1;
  74. inl=zeros(size(dnl));
  75. for j=1:size(inl')
  76.    inl(j)=sum(dnl(1:j));
  77. end

  78. %End-Point fit INL
  79. %[p,S]=polyfit([1,2^numbit-2],[inl(1),inl(2^numbit-2)],1);

  80. %Best-straight-line fit INL
  81. [p,S]=polyfit([1:2^numbit-2],inl,1);
  82. inl=inl-p(1)*[1:2^numbit-2]-p(2);

  83. disp('End Points Eliminated for DNL and INL Calculations');
  84. figure;
  85. plot([1:2^numbit-2],dnl);
  86. grid on;
  87. title('DIFFERENTIAL NONLINEARITY vs. DIGITAL OUTPUT CODE');
  88. xlabel('DIGITAL OUTPUT CODE');
  89. ylabel('DNL (LSB)');
  90. figure;
  91. plot([1:2^numbit-2],inl);
  92. grid on;
  93. title('INTEGRAL NONLINEARITY vs. DIGITAL OUTPUT CODE');
  94. xlabel('DIGITAL OUTPUT CODE');
  95. ylabel('INL(LSB)');  


复制代码
动态参数:(主函数)





  1. d_in=csvread('adc_data.csv');%以字符形式打开文件
  2. d11=1;d10=2;d9=3;d8=4;d7=5;d6=6;d5=7;d4=8;d3=9;d2=10;d1=11;d0=12;%标示样本矩阵的列
  3. vref=1;
  4. numpt=32768;
  5. %adc_data=d_in;
  6. adc_data=round(d_in);

  7. for i=1:numpt
  8.     dout(i)=adc_data(i,d11)/2+adc_data(i,d10)/4+adc_data(i,d9)/8 ...
  9.     +adc_data(i,d8)/16+adc_data(i,d7)/32+adc_data(i,d6)/64 ...
  10.     +adc_data(i,d5)/128+adc_data(i,d4)/254+adc_data(i,d3)/512 ...
  11.     +adc_data(i,d2)/1024+adc_data(i,d1)/2048+adc_data(i,d0)/4096;%通过转换器出来的结果,恢复原来的波形
  12.     doute(i)=dout(i)-0.5;%将正弦波的共模电平偏置为0
  13.     %doute(i)=dout(i)-mean(dout(i));
  14. end
  15. [ENOB, SNDR, SFDR, SNR, THD] = prettyFFT(dout,10e7,9,0,0,0);
  16. % function [ENOB, SNDR, SFDR, SNR, THD] = prettyFFT(wave,f_S,maxh,no_annotation,no_plot,baseline);




复制代码



prettyfft函数





  1. function [ENOB, SNDR, SFDR, SNR, THD] = prettyFFT(wave,f_S,maxh,no_annotation,no_plot,baseline);
  2. % Programmed by: Skyler Weaver, Ph.D.
  3. % Date: December 7, 2010
  4. % Version: 1.0
  5. %
  6. % This function plots a very pretty FFT plot and annotates all of the
  7. % relevant data. This is intended to be used by Nyquist guys and expects
  8. % coherently sampled data. Maybe in the future I will modify it to
  9. % automatically detect windowed data for Delta-Sigma or allow two input
  10. % tones. As for now, it is just for single sine-wave test, coherent data.
  11. %
  12. % The full function is:
  13. % [ENOB, SNDR, SFDR, SNR] = prettyFFT(wave,f_S,maxh,no_annotation,no_plot)
  14. %   'wave' can be any length but should be coherently sampled
  15. %       (required)
  16. %   'f_S' is the SAMPLING rate (i.e. f_Nyquist * 2)
  17. %       (optional, default = 1)
  18. %   'maxh' is the highest harmonic plotted, 0 means all harmonics
  19. %       (optional, default = 12) NOTE: lowering this value will affect SNR
  20. %       since SNR is calculated as SNDR with harmonics removed. Setting
  21. %       maxh to 1 will effectivly set SNR = SNDR. (1 means only the
  22. %       fundamental is a 'harmonic')
  23. %   'no_annotation' set to anything but 0 to turn off annotation
  24. %       (optional, default = 0)
  25. %   'no_plot' set to anything but 0 to not create a plot
  26. %       (optional, default = 0)
  27. %   'baseline' is the minimum value on the y-axis. When set to '0' the
  28. %       y-axis is auto-scaled such that some of the noise floor is
  29. %       displayed. It is useful to set this parameter when comparing two
  30. %       FFT plots by keeping the scale the same.
  31. %       (optional, default = 0)
  32. %
  33. % Here are some usage examples:
  34. %
  35. %    prettyFFT(some_data)
  36. %
  37. % In it's most default state, it will take some_data, grab the last
  38. % 2^integer data points, FFT it, plot it in a pretty way, normalize the
  39. % x-axis to Nyquist-rate, tag the first 12 harmonics (if above the noise
  40. % floor), annotate SFDR and SNDR/SNR (if there is room on the plot), draw a
  41. % red line where the effective noise floor is, and returns ENOB. Use this
  42. % to just plot an FFT from command line and get some useful visual feedback.
  43. %
  44. %    [ENOB,SNDR,SFDR,SNR]=prettyFFT(some_data)
  45. %
  46. % does the same thing, but you now have your stats in variables too.
  47. %
  48. %    prettyFFT(some_data,100e6,15)
  49. %
  50. % does the same thing, but the x-axis is normalized to 100MHz sampling rate.
  51. % The default of up to 12 harmonics is overridden to 15. (set to 0, it will
  52. % tag anything significantly above the noise floor, even harmonic 1032 if
  53. % it is high enough)
  54. %
  55. %    prettyFFT(some_data,100e6,15,1)
  56. %
  57. % same thing but annotation is turned off. For journals and stuff
  58. %
  59. %    prettyFFT(some_data,100e6,15,1,1)
  60. %
  61. % the extra '1' means it doesn't plot. This is in case you have a loop and
  62. % you need to get SNR, but you don't want it to keep plotting.
  63. %
  64. % Feel free to edit, but keep my name at the top.
  65. %
  66. % Enjoy!
  67. %   -Skyler

  68. if(nargin <= 0)
  69.         disp('prettyFFT: What are you trying to do, exactly?')
  70.         wave = rand(1,100);
  71.         f_S = 1;
  72.         maxh = 1;
  73.         no_annotation = 0;
  74.         no_plot = 0;
  75.         baseline = 0;
  76. end
  77. if(nargin == 1)
  78.         f_S = 1;
  79.         maxh = 12;
  80.         no_annotation = 0;
  81.         no_plot = 0;
  82.         baseline = 0;
  83. end
  84. if(nargin == 2)
  85.         maxh = 12;
  86.         no_annotation = 0;
  87.         no_plot = 0;
  88.         baseline = 0;
  89. end
  90. if(nargin == 3)
  91.         no_annotation = 0;
  92.         no_plot = 0;
  93.         baseline = 0;
  94. end
  95. if(nargin == 4)
  96.         no_plot = 0;
  97.         baseline = 0;
  98. end
  99. if(nargin == 5)
  100.         baseline = 0;
  101. end
  102. if(nargin > 6)
  103.         disp('prettyFFT: Too many arguments, man.')
  104. end

  105. text_y_offset = 4; %height above bar for harmonic # txt (def. = 4)
  106. plev = 9; %dB above noise floor to be considered a harmonic (def. = 9)

  107. [a,b]=size(wave);
  108. if(a>b)
  109.     wave=wave(:,1)';
  110. else
  111.     wave=wave(1,:);
  112. end
  113. fft_ord = floor(log(length(wave))./log(2));

  114. wave = wave(end-2^fft_ord+1:end);
  115. wave=wave-mean(wave); % remove DC offset
  116. f2 = abs(fft(wave)); % fft
  117. f2 = f2(2:floor(length(f2)/2)); % remove bin 1 (DC)

  118. [bin bin] = max(f2);
  119. f2a=[f2(1:(bin-1)) f2((bin+1):end)];
  120. f2a=[f2(1:(bin-1)) mean(f2) f2((bin+1):end)];
  121. step = (bin);
  122. pts = 2*(length(f2)+1);

  123. SNDR = mag2db((f2(bin).^2/(sum(f2.^2)-f2(bin).^2)))/2; % get SNDR (f_in / sum(the rest))
  124. ENOB=(SNDR-1.76)/6.02; % ENOB from SNDR

  125. scaledby = 1./max(f2);
  126. dbf2=mag2db(f2.*scaledby);
  127. dbf2a=[dbf2(1:(bin-1)) dbf2((bin+1):end)];
  128. dbf2a=[dbf2(1:(bin-1)) mean(dbf2) dbf2((bin+1):end)];
  129. [bins bins] =max(dbf2a);
  130. SFDR = -dbf2a(bins);

  131. noise_top = mean(dbf2a)+plev;
  132. noise_floor=mean(dbf2a);
  133. noise_bottom = mean(dbf2a)-plev;
  134. %noise_bottom = min(dbf2a);

  135. % GET HARMONICS
  136. harm = bin;
  137. t=1;
  138. nyqpts=(pts/2-1);
  139. all_harms = harm:step:(harm*nyqpts);
  140. all_harms = mod(all_harms,pts);
  141. all_harms = (pts-all_harms).*(all_harms>nyqpts) ...
  142.             + all_harms.*(all_harms<=nyqpts);
  143. all_harms = all_harms.*(all_harms>0 & all_harms<pts/2) ...
  144.             + (all_harms<=0) ...
  145.             + (all_harms>=pts/2).*nyqpts;
  146. if (maxh==0 || maxh>length(all_harms))
  147.     maxh=length(all_harms);
  148. end
  149. for k=1:maxh
  150.     if(dbf2(all_harms(k)) > noise_top)
  151.         harm(t) = all_harms(k);
  152.         hnum(t) = k;
  153.         t=t+1;
  154.     end
  155. end

  156. % GET REAL SNR
  157. numbins=2.^(fft_ord-1)-1;
  158. non_harm=1:numbins;
  159. non_harm([harm]) = [];
  160. SNR = mag2db((f2(bin).^2/(sum(f2(non_harm).^2))))/2; % get SNR (f_in / sum(the rest))
  161. %SNRpb = db(sqrt((f2(bin).^2/(sum(f2(non_harm).^2))))/numbins)-25 % get SNR (f_in / sum(the rest))
  162. SNRpb = -SNR-3.*(fft_ord-1);
  163. THD = mag2db((sum(f2.^2)-f2(bin).^2-sum(f2(non_harm).^2))/f2(bin).^2)/2;
  164. if(~no_plot)
  165. % MAKE FFT
  166. hold off
  167. f=f_S/nyqpts/2:f_S/nyqpts/2:f_S/2;

  168. h=bar(f,dbf2);   %%%% bar plot choice
  169. % h=plot(f,dbf2,'r*');  %%%% line plot choice

  170. if(~baseline)
  171. xx=max([min([SNRpb noise_bottom])-plev -250]);
  172. else
  173.     xx=baseline;
  174. end

  175. %set(get(h,"BaseLine"),"BaseValue",xx);
  176. set(h,'BaseValue',xx);
  177. set(h,'ShowBaseLine','off');
  178. set(h,'BarWidth',0.1);
  179. set(h,'LineStyle','none');
  180. axis([f(1)/2 f(end)+f(1)/2 xx 0]);

  181. if(~no_annotation)
  182. % HARMONIC RED SQUARES
  183. hold on
  184. plot(f(harm),dbf2(harm),'rs')
  185. text_y_offset = -xx/100*text_y_offset;
  186. if (length(harm) > 2)
  187.     for n=2:length(harm)
  188.         if sum(harm(1:n-1)==harm(n))
  189.             n=n-1; break, end

  190.     end
  191.     if (n<length(harm))
  192.         disp('prettyFFT: Not prime-coherent sampling!')
  193.     end
  194. else
  195.     n=length(harm);
  196. end

  197. % PRINT HARMONICS
  198. %text_y_offset = -xx/100*text_y_offset;
  199. for t=2:n
  200. text(f(harm(t)),dbf2(harm(t))+text_y_offset,num2str(hnum(t)),'HorizontalAlignment','center');
  201. end
  202. hold off

  203. hh=line([f(1)/2 f(end)+f(1)/2],[-SFDR -SFDR]);
  204. set(hh,'LineStyle','--');
  205. set(hh,'Color','k');
  206. hh1=line([f(1)/2 f(end)+f(1)/2],[SNRpb SNRpb]);
  207. set(hh1,'LineStyle','-');
  208. set(hh1,'Color','r');

  209. % where to put SFDR arrow
  210. numbins=floor(pts/2);
  211. dbin=round(numbins/32);
  212. if(numbins>4)
  213. if(bin>numbins/2+dbin*2)
  214.     if(bins<(numbins/4-dbin))|(bins>(numbins/4+dbin))
  215.         abin=round(numbins/4);
  216.     elseif (bins>numbins/4)
  217.         abin=round(numbins/4)-dbin;
  218.     else
  219.         abin=round(numbins/4)+dbin;
  220.     end
  221. else
  222.     if(bins<(3*numbins/4-dbin))|(bins>(3*numbins/4+dbin))
  223.         abin=round(3*numbins/4);
  224.     elseif (bins>3*numbins/4)
  225.         abin=round(3*numbins/4)-dbin;
  226.     else
  227.         abin=round(3*numbins/4)+dbin;
  228.     end
  229. end
  230. else
  231.     abin=12;
  232. end

  233. tempSFDR=SFDR;
  234. if(SFDR > -(.13*xx))
  235.     if(SFDR>250)
  236.         SFDR=250;
  237.     end
  238. dx=f(end)/100;
  239. dy=-xx/30;
  240. x=f(abin);
  241. tdx=max([dx (f(2)-f(1))]);
  242. hh2=line([x-dx x x+dx x x x-dx x x+dx],[-dy 0 -dy 0 -SFDR dy-SFDR -SFDR dy-SFDR]);
  243. set(hh2,'LineStyle','-');
  244. set(hh2,'Color','k');
  245. % text(f(abin)+tdx,-SFDR/2,["SFDR =\n" num2str(tempSFDR,4) 'dB'],'HorizontalAlignment','left');

  246. if(SFDR > -(.25*xx))
  247. infostr=...%['ENOB =\newline' num2str(ENOB,4) ' bits\newline\newline' ...
  248.     ["SNDR =\n" num2str(SNDR,4) "dB \n" ...
  249.     "\nSNR =\n" num2str(SNR,4) 'dB'];
  250. else
  251. infostr=...%['ENOB =\newline' num2str(ENOB,4) ' bits\newline\newline' ...
  252.     ['SNDR = ' num2str(SNDR,4) "dB \n " ...
  253.     'SNR =' num2str(SNR,4) 'dB'];
  254. end
  255. %if(bin<numbins/2)
  256. %   text(f(bin)+tdx,-SFDR/2,infostr,'HorizontalAlignment','left');
  257. %else
  258. %    text(f(bin)-tdx,-SFDR/2,infostr,'HorizontalAlignment','right');
  259. %end
  260. end
  261. ylabel('dB')
  262. xlabel('Frequency(Hz)')
  263. title('ADC spectrum analysis to obtain SFDR/SNDR/SNR')
  264. SFDR = tempSFDR;
  265. end % end if(~no_annotation)
  266. end % end if(~no_plot)
  267. hold on;
  268. s1=sprintf('SFDR = %4.1fdB\n',SFDR);
  269. s2=sprintf('THD = %4.1fdB\n',THD);
  270. s3=sprintf('SNR   = %4.1fdB\n',SNR);
  271. s4=sprintf('SNDR = %4.1fdB\n',SNDR);
  272. s5=sprintf('ENOB = %4.2fbit\n',ENOB);
  273. text(25,-10,s1);
  274. text(25,-20,s2);
  275. text(25,-30,s3);
  276. text(25,-40,s4);
  277. text(25,-50,s5);
  278. hold off;


复制代码


发表于 2021-5-26 10:22:47 | 显示全部楼层
请教楼主一个问题,谢谢。
我现在在测试一个10bit的SAR_ADC,输入的是一个下图所示的阶梯型波,周期很长ADC转换输出数据被HAPS(我也不知道这个玩意使什么)采集。这个HAPS只把每个输出数据成16进制数据,保存下来。
我需要计算一下DNL和INL,请问,楼主帖子中的代码可以直接用来计算我的数据吗?或者如何修改一下输出数据才能用楼主的代码进行计算?再次说谢谢!

输入信号波形

输入信号波形
发表于 2021-5-26 10:26:02 | 显示全部楼层
另外,想请问一下楼主,有没有从零开始学习ADC的资料呀?可以分享一下吗?
一些原理性的学习资料已经有很多了,但是没有那种设计flow的那种资料,比如从最开始的MATLAB建模和验证到schematic的设计和仿真等等。
期待您的回复,谢谢!!
 楼主| 发表于 2021-5-29 16:28:18 | 显示全部楼层


江上飘来 发表于 2021-5-26 10:22
请教楼主一个问题,谢谢。
我现在在测试一个10bit的SAR_ADC,输入的是一个下图所示的阶梯型波,周期很长ADC ...


测试需要输入一个接近满幅的正弦信号,而且采样频率和信号频率需要满足相干采样。帖子中的代码需要ADC输出的N列数字码,现在我又改了一下代码,可以先用理想DAC输出模拟信号的波形,然后再测试。



  1. %Code density/histofgram test to calculate INL and DNL require a large number of samples.
  2. %Step 1: Apply a close to full-scale sine wave (but not clipping) and find the mid-code for the applied signal.
  3. %Step 2: Apply the same sine wave input, but slightly larger amplitude to clip the ADC slightly.
  4. %Run the following program, enter the number of samples, resolution and mid-code from Step 1and continue.
  5. %Copyright Au/Hofner, Maxim Integrated Products, 120 San Gabriel Drive, Sunnyvale, CA94086
  6. %This program is believed to be accurate and reliable. This program may get altered without prior notification.

  7. %用于计算INL和DNL的%代码密度/直方图测试需要大量样本。
  8. %步骤1:施加接近满量程的正弦波(但不削波),并找到所施加信号的中间码。
  9. %步骤2:施加相同的正弦波输入,但幅度稍大些,以对ADC进行稍稍削波。
  10. %运行以下程序,输入步骤1中的样本数量,分辨率和中间代码,然后继续。版权所有Au / Hofner,Maxim Integrated Products,120 San Gabriel Drive,Sunnyvale,CA94086
  11. %该程序被认为是准确和可靠的。 该程序可能会更改,恕不另行通知。


  12. d_in=csvread('filename.csv');%以字符形式打开文件

  13. adc_data=round(d_in);

  14. [numpt,row]=size(d_in);
  15. numbit=12;
  16. mid_code=2048;
  17. d11=1;d10=2;d9=3;d8=4;d7=5;d6=6;d5=7;d4=8;d3=9;d2=10;d1=11;d0=12;
  18. dout=adc_data;

  19. [a,b]=size(dout);
  20. if(a>b)
  21.     dout=dout(:,1)';
  22. else
  23.     dout=dout(1,:);
  24. end

  25. mid_file=[dout ; dout];
  26. mid_file=double(mid_file);


  27. v1=mid_file';
  28. code=v1(:,2);
  29. code_count=zeros(1,2^numbit);

  30. for i=1:2^numbit
  31.     count=0;%附值
  32.     for j=1:numpt
  33.         if code(j)==i-1
  34.             count=count+1;
  35.         else count=count;
  36.         end
  37.     end
  38.     code_count(i)=count;
  39. end

  40. if code_count(1) == 0 | code_count(2^numbit) == 0 | ...
  41.   (code_count(1) < code_count(2)) | (code_count(2^numbit-1) > code_count(2^numbit))
  42.    disp('ADC not clipping ... Increase sinewave amplitude!');
  43.   % break;
  44. end

  45. A=max(mid_code,2^numbit-1-mid_code)+0.1;
  46. vin=(0:2^numbit-1)-mid_code;       
  47. sin2ramp=1./(pi*sqrt(A^2*ones(size(vin))-vin.*vin));

  48. while sum(code_count(2:2^numbit-1)) < numpt*sum(sin2ramp(2:2^numbit-1))
  49.   A=A+0.1;
  50.   sin2ramp=1./(pi*sqrt(A^2*ones(size(vin))-vin.*vin));
  51. end

  52. disp('You Have Applied a Sine Wave of (dBFS): ');
  53. Amplitude=A/(2^numbit/2)
  54. figure;
  55. plot([0:2^numbit-1],code_count,[0:2^numbit-1],sin2ramp*numpt);
  56. title('CODE HISTOGRAM - SINE WAVE');
  57. xlabel('DIGITAL OUTPUT CODE');
  58. ylabel('COUNTS');
  59. axis([0 2^numbit-1 0 max(code_count)]);
  60. code_countn=code_count(2:2^numbit-1)./(numpt*sin2ramp(2:2^numbit-1));
  61. figure;
  62. plot([1:2^numbit-2],code_countn);
  63. title('CODE HISTOGRAM - NORMALIZED')
  64. xlabel('DIGITAL OUTPUT CODE');
  65. ylabel('NORMALIZED COUNTS');

  66. dnl=code_countn-1;
  67. inl=zeros(size(dnl));
  68. for j=1:size(inl')
  69.    inl(j)=sum(dnl(1:j));
  70. end

  71. %End-Point fit INL
  72. %[p,S]=polyfit([1,2^numbit-2],[inl(1),inl(2^numbit-2)],1);

  73. %Best-straight-line fit INL
  74. [p,S]=polyfit([1:2^numbit-2],inl,1);
  75. inl=inl-p(1)*[1:2^numbit-2]-p(2);

  76. disp('End Points Eliminated for DNL and INL Calculations');
  77. figure;
  78. plot([1:2^numbit-2],dnl);
  79. grid on;
  80. title('DIFFERENTIAL NONLINEARITY vs. DIGITAL OUTPUT CODE');
  81. xlabel('DIGITAL OUTPUT CODE');
  82. ylabel('DNL (LSB)');
  83. figure;
  84. plot([1:2^numbit-2],inl);
  85. grid on;
  86. title('INTEGRAL NONLINEARITY vs. DIGITAL OUTPUT CODE');
  87. xlabel('DIGITAL OUTPUT CODE');
  88. ylabel('INL(LSB)');  


复制代码


 楼主| 发表于 2021-5-29 16:30:21 | 显示全部楼层


江上飘来 发表于 2021-5-26 10:26
另外,想请问一下楼主,有没有从零开始学习ADC的资料呀?可以分享一下吗?
一些原理性的学习资料已经有很多 ...


这个没有。matlab模型的话这个论坛里就有
发表于 2021-6-10 11:36:29 | 显示全部楼层
多谢
发表于 2021-6-28 14:52:46 | 显示全部楼层
ths mark
发表于 2021-7-9 10:20:05 | 显示全部楼层
非常感谢
发表于 2021-7-13 10:30:19 | 显示全部楼层


kongc 发表于 2021-5-29 16:28
测试需要输入一个接近满幅的正弦信号,而且采样频率和信号频率需要满足相干采样。帖子中的代码需要ADC输 ...


楼主,非常感谢您的回复。
再请教个问题。我的ADC不能连续取样,只能配置一次寄存器采样一次。请问可以用这个代码吗?
我听说输入sine波的话,需要保证ADC和sine同步。
我想输入ramp斜波,请问这个代码可以用吗?
发表于 2021-8-13 11:48:45 | 显示全部楼层
想詢問樓主有輸入.CSV檔案的範例嗎
我怕我不能跑
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

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

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

GMT+8, 2024-4-28 03:25 , Processed in 0.034797 second(s), 7 queries , Gzip On, Redis On.

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