How can I use this adc code to convert analog to digital ?

조회 수: 11 (최근 30일)
Tim Yeh
Tim Yeh 2016년 3월 8일
댓글: Walter Roberson 2023년 3월 30일
function [d,dcode]=adc(a,b,c,code_table)
% Analog-to-Digital Conversion
% Input : analog signal a, boundary vector b, centroid vector c,
% and code_table
% Output: quantized samples d and the corresponding code dcode
N=length(c);
if nargin<4, code_table=[0:N-1]'; end
Na=length(a); % dcode=zeros(Na,size(code_table,2));
for n=1:Na
I=find(a(n)<b(2:N));
if ~isempty(I), d(n)=c(I(1)); dcode(n,:)=code_table(I(1),:);
else d(n)=c(N); dcode(n,:)=code_table(N,:);
end
end
The MATLAB programs in "MATLAB/Simulink for Digital Communication" authored by Won Y. Yang et. al
Analog signal a, I know that is my input signal.
But I can't realize what does boundary vector b, centroid vector c, and code_table means.
Can someone help me, best wish have example.
Thanks for your patience.

답변 (1개)

Walter Roberson
Walter Roberson 2020년 11월 13일
The first input is a vector of voltage readings.
The readings would already have to have been converted to digital form from their original voltage or resistance or capacitance or whatever. This code do not communicate with hardware at any level. It does not, for example, talk to an Analog To Digital Converter.
The second input is an ascending list of boundary conditions. Any input value that is between b(K) and b(K+1) will be associated with bin #K.
The third input is a list of nominal values that is to be associated with each bin. For example you might have configured a boundary at 3.11 and the next boundary at 3.17, and you could configure the corresponding replacement value for readings in the range to be pi.
Note that the boundaries do not need to be equally spaced, and the replacement values do not need to be equally spaced. The replacement values in c do not even need to be real valued or sorted (but the inputs need to be real valued and the edges need to be real and sorted.
The last input is a column vector or 2d array of code values. If the input is determined to be between edge K and K+1, then the corresponding row of the second output is set to the content of row K of the fourth input. You could, for example, use this to convert input voltages into grey codes.
  댓글 수: 4
abdul
abdul 2023년 3월 30일
편집: abdul 2023년 3월 30일
can you give an example keeping real ADC in mind
Walter Roberson
Walter Roberson 2023년 3월 30일
b = [-inf 0:.1:10];
c = [0 edges(2:end)+.5];
This would be for the case where you wanted to map all negative voltages to 0, and otherwise use voltage bins 1/10 V wide from 0 to 10 volts, but you wanted to output the center of each of those bins (for example if you were wanting to do a histogram, you might want to center the bar for each bin at the center of the bin.)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Signal Generation, Manipulation, and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by