Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

B. Use the values you captured from your ADC to plot all three of your conversio

ID: 2291004 • 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 a4 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. The syntax for reading and plotting every third value is as follows: 3. 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 Scaling FactorMaximum of n-bit values f. g. h. Make each conversion plot a different color Label your X and Y axes and label your plot using the Matlab Legend function. Your final graph should look similar to the one in Figure 8.5

Explanation / Answer

Save the code as a.m file and save LP.txt file in the same folder where m-file is kept.

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

%===========================================================