Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %InnovateFPGA 2019
- %Team Number: EM002
- %Project Name: Successive-approximation-memory (SAM) analog-to-digital converter (ADC)
- clear all;
- function y = SquareWave(n,x)
- y = 1.5 + sin(x * (4 + n));
- %y = 1.5 + (sin(x * (4 + n)) > 0) * 2 - 1.0;
- endfunction
- f_width = 500;
- f_height = 150;
- %f_width = 1500;
- %f_height = 550;
- h = figure('position',[100,100,f_width,f_height]);
- filename = 'SAM_ADC_Animated.gif';
- xMAX = 10;
- xSTEP = 0.01;
- xNUM = (xMAX/xSTEP) + 1;
- iterNUM = 6;
- x = 0:xSTEP:xMAX;
- SignalIN = SquareWave(0,x);
- ComparatorOUT = ones(1, xNUM);
- ApproximationLogicOUT = zeros(1, xNUM);
- DACOUT = zeros(1, xNUM);
- for n = 1:1:iterNUM
- DACOUT = ApproximationLogicOUT;
- ComparatorOUT = (SignalIN - DACOUT > 0.0) * 2 - 1;
- ApproximationLogicOUT = ApproximationLogicOUT + (ComparatorOUT * 3 / (2^n));
- plot(x,SignalIN,"b;Signal input;",...
- x,DACOUT,"g;DAC output;",...
- x,ComparatorOUT * 0.3,"m;Comparator result;");
- axis([0, 10, -0.4, 3]);
- drawnow;
- % Capture the plot as an image
- frame = getframe(h,[1,1,f_width-1,f_height-3]);
- im = frame2im(frame);
- [imind,cm] = rgb2ind(im);
- % Write to the GIF File
- if n == 1
- imwrite(imind,cm,filename,'gif','WriteMode','overwrite','Loopcount',inf,'DelayTime',1.5);
- elseif n == iterNUM
- imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',6.5);
- else
- imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',1.5);
- endif
- end
- delete(h);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement