Value Discretization
georg-imms opened this issue · comments
Hey,
is there a possibility to value-discretize a signal as with an adc? Did anyone try something like this before?
Lcapy does not do this since it is symbolic. However, here is a function I use:
def adc(v, Nbits=8, Vrefmin=-0.5, Vrefmax=0.5, bipolar=False):
levels = 2**Nbits
dV = (Vrefmax - Vrefmin) / levels
v = np.array(v)
ml = v < Vrefmin
v[ml] = Vrefmin
mu = v > Vrefmax - dV
v[mu] = Vrefmax - dV
q = ((v - Vrefmin) / dV).astype(int)
if bipolar:
q -= levels // 2
return q