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

8 次查看(过去 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