mph- / lcapy

Lcapy is a Python package for symbolic linear circuit analysis and signal processing. It uses SymPy for symbolic mathematics.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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?

commented

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