Chapter 4 Analog to Digital and Digital to Analog converters

Example 1 Page No: 4.38

In [1]:
#given
z='0101';
n=4;
vof=15;#volt
#determine v0
r=vof/(pow(2,n)-1);
v0=r*int(z,2);#output voltage
print 'output voltage ',round(v0,3),'volt';
output voltage  5.0 volt

Example 2 Page No: 4.38

In [2]:
#given
r=20e-3;
z='11000000';
n=8;
#determine output voltage output offset voltage
vof=r*(pow(2,n)-1);#output offsetvoltage
v0=r*int(z,2);#output voltage
print 'output offset ',round(vof,3),'volt';
print 'output voltage ',round(v0,3),'volt';
output offset  5.1 volt
output voltage  3.84 volt

Example 3 Page No: 4.38

In [2]:
#given
n=4;
import numpy as np
z=np.array(['0111','1111']);
vref=5;#volt
#determine v0
r=vref*pow(10,3)/(pow(2,n)-1)
i=0;
while i<2 : v0=r*int(z[i],2); print'output voltage ',z[i],' = ',round(v0),'milivolt';i=i+1;
output voltage  0111  =  2331.0 milivolt
output voltage  1111  =  4995.0 milivolt

Example 4 Page No: 4.39

In [5]:
#given
n=12;
r=8e-3;#volt
z='011101110001';
#determine output voltage
vof=r*pow(2,n)-1;
v0=r*int(z,2);#output voltage
r=r*1e2/vof;
print'full scale output voltage',round(vof,2),'volt';
print'Resolution',round(r,2),'%';
print'output voltage ',round(v0,3),'volt';
full scale output voltage 31.77 volt
Resolution 0.03 %
output voltage  15.24 volt

Example 5 Page No: 4.39

In [12]:
#given
fs=1e3;#hz
r=0.01;
vref=10;#volt
#determine n vmin rms fs1 t1 z
r=0.01/100;
n=14;
print'minumum number of bits ',pow(2,14);
vm=vref*pow(10,6)/pow(2,n);#minmum voltage
print'minmum voltage         ',round(vm),'μvolt';
import math
eq=vref/(pow(2,n)*2*math.sqrt(3));#quantization error
print'quantization error     ',round(eq*pow(10,6)),'μvolt';
fs1=5*fs;#sampling rate
print'sampling rate          ',fs1/1e3,'Khz';
t1=1/(2*3.14*fs*pow(2,n));#aperture time
print'aperture time          ',round(t1*pow(10,6),3),'μsecond';#error in book
print'converter              ',6*n,'dB';
minumum number of bits  16384
minmum voltage          610.0 μvolt
quantization error      176.0 μvolt
sampling rate           5.0 Khz
aperture time           0.01 μsecond
converter               84 dB

Example 6 Page No: 4.40

In [8]:
#given
vref=10;#volt
Is=1.875e-3;#A
#determine R I
n=4;
v0=vref*pow(10,3)/pow(2,n)*(1*pow(2,(n-1))+1*pow(2,(n-2))+1*pow(2,(n-3))+1*pow(2,(n-4)));
r=v0/((Is)*pow(10,6));
print'R = ',round(r,3),' Kohm';
v0=vref*pow(10,3)/pow(2,n)*(1*pow(2,(n-1))+1*pow(2,(n-2)));
print'I at 1100 = ',round(v0/pow(10,3)/r,3),'mA';
R =  5.0  Kohm
I at 1100 =  1.4 mA

Example 7 Page No: 4.41

In [9]:
#given
vmin=1e-3;#volt
vref=10;#volt
q=0.01;
#determine n
import math
n=math.log10(((0.5)/0.01)+1)/math.log10(2);
print'N= ',round(n);
N=  6.0

Example 8 Page No: 4.42

In [15]:
#given
n=8;
#determine R
r=1*100e0/(pow(2,n)-1);
print'R in percent ',round(r,3),'%';
R in percent  0.392 %

Example 9 Page No: 4.42

In [12]:
#given
n=5;
#determine resolution
r=1*100/(pow(2,n)-1);#Resolution
print'Resolution in percent ',round(r,3),'%';
Resolution in percent  3.0 %

Example 10 Page No: 4.42

In [17]:
#given
import numpy as np
z=np.array(['111111','100110']);
vref1=20;#volt
#determine output voltage
e=1*pow(10,3)/int(z[0],2)*vref1;#minimum voltage
print'minimum voltage each bit ',round(e,3),'milivolt';
e=int(z[1],2)*1e0/int(z[0],2)*vref1;#output voltage
print'output voltage at ',z[1],' = ',round(e,3),'volt';
minimum voltage each bit  300.0 milivolt
output voltage at  100110  =  12.063 volt

Example 11 Page No: 4.42

In [22]:
#given
import math
n=12;
vref1=50e0;#volt
vref2=-50e0;#volt
#determine Resolution
r=float((vref1-vref2)/(pow(2,n)-(1)));
print'Resolution ',round(r,2),'volt';
r=1*1e2/(pow(2,n)-(1));
print'Resolution in percent ',round(r,3),'%';
Resolution  0.02 volt
Resolution in percent  0.024 %

