print("** Fourier Spectrum") freq, amp = ppk.FourierSpectrum(t, a, fmax=20) # freq, amp = ppk.Fourier_fft(t, a) # use fast algorithm frequency = freq[np.where(amp == max(amp))] print(" --> Frequenz mit max. Amplitude: ", frequency) # calculate autocorrelation function print("** Autocorrelation Function") ac_a = ppk.autocorrelate(a) ac_t = t - t[0] # run peak finder width = 80 # use convoluted template filter pidx = ppk.convolutionPeakfinder(ac_a, width, th=0.4) if len(pidx) > 3: print(" --> %i auto-correlation peaks found" % (len(pidx))) pidx[0] = 0 # first peak is at 0 by construction tp, ap = np.array(ac_t[pidx]), np.array(ac_a[pidx]) else: print("*!!* not enough peaks found - tune peakfinder parameters!") sys.exit(1) # Filter peaks and dips: keep only largest ones # !!! need inspection by eye to ensure correct peaks are identified tpm = [] apm = [] for i, ti in enumerate(tp): if ap[i] > 0.137: tpm.append(tp[i])
print("** numerical derivative") dt = t[1] - t[0] omega = np.gradient(phi, dt) # calculate fourier spectrum print("** Fourier Spectrum") freq, amp = ppk.FourierSpectrum(t, phi, fmax=1.) # freq, amp = ppk.Fourier_fft(t, phi) # fast algorithm frequency = freq[np.where(amp == max(amp))] print(" --> Frequenz: ", frequency) # run a peak finder # first, determine width of typical peaks and dips width = 0.5 * len(t) / (t[-1] - t[0]) / frequency # use convoluted template filter peakind = ppk.convolutionPeakfinder(phi, width, th=0.53) dipind = ppk.convolutionPeakfinder(-phi, width, th=0.53) if len(peakind) > 5: print(" --> %i peaks and %i dips found" % (len(peakind), len(dipind))) tp, phip = np.array(t[peakind]), np.array(phi[peakind]) td, phid = np.array(t[dipind]), np.array(phi[dipind]) else: print("*!!* not enough peaks found for envelope fit") print(" tune peakfinder parameters!") sys.exit(1) # cubic spline interpolation with scipy.interpolate print("** spline interpolation") cs_phi = interpolate.UnivariateSpline(t, phi, s=0) cs_omega = cs_phi.derivative()
#Bestimmung von T ___________________________________________________________________________ hlines, data = ppk.readCSV('HandyPendel.csv') t = data[0] a = data[2] #Glätten der Funktion a_smooth = ppk.meanFilter(a, 7) # calculate autocorrelation function ac_a = ppk.autocorrelate(a_smooth) ac_t = t # find maxima and minima using convolution peak finder width = 3 pidxac = ppk.convolutionPeakfinder(ac_a, width, th=0.66) didxac = ppk.convolutionPeakfinder(-ac_a, width, th=0.66) if len(pidxac) > 1: print(" --> %i auto-correlation peaks found" % (len(pidxac))) pidxac[0] = 0 # first peak is at 0 by construction ac_tp, ac_ap = np.array(ac_t[pidxac]), np.array(ac_a[pidxac]) ac_td, ac_ad = np.array(ac_t[didxac]), np.array(ac_a[didxac]) else: print("*!!* not enough correlation peaks found") #Plot erstellen fig = plt.figure(1, figsize=(7.5, 10)) fig.subplots_adjust(left=0.14, bottom=0.1, right=0.97, top=0.93,