Exemplo n.º 1
0
def find_fft(rawdata, peakindexes):
    global FFT, FFT_PkI, FFT_Pfreq, xf, N, f1, Pwelch
    FFT = []
    Pwelch = []
    FFT_PkI = []
    FFT_Pfreq = []
    preImpact = 150
    postImpact = 200
    sampfeq = 500
    # Take the fft of each impact on a single channel
    for ff in range(len(peakindexes)):
        fftdata = rawdata[peakindexes[ff] - preImpact:peakindexes[ff] +
                          postImpact]
        fft_rData = fft(fftdata)
        N = len(fft_rData)
        #Power Spectral Analysis using Welch method
        f1, Pwelch_spec = welch(fftdata,
                                sampfeq,
                                nperseg=200,
                                scaling='spectrum')

        # Set the length of the X vector to half of the original time vector
        xf = np.linspace(0.0, sampfeq / 2, N / 2)

        # Find peaks in FFT data
        fftpkI = detect_peaks(abs(fft_rData[0:int(N / 2)]),
                              mpd=3,
                              edge='rising')
        fftpkI = list(fftpkI)
        Pwelch.insert(ii, Pwelch_spec)
        FFT.insert(ii, fft_rData)
        FFT_PkI.append(fftpkI[0:numFreq])
        FFT_Pfreq.extend(xf[fftpkI[0:1]])
    while(index < len(millis)):
        time.append(interval * index)
        index += 1
      
    averageVoltage = np.mean(impact_data[0:50])
    adjusted_raw = [x - averageVoltage for x in impact_data]
    adjusted_smoothed = [x - averageVoltage for x in smoothed_data]
    
    #%%Analyze the data...!
    #peak voltage, total voltage displacement

    total_voltage_displacement = 0;
    for volt in adjusted_raw:
        total_voltage_displacement += abs(volt)
    total_voltage_displacement = round(total_voltage_displacement, 2)
    peaks = detect_peaks(smoothed_data)
    valleys = detect_peaks(smoothed_data, valley='true')
    
    
    max_peak = 0
    min_peak = 5
    max_peak_index = 0
    min_peak_index = 0
    for peak in peaks:
        if smoothed_data[peak] > max_peak:
            max_peak = smoothed_data[peak]
            max_peak_index = peak
    
    for valley in valleys:
        if smoothed_data[valley] < min_peak:
            min_peak = smoothed_data[valley]
Exemplo n.º 3
0
                    thresh = .002
            if ii == 20:
                Mthresh = .002
                if kk == 1:
                    Mthresh = .001
                    minpkdis = 100
            if ii == 5: Mthresh = .05
            if ii == 8 and kk == 2: Mthresh = .22
            if ii == 10 and kk == 1: Mthresh = .25
            if ii == 16 and kk == 2: Mthresh = .05
            if ii == 12 and kk == 4: Mthresh = .2
            if ii == 11 and kk == 2: Mthresh = .15

            # Find Peaks in signal
            pkI = detect_peaks(fData[ii, 0:int(samples[ii]), kk + 4],
                               mpd=300,
                               mph=thresh,
                               edge='rising')
            ind = remove_too_close(pkI)

            # Once again used to remove unwanted peaks
            if len(ind) > int(expectedPeaks):
                ind = ind[0:int(expectedPeaks)]
            reading = list(fData[ii, ind, kk + 4])
            absInteg, Integ, ToPeakInt = peak_integral(
                fData[ii, 0:int(samples[ii]), kk + 4], ind)

            # Find the FFT and Power Spectral Analysis of the data
            find_fft(rData[ii, 0:int(samples[ii]), kk + 4], ind)

            #            print('Test ' + str(ii) + ' Channel ' + str(kk))
            FFT = np.array(FFT)
Exemplo n.º 4
0
#        thresh = .002
#    if ii == 20:
#        Mthresh = .002
#        if kk == 1:
#            Mthresh = .001
#            minpkdis = 100
#    if ii == 5: Mthresh = .05
#    if ii == 8 and kk == 2: Mthresh = .22
#    if ii == 10 and kk == 1: Mthresh = .25
#    if ii == 16 and kk == 2: Mthresh = .05
#    if ii == 12 and kk == 4: Mthresh = .2
#    if ii == 11 and kk == 2: Mthresh = .15


    # Find Peaks in signal
    pkI = detect_peaks(rData[ii, 0:3000, 1], mpd=300, mph=thresh, edge='rising')
    ind = remove_too_close(pkI)

    # Once again used to remove unwanted peaks
    if len(ind) > int(expectedPeaks):
        ind = ind[0:int(expectedPeaks)]
    #reading = list(fData[ii, ind, 1])
    reading = list(rData[ii, ind, 1])
    #absInteg, Integ, ToPeakInt = peak_integral(rData[ii, 0:3000, 1], ind)

    # Find the FFT and Power Spectral Analysis of the data
    find_fft(rData[ii, 0:3000, 1], ind)

#            print('Test ' + str(ii) + ' Channel ' + str(kk))
    FFT = np.array(FFT)
    FFT_PkI = np.array(FFT_PkI)