signal_preprocessing/preprocess.py
def band_pass_filter(data_df, sampling_rate, bp_cutoff, order, channels=['X', 'Y', 'Z']):
    '''
    Band-pass filter a given sensor signal.

    :param data_df: dataframe housing sensor signals
    :param sampling_rate: sampling rate of signal
    :param bp_cutoff: filter cutoffs
    :param order: filter order
    :param channels: channels of signal to filter
    :return: dataframe of raw and filtered data
    '''
    data = data_df[channels].values

    # Calculate the critical frequency (radians/sample) based on cutoff frequency (Hz) and sampling rate (Hz)
    critical_frequency = [bp_cutoff[0]* 2.0 / sampling_rate, bp_cutoff[1]* 2.0 / sampling_rate]

    # Get the numerator (b) and denominator (a) of the IIR filter
    [b, a] = signal.butter(N=order, Wn=critical_frequency, btype='bandpass', analog=False)

    # Apply filter to raw data
    bp_filtered_data = signal.filtfilt(b, a, data, padlen=10, axis=0)

    new_channel_labels = [ax + '_bp_filt_' + str(bp_cutoff) for ax in channels]

    data_df[new_channel_labels] = pd.DataFrame(bp_filtered_data)

    return data_df

    Band-pass filter a given sensor signal.

    :param data_df: dataframe housing sensor signals
    :param sampling_rate: sampling rate of signal
    :param bp_cutoff: filter cutoffs
    :param order: filter order
    :param channels: channels of signal to filter
    :return: dataframe of raw and filtered data
    
Band-pass filter a given sensor signal.
Band - pass filter a given sensor signal .
def band_pass_filter(data_df, sampling_rate, bp_cutoff, order, channels=['X', 'Y', 'Z']):
    data = data_df[channels].values
    critical_frequency = [bp_cutoff[0]* 2.0 / sampling_rate, bp_cutoff[1]* 2.0 / sampling_rate]
    [b, a] = signal.butter(N=order, Wn=critical_frequency, btype='bandpass', analog=False)
    bp_filtered_data = signal.filtfilt(b, a, data, padlen=10, axis=0)
    new_channel_labels = [ax + '_bp_filt_' + str(bp_cutoff) for ax in channels]
    data_df[new_channel_labels] = pd.DataFrame(bp_filtered_data)
    return data_df
def band_pass_filter ( data_df , sampling_rate , bp_cutoff , order , channels = [ 'X' , 'Y' , 'Z' ] ) : data = data_df [ channels ] . values critical_frequency = [ bp_cutoff [ 0 ] * 2.0 / sampling_rate , bp_cutoff [ 1 ] * 2.0 / sampling_rate ] [ b , a ] = signal . butter ( N = order , Wn = critical_frequency , btype = 'bandpass' , analog = False ) bp_filtered_data = signal . filtfilt ( b , a , data , padlen = 10 , axis = 0 ) new_channel_labels = [ ax + '_bp_filt_' + str ( bp_cutoff ) for ax in channels ] data_df [ new_channel_labels ] = pd . DataFrame ( bp_filtered_data ) return data_df
Band-pass filter a given sensor signal.
Band - pass filter a given sensor signal .
'''
    Band-pass filter a given sensor signal.

    :param data_df: dataframe housing sensor signals
    :param sampling_rate: sampling rate of signal
    :param bp_cutoff: filter cutoffs
    :param order: filter order
    :param channels: channels of signal to filter
    :return: dataframe of raw and filtered data
    ''' # Calculate the critical frequency (radians/sample) based on cutoff frequency (Hz) and sampling rate (Hz) # Get the numerator (b) and denominator (a) of the IIR filter # Apply filter to raw data
dataframe of raw and filtered data
dataframe of raw and filtered data
data_df
dataframe housing sensor signals
dataframe housing sensor signals
sampling_rate
sampling rate of signal
sampling rate of signal
bp_cutoff
None
order
None
channels
channels of signal to filter
channels of signal to filter