Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.72 KB | None | 0 0
  1. clear all;
  2. close all;
  3. clc;
  4.  
  5.  
  6. % Regular Gradient descent Synapses
  7. R = 1000*[0 30 30 30; 0 0 30 30; 0 0 0 30; 0 0 0 0];
  8.  
  9. R12 = 30000;
  10. R13 = 30000;
  11. R14 = 30000;
  12. R23 = 30000;
  13. R24 = 30000;
  14. R34 = 30000;
  15.  
  16.  
  17.  
  18. % Define constants
  19. tau = 400e-12; % RC constant
  20. fs=100e3;
  21. fi = 1/(160e-6);
  22. cycles=512;
  23. N=fs/fi*cycles;
  24. ts = (0:1/fs:(50e-3)-1/fs);
  25. Ns= 5e3;
  26.  
  27. % CLK
  28. tr=1/fs*(1:N);
  29. tf=tr+1/(2*fs);
  30. dt=1/(2*fs);
  31.  
  32.  
  33. prompt = 'Enter non_ideal parameter value ';
  34. non_ideal = input(prompt);
  35.  
  36.  
  37. %%%%%%%%%%%%%%%%
  38. % Noise sources
  39. %%%%%%%%%%%%%%%%
  40. % Comparator mismatch
  41. kVth=5e-3;
  42. area_tran=100;
  43. sVth=kVth/sqrt(area_tran);
  44.  
  45. % There are two transistors in a differential comparator
  46. sVth=sqrt(2*sVth^2);
  47. offset=random('norm',0,sVth,1,length(ts));
  48.  
  49. % Comparator input noise
  50. sNoise=(10e-9)*sqrt(6.25e3);
  51. %noise=random('norm',0,sNoise,1,length(ts));
  52.  
  53. %Thermal noise
  54. thNoise=10e-16;
  55.  
  56. % Resistance mismatch
  57. sR = 0.05/sqrt(32);
  58.  
  59. frec=1;
  60. % Jitter
  61. sJit=20e-3; %frequency dependent
  62. vJit=random('norm',0,sJit,1,length(ts));
  63.  
  64.  
  65. % Resistance ladder
  66. Rf= normrnd(45e3,sR*(45e3),1,6);
  67. %Rf = 90e3;
  68. Rin= normrnd(45e3,sR*(45e3),1,4);
  69. RRef = normrnd([45e3 22.5e3 11.25e3 5.625e3], sR*(22.5e3),1,4);
  70.  
  71.  
  72. %Input
  73. %vin = 1.8/2*(1 + sawtooth(ts*fi*(2*pi)));
  74. alpha = 1.8/16;
  75. %vin=linspace(0,1.8-alpha, length(tr));
  76. vin = [0:alpha:1.8 - alpha];
  77.  
  78.  
  79. % Cap response
  80. vC=zeros(1,length(ts));
  81. %for i=1:length(ts)
  82. % vC(i)=vin(i)*(1-exp(-dt/tau))+noise(i);
  83. %end
  84.  
  85. %learning parameters
  86. Vref = 0.1125;
  87. Y = zeros(1,4);
  88. E_threshold = 1e-8;
  89. T_write = 5e-6;
  90. dt = 0.54e-8;
  91. %RMOS = 450;
  92. %K = 1e-3;
  93. Vp = 0.5;
  94. %Ron = 100;
  95. %Roff = 200e3;
  96. RMOS = normrnd(700,sR*(700),1,100);
  97. Yvar = normrnd(1,0.1*(1),1,4);
  98. Kon = normrnd(-4.8e-3,0.01*(4.8e-3),1,100);
  99. Koff = normrnd(2.8125e-3,0.01*(2.8125e-3),1,100);
  100. Von = -0.3;
  101. Voff = 0.4;
  102. %Von = normrnd(0.3,0.033*(0.3),1,6);
  103. %Vp = normrnd(0.5,0.1*0.5);
  104. %Vpgd = normrnd(0.4,0.1*0.4);
  105. Roff = normrnd(100e3,sR*(100e3),1,100);
  106. Ron = normrnd(2000,sR*(2000),1,100);
  107. VR_parasite = 0.015; %frequency dependent
  108.  
  109. E = 1 ;
  110. E_rate = 1;
  111.  
  112.  
  113. %Digital data set
  114. D = 1.8*[0 0 0 0; 0 0 0 1; 0 0 1 0; 0 0 1 1; 0 1 0 0; 0 1 0 1; 0 1 1 0; 0 1 1 1;
  115. 1 0 0 0; 1 0 0 1; 1 0 1 0; 1 0 1 1; 1 1 0 0; 1 1 0 1; 1 1 1 0; 1 1 1 1;];
  116.  
  117. n = 0;
  118.  
  119. t = 1;
  120. A = 0;
  121. DAC = zeros(1, length(vin));
  122. Neurons = zeros(4, length(vin));
  123. vout = zeros(1, length(vin));
  124.  
  125.  
  126.  
  127. %binary-weighted gradient descent Training loop
  128. W_prev = 1/2.+zeros(1,100);
  129. gamma = 1;
  130. for l = 1:1 %2000 samples 20ms
  131. Ptot_neuron = 0;
  132. Ptot_net = 0;
  133. Ptot_comparator = 0;
  134. for x = 1: length(vin)
  135. %k = randi([1,length(vin)]); %random dataset
  136. k = x;
  137.  
  138. noise=random('norm',0,sNoise);
  139. thermnoise = random('norm',0,thNoise);
  140. vJit=random('norm',0,sJit);
  141.  
  142. if vin(k)> 1.793
  143. vin(k)=0;
  144. end
  145. indx = int16(vin(k)/alpha) + 1;
  146.  
  147. n = n+1;
  148. vC(n)=vin(k)*(1-exp(-dt/tau));
  149. if non_ideal == 1
  150. Y(4) = activation(vin(k) - 8*Vref);
  151. Y(3) = activation(vin(k) +vJit - 4*Vref - (Rf(3)/(R(3,4)+RMOS(3*10+4) + thermnoise))*Y(4)*Yvar(4)/18 + noise +VR_parasite);
  152. Y(2) = activation(vin(k) +vJit - 2*Vref - (Rf(2)/(R(2,4)+RMOS(2*10+4)+ thermnoise))*Y(4)*Yvar(4)/18 - (Rf(2)/(R(2,3)+RMOS(2*10+3)+ thermnoise))*Y(3)*Yvar(3)/18 + noise +VR_parasite);
  153. Y(1) = activation(vin(k)+vJit - 1*Vref - (Rf(1)/(R(1,4)+RMOS(1*10+4)+ thermnoise))*Y(4)*Yvar(4)/18 - (Rf(2)/(R(1,3)+RMOS(1*10+3)+ thermnoise))*Y(3)*Yvar(3)/18 - (Rf(1)/(R(1,2)+RMOS(1*10+2)+ thermnoise))*Y(2)*Yvar(2)/18 + noise +VR_parasite);
  154. else
  155. % Y(5) = activation(vin(k) - 16*Vref);
  156. % Y(4) = activation(vin(k) - 8*Vref - 16*Y(5)/18);
  157. % Y(3) = activation(vin(k) - 4*Vref - 8*Y(4)/18 - 16*Y(5)/18);
  158. % Y(2) = activation(vin(k) - 2*Vref - 4*Y(3)/18 - 8*Y(4)/18 - 16*Y(5)/18);
  159. % Y(1) = activation(vin(k) - 1*Vref - 2*Y(2)/18 - 4*Y(3)/18 - 8*Y(4)/18 - 16*Y(5)/18);
  160.  
  161. Y(4) = activation(vin(k) - 8*Vref)
  162. Y(3) = activation(vin(k) - 4*Vref - 8*Y(4)/16)
  163. Y(2) = activation(vin(k) - 2*Vref - 4*Y(3)/16 - 8*Y(4)/16)
  164. Y(1) = activation(vin(k) - 1*Vref - 2*Y(2)/16 - 4*Y(3)/16 - 8*Y(4)/16)
  165. end
  166.  
  167. Rfed=45e3;
  168. P1_neuron = (vin(k) - 8*Vref )^2/Rfed ;
  169. P1_net = vin(k)^2/Rfed + Vref^2/Rfed/8;
  170. P2_neuron = (vin(k) - 4*Vref - (Rfed/(R(3,4)+450))*Y(4)/18)^2/Rfed ;
  171. P2_net = vin(k)^2/Rfed + Vref^2/Rfed/4 + (Y(4)/18)^2/(R(3,4)+450);
  172. P3_neuron = (vin(k) - 2*Vref - (Rfed/(R(2,4)+450))*Y(4)/18 - (Rfed/(R(2,3)+450))*Y(3)/18)^2/Rfed ;
  173. P3_net = vin(k)^2/Rfed + Vref^2/Rfed/2 + (Y(4)/18)^2/(R(2,4)+450) + (Y(3)/18)^2/(R(2,3)+450);
  174. P4_neuron = (vin(k) - 1*Vref - (Rfed/(R(1,4)+450))*Y(4)/18 - (Rfed/(R(1,3)+450))*Y(3)/18 - (Rfed/(R(1,2)+450))*Y(2)/18)^2/Rfed ;
  175. P4_net = vin(k)^2/Rfed + Vref^2/Rfed/1 + (Y(4)/18)^2/(R(1,4)+450) + (Y(3)/18)^2/(R(1,3)+450) + (Y(2)/18)^2/(R(1,2)+450);
  176. %Ptot_net = Ptot_net + P1_net + P2_net + P3_net + P4_net ;
  177. Ptot_neuron = Ptot_neuron + P1_neuron + P2_neuron + P3_neuron + P4_neuron ;
  178. %Ptot_comparator = Ptot_comparator + 4*(1e-8);
  179.  
  180. fliplr(Y);
  181. D(ceil(indx),:);
  182. E(end + 1) = (0.125/(1.8^2))*((Y(1) - D(ceil(indx),4))^2 + (Y(2) - D(ceil(indx),3))^2 + (Y(3) - D(ceil(indx),2))^2 + (Y(4) - D(ceil(indx),1))^2 + 0.01*rand()^2) + E(end);
  183. if E(end) == 0 %false positive case
  184. continue;
  185. end
  186. DAC(n) = 1/16*(1*Y(1)+ 2*Y(2) + 4*Y(3) + 8*Y(4));
  187. % Neurons(1,n) =Y(5);
  188. Neurons(1,n) =Y(4);
  189. Neurons(2,n) =Y(3);
  190. Neurons(3,n) =Y(2);
  191. Neurons(4,n) =Y(1);
  192. vout(n) = vin(k);
  193.  
  194. E_rate(end+1) = (1/n)*E(end);
  195. t(end+1) = t(end) + 1;
  196. if E_rate(end) < E_threshold
  197. break;
  198. end
  199. for i = 1:4
  200. for j = 1:4
  201. if i >= j
  202. R(i,j) = 0;
  203. else
  204. x = 10*i +j;
  205. W_f = W_prev(x)*(1-W_prev(x));
  206. if (D(ceil(indx),5-i) - Y(i))>=0
  207. Vw = -1*Vp*(R(i,j)/(R(i,j)+ RMOS(x)));
  208. dW = -1*Kon(x)*((Vw/Von -1)^3)*W_f;
  209. else
  210. Vw = 1*Vp*(R(i,j)/(R(i,j)+ RMOS(x)));
  211. dW = Koff(x)*((Vw/Voff -1)^1)*W_f;
  212. end
  213.  
  214. if n < 1600
  215. gamma = 1;
  216. elseif n>=1600 && n<2400
  217. gamma = 0.5;
  218. elseif n>=2800 && n<3200
  219. gamma = 0.25;
  220. else
  221. gamma = 0.03;
  222. end
  223.  
  224. beta = gamma*0.09*(Roff(x)-Ron(x))*dW*T_write/dt;
  225.  
  226. %if R(i) + beta*(D(ceil(indx),5-i) - Y(i))*D(ceil(indx),5-j)*Yvar(i)/1.8 >= Roff(x)
  227. % continue
  228. %end
  229. %if R(i) + beta*(D(ceil(indx),5-i) - Y(i))*D(ceil(indx),5-j)*Yvar(i)/1.8 <= Ron(x)
  230. % continue
  231. %end
  232.  
  233. %R(i,j) = R(i,j) + beta*random('norm',(D(ceil(indx),5-i) - Y(i))*D(ceil(indx),5-j)/(1.8^2), thNoise) + thermnoise;
  234. R(i,j) = R(i,j) + beta*(D(ceil(indx),5-i) - Y(i)+ 0.0001*rand())*D(ceil(indx),5-j)/(1.8^2);
  235. W_prev(x) = R(i,j)/(Roff(x) - Ron(x));
  236. end
  237. end
  238. end
  239. R12(end+1) = R(1,2);
  240. R13(end+1) = R(1,3);
  241. R14(end+1) = R(1,4);
  242. R23(end+1) = R(2,3);
  243. R24(end+1) = R(2,4);
  244. R34(end+1) = R(3,4);
  245.  
  246.  
  247. end
  248. if E_rate(end) < E_threshold
  249. break;
  250. end
  251. P(l) = (Ptot_comparator + Ptot_net + Ptot_neuron )/2^4;
  252. end
  253.  
  254.  
  255. %%
  256. figure(1);
  257. hold on;
  258. ylabel('Training Error','FontSize',18);
  259. xlabel('#Samples','FontSize',18);
  260.  
  261.  
  262. plot(t,E_rate,'LineWidth',4);
  263. grid on;
  264. leg = legend('Algorithm');
  265. set(leg,'FontSize',12);
  266. set(gca,'FontSize',12);
  267.  
  268.  
  269. figure(3);
  270. hold on;
  271. plot(t,(45e3)./R12);
  272. plot(t,(45e3)./R13);
  273. plot(t,(45e3)./R14);
  274. plot(t,(45e3)./R23);
  275. plot(t,(45e3)./R24);
  276. plot(t,(45e3)./R34);
  277.  
  278. figure;
  279. plot(P);
  280.  
  281.  
  282. tf = t(1:length(t)-1);
  283. figure(4);
  284. hold on;
  285. stairs(tf,DAC), xlim([n-300 n]);
  286. stairs(tf,vout), xlim([n-300 n]);
  287.  
  288. figure(5);
  289. subplot(4,1,1);
  290. stairs((n-48:n),Neurons(1,n-48:n),'b','linewidth',2);
  291. subplot(4,1,2);
  292. stairs((n-48:n),Neurons(2,n-48:n),'r','linewidth',2);
  293. subplot(4,1,3);
  294. stairs((n-48:n),Neurons(3,n-48:n),'g','linewidth',2);
  295. subplot(4,1,4);
  296. stairs((n-48:n),Neurons(4,n-48:n),'y','linewidth',2);
  297. % subplot(4,1,5);
  298. % stairs((n-48:n),Neurons(5,n-48:n),'y','linewidth',2);
  299.  
  300.  
  301. figure(6);
  302. subplot(4,1,1);
  303. stairs((n-3848:n-3800),Neurons(1,n-3848:n-3800),'b','linewidth',2);
  304. subplot(4,1,2);
  305. stairs((n-3848:n-3800),Neurons(2,n-3848:n-3800),'r','linewidth',2);
  306. subplot(4,1,3);
  307. stairs((n-3848:n-3800),Neurons(3,n-3848:n-3800),'g','linewidth',2);
  308. subplot(4,1,4);
  309. stairs((n-3848:n-3800),Neurons(4,n-3848:n-3800),'y','linewidth',2);
  310. % subplot(4,1,5);
  311. % stairs((n-3848:n-3800),Neurons(5,n-3848:n-3800),'y','linewidth',2);
  312. %
  313. figure(7);
  314. subplot(4,1,1);
  315. stairs((1:48),Neurons(1,1:48),'b','linewidth',2);
  316. subplot(4,1,2);
  317. stairs((1:48),Neurons(2,1:48),'r','linewidth',2);
  318. subplot(4,1,3);
  319. stairs((1:48),Neurons(3,1:48),'g','linewidth',2);
  320. subplot(4,1,4);
  321. stairs((1:48),Neurons(4,1:48),'y','linewidth',2);
  322. % subplot(4,1,5);
  323. % stairs((1:48),Neurons(5,1:48),'y','linewidth',2);
  324.  
  325.  
  326.  
  327.  
  328. %% %% Static Evaluation
  329.  
  330. %maxDNL =zeros(1,length(R12));
  331. %maxINL =zeros(1,length(R12));
  332. %for id = 1:length(R12)
  333. %Input
  334.  
  335. VFS = 1.8;
  336. vin = [0:0.001:15/16*VFS];
  337.  
  338.  
  339. index = length(R12);
  340. R_mean_f = [mean(R14(index - 48:index-1)), mean(R24(index - 48:index-1)),mean(R34(index - 48:index-1)),mean(R13(index - 48:index-1)), mean(R23(index - 48:index-1)),mean(R12(index - 48:index-1))];
  341. vout_f=zeros(length(tr),4);
  342. vout_c=zeros(length(tr),4);
  343. vout_i=zeros(length(tr),4);
  344. out_f = zeros(length(vin),1);
  345. out_i = zeros(length(vin),1);
  346. out_c = zeros(length(vin),1);
  347. for i=1:length(vin)
  348. for j=1:1
  349. noise=random('norm',0,sNoise);
  350. thermnoise = random('norm',0,thNoise);
  351. vJit=random('norm',0,sJit);
  352. vout_f(i,1) = activation(vin(i) - 8*Vref);
  353. vout_f(i,2) = activation(vin(i) +vJit - 4*Vref - (Rf(3)/(R_mean_f(3)+RMOS(3*10+4) + thermnoise))*vout_f(i,1)*Yvar(4)/18 + noise +VR_parasite);
  354. vout_f(i,3) = activation(vin(i) +vJit - 2*Vref - (Rf(2)/(R_mean_f(2)+RMOS(2*10+4)+ thermnoise))*vout_f(i,1)*Yvar(4)/18 - (Rf(2)/(R_mean_f(5)+RMOS(2*10+3)+ thermnoise))*vout_f(i,2)*Yvar(3)/18 + noise +VR_parasite);
  355. vout_f(i,4) = activation(vin(i)+vJit - 1*Vref - (Rf(1)/(R_mean_f(1)+RMOS(1*10+4)+ thermnoise))*vout_f(i,1)*Yvar(4)/18 - (Rf(2)/(R_mean_f(4)+RMOS(1*10+3)+ thermnoise))*vout_f(i,2)*Yvar(3)/18 - (Rf(1)/(R_mean_f(6)+RMOS(1*10+2)+ thermnoise))*vout_f(i,3)*Yvar(2)/18 + noise +VR_parasite);
  356.  
  357. for j=1:4
  358. out_f(i) = out_f(i) + (vout_f(i,j)/1.8)*power(2,4-j);
  359. end
  360. end
  361. end
  362.  
  363.  
  364. R_mean_c = [mean(R14(index - 3000:index-2600)), mean(R24(index - 3000:index-2600)),mean(R34(index - 3000:index-2600)),mean(R13(index - 3000:index-2600)), mean(R23(index - 3000:index-2600)),mean(R12(index - 3000:index-2600))];
  365. for i=1:length(vin)
  366. for j=1:1
  367. noise=random('norm',0,sNoise);
  368. thermnoise = random('norm',0,thNoise);
  369. vJit=random('norm',0,sJit);
  370. vout_c(i,1) = activation(vin(i) - 8*Vref);
  371. vout_c(i,2) = activation(vin(i) +vJit - 4*Vref - (Rf(3)/(R34(200)+RMOS(3*10+4) + thermnoise))*vout_c(i,1)*Yvar(4)/18 + noise +VR_parasite);
  372. vout_c(i,3) = activation(vin(i) +vJit - 2*Vref - (Rf(2)/(R24(200)+RMOS(2*10+4)+ thermnoise))*vout_c(i,1)*Yvar(4)/18 - (Rf(2)/(R23(200)+RMOS(2*10+3)+ thermnoise))*vout_c(i,2)*Yvar(3)/18 + noise +VR_parasite);
  373. vout_c(i,4) = activation(vin(i)+vJit - 1*Vref - (Rf(1)/(R14(200)+RMOS(1*10+4)+ thermnoise))*vout_c(i,1)*Yvar(4)/18 - (Rf(2)/(R13(200)+RMOS(1*10+3)+ thermnoise))*vout_c(i,2)*Yvar(3)/18 - (Rf(1)/(R12(200)+RMOS(1*10+2)+ thermnoise))*vout_c(i,3)*Yvar(2)/18 + noise +VR_parasite);
  374.  
  375. for j=1:4
  376. out_c(i) = out_c(i) + (vout_c(i,j)/1.8)*power(2,4-j);
  377. end
  378. end
  379. end
  380.  
  381.  
  382. for i=1:length(vin)
  383. for j=1:1
  384. noise=random('norm',0,sNoise);
  385. thermnoise = random('norm',0,thNoise);
  386. vJit=random('norm',0,sJit);
  387. vout_i(i,1) = activation(vin(i) - 8*Vref);
  388. vout_i(i,2) = activation(vin(i) +vJit - 4*Vref - (Rf(3)/(R34(1)+RMOS(3*10+4) + thermnoise))*vout_i(i,1)*Yvar(4)/18 + noise +VR_parasite);
  389. vout_i(i,3) = activation(vin(i) +vJit - 2*Vref - (Rf(2)/(R24(1)+RMOS(2*10+4)+ thermnoise))*vout_i(i,1)*Yvar(4)/18 - (Rf(2)/(R23(1)+RMOS(2*10+3)+ thermnoise))*vout_i(i,2)*Yvar(3)/18 + noise +VR_parasite);
  390. vout_i(i,4) = activation(vin(i)+vJit - 1*Vref - (Rf(1)/(R14(1)+RMOS(1*10+4)+ thermnoise))*vout_i(i,1)*Yvar(4)/18 - (Rf(2)/(R13(1)+RMOS(1*10+3)+ thermnoise))*vout_i(i,2)*Yvar(3)/18 - (Rf(1)/(R12(1)+RMOS(1*10+2)+ thermnoise))*vout_i(i,3)*Yvar(2)/18 + noise +VR_parasite);
  391.  
  392. for j=1:4
  393. out_i(i) = out_i(i) + (vout_i(i,j)/1.8)*power(2,4-j);
  394. end
  395. end
  396. end
  397.  
  398.  
  399.  
  400.  
  401.  
  402. LSB=1/16;
  403. out_step_unique = unique(out_f);
  404. out_step = zeros(1,16);
  405. for j=1:length(out_step_unique)
  406. out_step(out_step_unique(j)+1) = out_step_unique(j);
  407. end
  408.  
  409. w = length(out_step);
  410. s=zeros(1,w);
  411. in=zeros(1,w);
  412. for i=2: w+1
  413. s(i-1) = find(out_f == out_step(i-1), 1, 'first');
  414. in(i-1) = vin(s(i-1));
  415. end
  416. %x= diff(in);
  417. steps =zeros(1,15);
  418. last = 0;
  419. for k=1:15
  420. if in(k) == 0
  421. steps(k) = 0;
  422. else
  423. steps(k) = in(k) - last;
  424. last = in(k);
  425. end
  426. end
  427. step_av=mean(steps)
  428. DNL_f= steps/step_av - 1;
  429. DNL_f(1) = 0;
  430. maxDNL_f=max(DNL_f)
  431.  
  432. INL_f=zeros(1,length(out_step));
  433. for i = 1:length(steps)
  434. INL_f(i) = sum(DNL_f(1:i-1));
  435. end
  436.  
  437.  
  438. maxINL_f=max(INL_f);
  439.  
  440.  
  441. out_step_unique = unique(out_c);
  442. out_step = zeros(1,16);
  443. for j=1:length(out_step_unique)
  444. out_step(out_step_unique(j)+1) = out_step_unique(j);
  445. end
  446.  
  447. w = length(out_step);
  448. s=zeros(1,w);
  449. in=zeros(1,w);
  450. for i=2: w+1
  451. s(i-1) = find(out_f == out_step(i-1), 1, 'first');
  452. in(i-1) = vin(s(i-1));
  453. end
  454. %x= diff(in);
  455. steps =zeros(1,15);
  456. last = 0;
  457. for k=1:15
  458. if in(k) == 0
  459. steps(k) = 0;
  460. else
  461. steps(k) = in(k) - last;
  462. last = in(k);
  463. end
  464. end
  465. step_av=mean(steps)
  466. DNL_c= steps/step_av - 1;
  467. DNL_c(1) =0;
  468. maxDNL_f=max(DNL_c)
  469.  
  470. INL_c=zeros(1,length(out_step));
  471. for i = 1:length(steps)
  472. INL_c(i) = sum(DNL_c(1:i-1));
  473. end
  474.  
  475.  
  476. maxINL_c=max(INL_c);
  477.  
  478.  
  479.  
  480. out_step_unique = unique(out_i);
  481. out_step = zeros(1,16);
  482. for j=1:length(out_step_unique)
  483. out_step(out_step_unique(j)+1) = out_step_unique(j);
  484. end
  485.  
  486. w = length(out_step);
  487. s=zeros(1,w);
  488. in=zeros(1,w);
  489. for i=2: w+1
  490. s(i-1) = find(out_i == out_step(i-1), 1, 'first');
  491. in(i-1) = vin(s(i-1));
  492. end
  493. %x= diff(in);
  494. steps =zeros(1,15);
  495. last = 0;
  496. for k=1:15
  497. if in(k) == 0
  498. steps(k) = 0;
  499. else
  500. steps(k) = in(k) - last;
  501. last = in(k);
  502. end
  503. end
  504. step_av=mean(steps)
  505. DNL_i= steps/step_av - 1;
  506. DNL_i(1) =0;
  507. maxDNL_i=max(DNL_i)
  508.  
  509. INL_i=zeros(1,length(out_step));
  510. for i = 1:length(steps)
  511. INL_i(i) = sum(DNL_i(1:i-1));
  512. end
  513.  
  514.  
  515. maxINL_i=max(INL_i);
  516.  
  517.  
  518.  
  519.  
  520.  
  521. %end
  522. %close all
  523. figure
  524. hold on
  525. plot((0:14),DNL_f,'b-*','linewidth',2);
  526. plot((0:14),DNL_c,'r--','linewidth',2);
  527. plot((0:14),DNL_i,'g--','linewidth',2);
  528. hold off
  529. ylabel('DNL (LSB)');
  530. xlabel('Input code')
  531. legend('Gradient Descent')
  532. xlim([0 14])
  533. box on
  534. set(gca,'linewidth',3)
  535. set(findall(gcf,'-property','FontSize'),'FontSize',44)
  536. set(findall(gcf,'-property','FontName'),'FontName','Calibri')
  537. set(findall(gcf,'-property','FontWeight'),'FontWeight','bold')
  538.  
  539. figure
  540. hold on
  541. plot((0:15),INL_f,'b-*','linewidth',2);
  542. plot((0:15),INL_c,'r--','linewidth',2);
  543. plot((0:15),INL_i,'g--','linewidth',2);
  544. ylabel('INL (LSB)');
  545. xlabel('Input code')
  546. hold off
  547. box on
  548. xlim([0 15])
  549. legend('Gradient Descent')
  550. set(gca,'linewidth',3)
  551. set(findall(gcf,'-property','FontSize'),'FontSize',44)
  552. set(findall(gcf,'-property','FontName'),'FontName','Calibri')
  553. set(findall(gcf,'-property','FontWeight'),'FontWeight','bold')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement