def extractAxisFeature(dfData, 
                       strDataName, 
                       strCol, 
                       dSamplingFreq, 
                       nReponses,
                       nSegmentPerRespsonse, 
                       dVibrationDuration,
                       dIntervalDuration,
                       dRestDuration,
                       nFreqLowCut=20, 
                       nFreqHighCut=120):
    """
        Extract feature for single-axis data as follows:
        1. divide this data into multiple responses;
        2. divide each response into several segments;
        3. extract features from all segment;
        4. combine all features together;
        
        Parameters:
        ----
        dfData: 
            the data frame
        strDataName:
            name of data
        strCol: 
            axis name
        dSamplingFreq: 
            sampling frequency of data
        nResponse: 
            number of responses in single-axis data
        nSegmentPerRespsonse: 
            number of excitation segment per response
        dVibrationDuration: 
            duration of vibration (seconds)
        dIntervalDuration: 
            interval duration btw segments (seconds)
        dRestDuration: 
            the static duration btw responses
        nFreqLowCut: 
            the low cutting frequency of bandpass filter
        nFreqHighCut: 
            the high cutting frequency of bandpass filter 
        
        Returns:
        ----
        dcResponseFeature: 
            a dict of key-value pairs like: 
                     {'r1': {
                             'x0_s1_std': 0.85, 
                             'y0_s5_min': 4.72,
                             ...
                             }
                     }
    """
    arrData = dfData[strCol].values
    
    # bandpass filter to select spectrum of interest
    arrFiltered = bp_filter.butter_bandpass_filter(arrData, 
                                                   lowcut=nFreqLowCut,
                                                   highcut=nFreqHighCut,
                                                   fs=dSamplingFreq,
                                                   order=7)
                         
    # find reponses & segements in each response
    lsResponses, arrResponseEndIndex, \
    arrLocalPeakRefVal = sd.splitData(arrFiltered, 
                                      dSamplingFreq, 
                                      nReponses,
                                      nSegmentPerRespsonse,
                                      dVibrationDuration,
                                      dIntervalDuration,
                                      dRestDuration)
                                     
    dcResponseFeature = {}
    for nRespID, lsSegments in enumerate(lsResponses):
        dcFeaturePerResponse = dcResponseFeature.get( \
            "%s_r%d"% (strDataName, nRespID), None)
        if(dcFeaturePerResponse == None):
            dcFeaturePerResponse = {}
            dcResponseFeature["%s_r%d"% (strDataName, nRespID)] = \
                dcFeaturePerResponse
    
        for nSegID, (nSegStart, nSegEnd) in enumerate(lsSegments):
            arrSeg = arrFiltered[nSegStart:nSegEnd]
            dcSegFeatures = extractSegmentFeatures(strCol, nSegID, arrSeg)
            dcFeaturePerResponse.update(dcSegFeatures)
            
    return dcResponseFeature
Exemple #2
0
    bPlotRawData = True
    bPlotSegmentLine = True
    bPlotModulus = True
    
    lsColors = lsRGB*60
#    lsColors = ['#65737e']*3
    
    nRows= len(lsAxis2Inspect)+1 if bPlotModulus else len(lsAxis2Inspect)
    nCols = 2 if bPlotRawData is True else 1
    fig, axes = plt.subplots(nrows=nRows, ncols=nCols, squeeze=False)
    
    lsResponses, arrResponseEndIndex, arrBandwidthSTD = None, None, None
    for i, col in enumerate(lsAxis2Inspect):
        arrData = dfData[col].values
        arrFiltered = bp_filter.butter_bandpass_filter(arrData, lowcut=20,
                                                       highcut=130,
                                                       fs=dSamplingFreq,
                                                       order=10)
        axes[i%nRows, 0].plot(arrFiltered, color=lsColors[i])
        axes[i%nRows, 0].set_xlabel("%s_filtered" % col)
#        axes[i%nRows, 0].set_ylim(-700, 700)
        
        
        # plot raw data
        if(bPlotRawData is True):
            axes[i%nRows, 1].plot(arrData, color=lsColors[i])
            axes[i%nRows, 1].set_xlabel(col)
            
        # plot segement lines
        if(bPlotSegmentLine is True):
            lsResponses, arrResponseEndIndex, \
            arrBandwidthSTD = splitData(arrFiltered,
Exemple #3
0
    nRows = len(lsAxis2Inspect)
    nCols = len(lsFileNames)
    nFigWidth, nFigHeight = plt.figaspect(4.0/3.0)
    fig, axes = plt.subplots(nrows=nRows, ncols=nCols, 
                             squeeze=False, sharex=True,
                             sharey=True, 
                             figsize=(nFigWidth, nFigHeight) )
    
    for nDataID, strFileName in enumerate(lsFileNames):
        dfData = sd.loadData(strWorkingDir, strFileName, lsColumnNames)

        for nColID, strCol in enumerate(lsAxis2Inspect):
            arrData = dfData[strCol].values
            arrFiltered = bp_filter.butter_bandpass_filter(arrData,
                                                           lowcut=20,
                                                           highcut=120,
                                                           fs=dSamplingFreq,
                                                           order=10)
            axes[nColID, nDataID].plot(arrFiltered, color=lsColors[nColID])
            axes[nColID, nDataID].set_ylim(-5000, 5000)
            axes[nColID, nDataID].set_ylabel("%s" % strCol,
                                             rotation=0,
                                             fontname=strBasicFontName,
                                             fontsize=nBasicFontSize)
            axes[nColID, nDataID].set_xlabel("Time(sec)",
                                             rotation=0,
                                             fontname=strBasicFontName,
                                             fontsize=nBasicFontSize)
            xTickLabels = axes[nColID, nDataID].xaxis.get_ticklabels()
            plt.setp(xTickLabels, fontname=strBasicFontName,
                     size=nBasicFontSize)