def calculate_beta(m, vcc): col = ColsProxy(m) col.Ab = uarray((col.Ab, 1)) col.Ac = uarray((col.Ac, 1)) col.Ub = an2v(col.Ab, vcc) col.Uc = an2v(col.Ac, vcc) Rout = 20 pnp = col.polarity == 'PNP' npn = col.polarity == 'NPN' col.Urb[pnp] = col.Ub[pnp] col.Urb[npn] = vcc - col.Ub[npn] col.Urc[pnp] = col.Uc[pnp] col.Urc[npn] = vcc - col.Uc[npn] col.Ib = col.Urb / (col.Rb + Rout) col.Ic = col.Urc / (col.Rc + Rout) col.Ie = col.Ib + col.Ic col.beta = col.Ic / col.Ib[nominal_values(col.Ib) != 0] col.Ue[pnp] = vcc - (Rout * col.Ie[pnp]) col.Ue[npn] = Rout * col.Ie[npn] col.Ube[pnp] = -(col.Ub[pnp] - col.Ue[pnp]) col.Ube[npn] = (col.Ub[npn] - col.Ue[npn])
def calculate_beta(m, vcc): col = ColsProxy(m) col.Ab=uarray((col.Ab,1)) col.Ac=uarray((col.Ac,1)) col.Ub = an2v(col.Ab, vcc) col.Uc = an2v(col.Ac, vcc) Rout = 20 pnp = col.polarity == 'PNP' npn = col.polarity == 'NPN' col.Urb[pnp] = col.Ub[pnp] col.Urb[npn] = vcc - col.Ub[npn] col.Urc[pnp] = col.Uc[pnp] col.Urc[npn] = vcc - col.Uc[npn] col.Ib = col.Urb / (col.Rb + Rout) col.Ic = col.Urc / (col.Rc + Rout) col.Ie = col.Ib + col.Ic col.beta = col.Ic / col.Ib[nominal_values(col.Ib) != 0] col.Ue[pnp] = vcc - (Rout * col.Ie[pnp]) col.Ue[npn] = Rout * col.Ie[npn] col.Ube[pnp] = -(col.Ub[pnp] - col.Ue[pnp]) col.Ube[npn] = (col.Ub[npn] - col.Ue[npn])
def extend(data): # dw = DataWrapper(data) data.measurements = filter_measurements(data.measurements, ['pwm_value', 'rail'], ['Aout', 'Ain', 'Aamp']) # print 111,unbunchify(dw.data) # print 222,(dw.data) R = data.config.R vcc = data.vcc # def calc(x): # x.Vin = an2v(x.Ain, vcc) # x.Vout = an2v(x.Aout, vcc) # x.Vamp = an2v(x.Aamp, vcc) # x.Vx = x.Vout - x.Vin # x.I = (x.Vin - x.Vamp) / R data.Vmax = data.vcc data.Imax = data.vcc / R # ls=[] # pwm_current=0 # for x in dw.data.measurements: # # group by pwm_value # x.pwm_value==pwm_current: # ls.append(x) # else: # calc(x) # ls=[] # pwm_current=x.pwm_value d = groupped_measurements(data.measurements, ['pwm_value', 'rail']) for p in range(256): for r in [0, 1]: ls = d[p, r] # ls = [x for x in dw.data.measurements if x.pwm_value == p and x.rail == # r] if not len(ls): continue Ain = ls[0].Ain Aout = ls[0].Aout Aamp = ls[0].Aamp Vin = an2v(Ain, vcc) Vout = an2v(Aout, vcc) Vamp = an2v(Aamp, vcc) Vx = Vout - Vin I = (Vin - Vamp) / R for x in ls: x.I = I x.Vx = Vx x.Vin = Vin x.Vout = Vout x.Vamp = Vamp
def extend(data): m = filter_measurements(data.measurements, ['Dout', 'pwm_value'], ['Aout', 'Aamp']) R = data.config.R vcc = data.vcc m['Vout'] = an2v(m.Aout, vcc) m['Vamp'] = an2v(m.Aamp, vcc) m['I'] = (m.Vout - m.Vamp) / R m['Iabs'] = abs(m.I) data.measurements = m
def extend(data): # dw = DataWrapper(data) data.measurements = filter_measurements( data.measurements, ['pwm_value', 'rail'], ['Aout', 'Ain', 'Aamp']) # print 111,unbunchify(dw.data) # print 222,(dw.data) R = data.config.R vcc = data.vcc # def calc(x): # x.Vin = an2v(x.Ain, vcc) # x.Vout = an2v(x.Aout, vcc) # x.Vamp = an2v(x.Aamp, vcc) # x.Vx = x.Vout - x.Vin # x.I = (x.Vin - x.Vamp) / R data.Vmax = data.vcc data.Imax = data.vcc / R # ls=[] # pwm_current=0 # for x in dw.data.measurements: # # group by pwm_value # x.pwm_value==pwm_current: # ls.append(x) # else: # calc(x) # ls=[] # pwm_current=x.pwm_value d = groupped_measurements(data.measurements, ['pwm_value', 'rail']) for p in range(256): for r in [0, 1]: ls = d[p, r] # ls = [x for x in dw.data.measurements if x.pwm_value == p and x.rail == # r] if not len(ls): continue Ain = ls[0].Ain Aout = ls[0].Aout Aamp = ls[0].Aamp Vin = an2v(Ain, vcc) Vout = an2v(Aout, vcc) Vamp = an2v(Aamp, vcc) Vx = Vout - Vin I = (Vin - Vamp) / R for x in ls: x.I = I x.Vx = Vx x.Vin = Vin x.Vout = Vout x.Vamp = Vamp
def transfer_plot(data, fig, error_plot=False): data.measurements = filter_measurements(data.measurements, ['pwm_value'], ['Ain']) title = 'Transfer error plot (%s)' if error_plot else 'Transfer plot (%s)' title = title % (data.model) fw = FigureWrapper( data, fig, x='voltage', y='error (V)' if error_plot else 'voltage', title=title, ) vcc = data.vcc fw.addcol( legend=data.config.pin_in, x=lambda e: pwm2v(e.pwm_value, vcc), y=lambda e: an2v(e.Ain, vcc) - (pwm2v(e.pwm_value, vcc) if error_plot else 0), ) ax = fw.subplot if error_plot: ax.axis([0, 5.1, -0.050, 0.050]) return fig
def transfer_plot(data, fig, error_plot=False): data.measurements = filter_measurements(data.measurements, ['value'], ['Ain']) title = 'Transfer error plot' if error_plot else 'Transfer plot' title = title fw = FigureWrapper( data, fig, x='voltage', y='error (V)' if error_plot else 'voltage', title=title, ) vcc = data.vcc if error_plot: fw.subplot.plot([0, vcc], [vcc / 99, vcc / 99], 'r-') fw.subplot.plot([0, vcc], [-vcc / 99, -vcc / 99], 'r-') else: fw.subplot.plot([0, 0], [vcc, vcc], 'r-') fw.addcol( legend=data.config.pin_in, x=lambda e: pot2v(e.value, vcc), y=lambda e: an2v(e.Ain, vcc) - (pot2v(e.value, vcc) if error_plot else 0), ) ax = fw.subplot if error_plot: ax.axis([0, 5.1, -0.1, 0.1]) return fig
def extend(data): m = filter_measurements( data.measurements, ['Dout', 'pwm_value'], ['Aout', 'Aamp'] ) R = data.config.R vcc = data.vcc m['Vout'] = an2v(m.Aout, vcc) m['Vamp'] = an2v(m.Aamp, vcc) m['I'] = (m.Vout - m.Vamp) / R m['Iabs'] = abs(m.I) data.measurements = m
def calculate_ohm(data, Vnull, Ain): vcc = data.vcc # print 'calibration', calibration Vin = an2v(Ain, vcc) # Ain, Vin = maxi(ls, vcc) R1 = data.config.R1 R2 = data.config.R2 Ramp1 = data.config.Ramp1 Ramp2 = data.config.Ramp2 # def perc1(x): # return ufloat((x, x * 0.01)) Rout = 24 # R1 = perc1(R1) + ufloat((Rout, Rout * 0.1)) # R2 = perc1(R2) R1 = R1 + Rout # Ramp1 = perc1(Ramp1) # Ramp2 = perc1(Ramp2) A = Ramp2 / Ramp1 Vgen = R2 / (R2 + R1) * vcc Rgen = R1 * R2 / (R1 + R2) # print R2, Vgen, Rgen, vcc, R1 Vampout = Vin Vampout_pp = 2 * (Vampout - Vnull) Vampin_pp = Vampout_pp / A divider = (Vampin_pp / Vgen) def calc_Rx(cal): return Rgen / (1 - divider / cal) - Rgen Rx_raw = calc_Rx(1) calibration_open = Vampin_pp / Vgen # calibration = 0.93 # Rx_cal = calc_Rx(calibration) # def calibration_x(x): # return divider / (1 - (Rgen / (x + Rgen))) # print 555, calibration_x(1.8) Rx = Rx_raw # print 'Rx_raw,Rx_cal', Rx_raw, Rx_cal # if Rx > 30: # Rx = None return Rx, calibration_open
def analyse(data): m = data.measurements vcc = data.vcc stats = m.Ain.describe() count = stats['count'] Amean = stats['mean'] Amin = stats['min'] Amax = stats['max'] Arange = Amax - Amin Amiddle = (Amin + Amax) / 2 duty_cycle = len(m.Ain[m.Ain > Amiddle]) / len(m.Ain) Astd = stats['std'] Arms = (Astd ** 2 + Amean ** 2) ** 0.5 return dict( count=count, Amin=Amin, Amax=Amax, Arange=Arange, Amean=Amean, duty_cycle=duty_cycle, Astd=Astd, Arms=Arms, Vmean=an2v(Amean, vcc), Vstd=an2v(Astd, vcc), Vrms=an2v(Arms, vcc), Vmin=an2v(Amin, vcc), Vmax=an2v(Amax, vcc), Vrange=an2v(Arange, vcc), )
def extend(data): m = filter_measurements( data.measurements, ['pwm_value', 'rail'], ['Aout', 'Ain', 'Aamp']) R = data.config.R vcc = data.vcc data.Vmax = data.vcc data.Imax = data.vcc / R col = ColsProxy(m) col.Vin = an2v(col.Ain, vcc) col.Vout = an2v(col.Aout, vcc) col.Vamp = an2v(col.Aamp, vcc) col.Vx = col.Vout - col.Vin col.I = (col.Vin - col.Vamp) / R m = m.sort_index(by='Vx') col.I = pandas.rolling_median(col.I, window=5) data.measurements = m
def addcol(self, x=None, y=None, legend=None, lineformat=None, filter_func=None, sortbyx=None): ax = self.subplot if x and not callable(x): ax.set_xlabel(x) else: if self.x == 'time': x = 't' if not x: x = self.x if not lineformat: lineformat = '-o' if not callable(y): if not legend: legend = y if self.convert2voltage and self.y == 'analog_value': f2 = lambda e: an2v(e[y], self.data['vcc']) else: f2 = y xcol = self._col(x, filter_func=filter_func) ycol = self._col(f2, filter_func=filter_func) if sortbyx: ls = sorted(zip(xcol, ycol), key=lambda e: e[0]) xcol = [e[0] for e in ls] ycol = [e[1] for e in ls] assert len(xcol) == len(ycol) assert len(xcol) assert len(ycol) ax.plot(nominal_values(xcol), nominal_values(ycol), lineformat, label=legend) self.update_legend()
def addcol(self, x=None, y=None, legend=None, lineformat=None, filter_func=None, sortbyx=None): ax = self.subplot if x and not callable(x): ax.set_xlabel(x) else: if self.x == 'time': x = 't' if not x: x = self.x if not lineformat: lineformat = '-o' if not callable(y): if not legend: legend = y if self.convert2voltage and self.y == 'analog_value': f2 = lambda e: an2v(e[y], self.data['vcc']) else: f2 = y xcol = self._col(x, filter_func=filter_func) ycol = self._col(f2, filter_func=filter_func) if sortbyx: ls = sorted(zip(xcol, ycol), key=lambda e: e[0]) xcol = [e[0] for e in ls] ycol = [e[1] for e in ls] assert len(xcol) == len(ycol) assert len(xcol) assert len(ycol) ax.plot( nominal_values(xcol), nominal_values(ycol), lineformat, label=legend) self.update_legend()
def transfer_plot(data, fig, error_plot=False): data.measurements = filter_measurements( data.measurements, ['pwm_value'], ['Ain']) title = 'Transfer error plot (%s)' if error_plot else 'Transfer plot (%s)' title = title % (data.model) fw = FigureWrapper( data, fig, x='voltage', y='error (V)' if error_plot else 'voltage', title=title, ) vcc = data.vcc fw.addcol(legend=data.config.pin_in, x=lambda e: pwm2v(e.pwm_value, vcc), y=lambda e: an2v( e.Ain, vcc) - (pwm2v(e.pwm_value, vcc) if error_plot else 0), ) ax = fw.subplot if error_plot: ax.axis([0, 5.1, -0.050, 0.050]) return fig
def transfer_plot(data, fig, error_plot=False): data.measurements = filter_measurements(data.measurements, ["value"], ["Ain"]) title = "Transfer error plot" if error_plot else "Transfer plot" title = title fw = FigureWrapper(data, fig, x="voltage", y="error (V)" if error_plot else "voltage", title=title) vcc = data.vcc if error_plot: fw.subplot.plot([0, vcc], [vcc / 99, vcc / 99], "r-") fw.subplot.plot([0, vcc], [-vcc / 99, -vcc / 99], "r-") else: fw.subplot.plot([0, 0], [vcc, vcc], "r-") fw.addcol( legend=data.config.pin_in, x=lambda e: pot2v(e.value, vcc), y=lambda e: an2v(e.Ain, vcc) - (pot2v(e.value, vcc) if error_plot else 0), ) ax = fw.subplot if error_plot: ax.axis([0, 5.1, -0.1, 0.1]) return fig
def avgAV(df, vcc): a = averaged_median_arr(df.Ain) Ain = ufloat((a, 1)) Vin = an2v(Ain, vcc) return Ain, Vin