Alex Nazarovsky

MATLAB, DSP, Julia, Power quality, Engineering, Metrology

How to Model ADC Quantization Effect With Known Maximum Voltage and Number of Bits and Apply It to a Signal in Matlab

Model ADC quantization effect
1
2
3
   Umax=1; % Set maximum voltage, for which max ADC code is reached
   bits=16; % ADC resolution 
   U=double(uencode(U,bits,Umax,'signed'))/(2^(bits-1))*(Umax);

ADC quantization demo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
t=0:1/500:1-1/500;
U=sin(2*pi*5.00*t);

Umax=1; % Set maximum voltage, for which max ADC code is reached
bits=3; % ADC resolution 
Uq=double(uencode(U,bits,Umax,'signed'))/(2^(bits-1))*(Umax);

figure;
subplot 211
plot(t,U), hold on, stem(t,Uq);
xlabel('t, s') , ylabel('Magnitude, V');
legend('U','U_{quantized}');
subplot 212
plot(t,U-Uq);
legend('Quantization Error');
xlabel('t, s') , ylabel('Magnitude, V');