def __init__(self,plugin): self.connection = sqlite.connect(config.DATABASE) self.cursor = self.connection.cursor() self.plugin = plugin self.coeff = sg_filter.calc_coeff(config.LISSAGE_NUM_POINTS,config.LISSAGE_COEFF) self.speed = False self.real_data = []
(step, t) = find_min_delta(time) end_time = time[len(time)-1] while t <= end_time: itime.append(t) t = t + step icompounds = [] # linear piecewise interpolation for c in compounds: icompounds.append(arrayfns.interp(c, time, itime)) compounds = icompounds time = itime if smoothing: ############ smoothing (Savitzky-Golay) ############ ### TODO choose between sg_filter and savitzky_golay coeff = sg_filter.calc_coeff(6,3) smoothed_compounds = [] for i in range(len(compounds)): #smoothed_compounds.append(sg_filter.smooth(compounds[i], coeff)) smoothed_compounds.append(savitzky_golay(compounds[i])) ############ derivative ############ coeff = sg_filter.calc_coeff(6,3,1) smoothed_dcompounds = [] for i in range(len(compounds)): smoothed_dcompounds.append(sg_filter.smooth(compounds[i], coeff)) #smoothed_dcompounds.append(deriv(compounds[i], time)) if plot: plot_figs('smoothed.png', time, \ compounds=compounds, \ smoothed_compounds=smoothed_compounds, \ smoothed_derivative_of_compounds=smoothed_dcompounds\
def smooth(signal): """ Smoothing a signal using the Savitzky–Golay filter. """ coeff = sg_filter.calc_coeff(len(signal)/500, 5) return sg_filter.smooth(signal, coeff)
# generate chirp signal tvec = arange(0, 6.28, .02) signal = sin(tvec*(2.0+tvec)) # add noise to signal noise = random.normal(size=signal.shape) signal += (2000.+.15 * noise) # plot signal subplot(311) plot(signal) title('signal') # smooth and plot signal subplot(312) coeff = calc_coeff(8, 4) s_signal = smooth(signal, coeff) plot(s_signal) title('smoothed signal') # smooth derivative of signal and plot it subplot(313) coeff = calc_coeff(8, 1, 1) d_signal = smooth(signal, coeff) plot(d_signal) title('smoothed derivative of signal') # show plot savefig("savitzky.png")