B. Use the values you captured from your ADC to plot all three of your conversio
ID: 2291003 • Letter: B
Question
B. Use the values you captured from your ADC to plot all three of your conversions in a single MATLAB graph by following these steps 1. Save your.txt in the same folder as your MATLAB code. Delete the Os at the beginning of the file. 2. Write a m script to open and read the text file line by line into a variable using the fopen) and fscan) functions Now plot the variable using the plot function, Remember that every third value in your file belongs to the same conversion. In other words, each ADC sample has been converted to a 4- bit sample, a 7-bit sample and a 10-bit sample and written in that order. Then the next sample has been written the same way. T ollows 3. he syntax for reading and plotting every third value is as plot (A (1:3:end)(1023/X a A is the variable to which the txt values were stored. b. 1 corresponds to the first value of the text file. To plot starting with the second value, replace, 1 with 2 c' .3' mean plot every third value d. end means follow this pattern until the end of the text [data) file. e. (1023/x) is the scaling factor where X-2"-1 for the n-bit conversion. This scaling factor will allow all three conversions to be plotted on the same scale so that you can compare the quality of the three analog to digital conversions Maximum of 10-bit values Maximum of n-bit values Scaling Factor- f. Make each conversion plot a different color & Label your X and Y axes and label your plot using the Matlab Legend function h. Your final graph should look similar to the one in Figure 8.5. ig85- MATLAB plot compering4-bit, 7-bit and 1D-bR ADC quantized output welues C. Answer the following o your answers with yourExplanation / Answer
Save the code as a.m file and save LP.txt file in the same folder where m-file is kept.
Don't forget to Hit LIKE....
Matlab Code:
%%===================================================
fp = fopen('LP.txt','r');
A = fscanf(fp,'%d');
fclose(fp);
%----------------------------
X = 4^2 -1;
plot(A(1:3:end)*(1023/X))
hold on
X = 7^2 -1;
plot(A(1:3:end)*(1023/X))
hold on
X = 10^2 -1;
plot(A(1:3:end)*(1023/X))
xlabel 'Time Seriese Data'
ylabel 'Potentiometer Reading (scale:0-1023)'
legend ('No levels 16','no of levels 128','no of levels 1024','Location','northwest');
title 'Matlab plot comparing 4 bit, 7 bit, 10 bit ADC quantized output'
grid on
%===========================================================
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.