def fit(self): """ Fitting data in self.t, self.v with a damped oscillation model """ # fitting is performed by eyemath (aka em) thanks to # scipy.optimize, and the error function defined by # the module eyemath (line 92): # p[0] * sin(2*pi*p[1]*x+p[2]) * exp(-p[4]*x) - p[3] # so the vector of parameters is: # amplitude, frequency, phase, DC average, damping factor. yfit, plsq = em.fit_dsine(self.t, self.v, mode="Hz") # display the fitting model msg="{0:4.2f}*sin(2*pi*{1:4.2f}*t+({2:3.1f}))*exp(-{4:4.2f}*t)+{3:3.1f}".format( *plsq ) self.ui.fitEdit.setText(msg) # display three curves : model and model's envelopes t=np.array(self.t) f1=np.array(yfit) f2=plsq[0]*np.exp(-plsq[4]*t) f3=-1.0*f2 average=plsq[3]*np.ones(len(t)) red=QtGui.QColor("#ff0000") self.fitCurve1.setPen(red) self.fitCurve2.setPen(red) self.fitCurve3.setPen(red) self.fitCurve1.setData(t, f1, len(t)) self.fitCurve2.setData(t, f2+average, len(t)) self.fitCurve3.setData(t, f3+average, len(t)) return
def fit_curve(self): fa = eyemath.fit_dsine(self.tv[0], self.tv[1], mode="Hz") if fa != None: pa = fa[1] g.line(self.tv[0], fa[0],1) self.msg(_('Angular velocity = %5.2f rad/sec. Damping Factor = %5.3f')%(pa[1], pa[4])) else: self.msg(_('Failed to fit data'))
def fit_curve(): global data, trial s = _('Fit Failed') fa = eyemath.fit_dsine(data[0], data[1],1) if fa != None: #print fa[1] pa = fa[1] rc = 1.0 / pa[1] damping = pa[4] / (2*math.pi*pa[1]) # unitless damping factor s = _('Resonant Frequency = %5.2f kHz Damping = %5.3f')%(pa[1], damping) g.line(data[0],fa[0],trial) msgwin.config(text = s)