Beispiel #1
0
    # check for / read command line arguments
    if len(sys.argv) == 2:
        fname = sys.argv[1]
    else:
        fname = "Wellenform.csv"
    print('\n*==* script ' + sys.argv[0]+ ' executing \n',\
        '     processing file ' + fname)

    # read data from PicoScope
    units, data = ppk.readPicoScope(fname, prlevel=2)
    t = data[0]
    a = data[1]

    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)))
Beispiel #2
0
    #phi=ppk.meanFilter(phi_c, width=10) #

    # * use, if sampling rate is too high
    if len(phi) > 2000:
        print("  resampling")
        phi, t = ppk.resample(phi, t, n=int(len(phi) /
                                            1000))  # average n samples into 1

# numerical differentiation with numpy
    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:
#Create Array of differences of Maximums
deltaMax = deltaArray(maxac)
deltaMin = deltaArray(minac)

print(deltaMax)
print(deltaMin)
deltaMin = (-1)*deltaMin
deltaNew = deltaMin + deltaMax

# plot data as histogram
nbin = 10
binc, bine, patches = plt.hist(deltaNew, nbin,facecolor='g', log=False, alpha=1)
plt.title("Histogramm of MaxDifferences")
plt.show()

#Calculate Period and Uncertainity from Histogram data
Perioddata = PhyPraKit.histstat(binc, bine, patches)
print("Period by amplitude alone = " + str(Perioddata[0]))
print("?? = "  + str(Perioddata[1]))
print("Uncertainity = " + str(Perioddata[2]))
print("True Period in s = " + str(Perioddata[0]/0.05555555555))
print("True Uncertantiy = " + str(Perioddata[2]/0.05555555555))

#Stelle Frequenz Spektrum dar
fourierspec = PhyPraKit.FourierSpectrum(time,smoothamplitude)
plt.plot(fourierspec[0],fourierspec[1])
plt.title("Frequenz Spektrum des Signals")
print('Frequency by Fourier Analysis = ' +str(findMaximumxPos(*fourierspec)))
plt.show()