#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';
#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';
#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;
#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';
#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';
#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';
#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);
#given
n=8;
#determine R
r=1*100e0/(pow(2,n)-1);
print'R in percent ',round(r,3),'%';
#given
n=5;
#determine resolution
r=1*100/(pow(2,n)-1);#Resolution
print'Resolution in percent ',round(r,3),'%';
#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';
#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),'%';
#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),'%';
#given
n=12e0;
#determine Resolution
r=1/(pow(2,n)-(1));
r=r*100;#Resolution
print'Resolution in percent ',round(r,3),'%';
#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';
#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);
#given
fs=1e6;#hz
n=8;
#determine conversion time
tc=(1/fs)*(n+1);
print'conversion time = ',round(tc*pow(10,6),(3)),'μs';
#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';
#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
#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;
#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';
#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';
#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);