Example 12 Page No: 4.43

In [21]:
#given
n=10e0;
vref1=-10e0;#volt
vref2=10e0;#volt
#determine Resolution 
r=(vref2-vref1)/(pow(2,n)-(1));#Resolution
print'Resolution ',round(r*1e3,2),'milivolt';
r=100/(pow(2,n)-(1));
print'Resolution in percent ',round(r,3),'%';
Resolution  19.55 milivolt
Resolution in percent  0.098 %

Example 13 Page No: 4.43

In [30]:
#given
n=12e0;
#determine Resolution 
r=1/(pow(2,n)-(1));
r=r*100;#Resolution
print'Resolution in percent ',round(r,3),'%';
Resolution in percent  0.024 %

Example 14 Page No: 4.44

In [20]:
#given
n=7;
vmax=25.4;#volt
#determine voltage 
r=1*pow(10,3)/(pow(2,n)-1);
print'change in voltage ',round(r*vmax),'milivolt';
change in voltage  178.0 milivolt

Example 15 Page No: 4.44

In [21]:
#given
r=5e-3;#volt
vref=8;#volt 
#determine N
import math
n=math.log10(1/(r/vref)+(1))/math.log10(2);
print'N =',round(n);
N = 11.0

Example 16 Page No: 4.44

In [22]:
#given
fs=1e6;#hz
n=8;
#determine conversion time
tc=(1/fs)*(n+1);
print'conversion time = ',round(tc*pow(10,6),(3)),'μs';
conversion time =  9.0 μs

Example 17 Page No: 4.45

In [23]:
#given
vref=10;#volt
vin=100e-3;#volt
#determine output voltage
v0=vref*vin/pow(10,-3);#output voltage
print'output voltage ',round(v0),'volt';
output voltage  1000.0 volt

Example 18 Page No: 4.45

In [24]:
#given
n=4;
z='1111';
r=10e3;#ohm
r1=20e3;#ohm
vref=10;#volt
#determine Resolution output current
r=((1)*pow(10,6)/pow(2,n))*vref/r;#Resolution
print'Resolution of 1th ',round(r,3),'μA';
iout=r*int(z,2);#Output current
print'Output current ',round(iout,3),'μA';#error in book
Resolution of 1th  62.5 μA
Output current  937.5 μA

Example 19 Page No: 4.45

In [25]:
#given
n=8;
vref=10;#volt
#determine input voltage
vmin=vref*pow(10,3)/pow(2,n);#minimum input voltage
print'minimum input voltage ',round(vmin,3),'milivolt';
vif=vref-vmin/pow(10,3);#input voltage
print'input voltage at 1s ',round(vif,3),'volt';
vin=5.2;
D=vin/vmin;D=133;z=bin(D);
print'decimal at ',round(vin,3),'volt = ',z;
minimum input voltage  39.0 milivolt
input voltage at 1s  10.0 volt
decimal at  5.2 volt =  0b10000101

Example 20 Page No: 4.46

In [25]:
#given
vref=10;#volt
import numpy as np
z=np.array(['01','0111','10111100']);
n=2;
#determine output voltage
v0=vref*1e0/pow(2,2);#output voltage
print'output voltage at ',z[0],' = ',round(v0,3),'volt';
n=4
v0=vref*1e0*(1*pow(10,3)/pow(2,2)+1*pow(10,3)/pow(2,3)+1*pow(10,3)/pow(2,4));#output voltage
print'output voltage at ',z[1],' = ',round(v0/pow(10,3),3),'volt';
v0=vref*(1*pow(10,3)*1e0/2+1*pow(10,3)/pow(2,3)+1*pow(10,3)/pow(2,4)+1*pow(10,3)/pow(2,5)+1*pow(10,3)/pow(2,6)+1*pow(10,3)/pow(2,8));
print'output voltage at ',z[2],' = ',round(v0/pow(10,3),3),'volt';
output voltage at  01  =  2.5 volt
output voltage at  0111  =  4.37 volt
output voltage at  10111100  =  7.36 volt

Example 21 Page No: 4.46

In [23]:
#given
n=4;
z='0110';
vref=10e0;
#determine output voltage
v0=vref*(1*pow(10,3)/pow(2,2)+1*pow(10,3)/pow(2,3));#output voltage
print'output voltage at ',z,' = ',round(v0/pow(10,3),3),'volt';
output voltage at  0110  =  3.75 volt

Example 22 Page No: 4.47

In [26]:
#given
n=10;
vfs=10.24;#volt
distortion=56;#dB
#determine ENOB SNRmax
import math
q=vfs/(pow(2,n)*math.sqrt(12));
snrmax=(6.02*n+1.76);
print'SNRmax = ',round(snrmax,3),'dB';
en=(distortion-1.76)/6.02;
print'ENOB = ',round(en);
SNRmax =  61.96 dB
ENOB =  9.0