classifiers/hand_movement_features.py
def calculate_amplitude_and_smoothness_features(raw_accelerometer_data_df, fs):
    '''
    Function to calculate hand movement amplitude and smoothness of hand movement (jerk metric) from accelerometer data
    collected from a wrist worn wearable device.

    :param raw_accelerometer_data_df: Pandas DataFrame of raw accelerometer data. Columns = ['ts', 'x', 'y', 'z']
    :param fs: Sampling rate of raw accelerometer data (Float)
    :return: Computed hand movement amplitude (list) and smoothness of hand movement (jerk metric) (list) in 3 second
    windows
    '''

    # Pre-process data
    # Bandpass filter between 0.25-3.5
    filtered_data_df = preprocess.band_pass_filter(raw_accelerometer_data_df, fs, [0.25, 3.5], 4,
                                        channels=['x', 'y', 'z'])
    bp_headers = ['x_bp_filt_[0.25, 3.5]', 'y_bp_filt_[0.25, 3.5]', 'z_bp_filt_[0.25, 3.5]']
    filtered_data_df = filtered_data_df[bp_headers]

    avg_acc_per_window = []
    jerk_per_window = []

    # Segment into 3 second windows
    total_samples = filtered_data_df.shape[0]
    window_samples = fs * 3.0
    total_windows = round(total_samples / float(window_samples))
    for win in range(int(total_windows)):
        current_win_start = int(window_samples * win + 1)
        current_win_end = int(current_win_start + window_samples - 1)
        if current_win_end > filtered_data_df.shape[0]:
            window_data_df = filtered_data_df.loc[current_win_start:, :]
        else:
            window_data_df = filtered_data_df.loc[current_win_start:current_win_end, :]
        window_data_df.reset_index(drop=True, inplace=True)
        window_data_df = window_data_df[bp_headers]

        # Compute Avg RMS -> Amplitude of hand movement
        window_data_df['mag'] = np.sqrt(
            (window_data_df['x_bp_filt_[0.25, 3.5]'] ** 2) + (window_data_df['y_bp_filt_[0.25, 3.5]'] ** 2) + (
            window_data_df['z_bp_filt_[0.25, 3.5]'] ** 2))
        combined_amplitude = compute_rms(window_data_df.mag.tolist())
        avg_acc_per_window.append(combined_amplitude)

        # Compute Jerk -> Smoothness of hand movement
        computed_jerk_df = sf.jerk_metric(window_data_df, fs, ['mag'])
        computed_jerk = computed_jerk_df.mag_jerk_ratio.values[0]
        jerk_per_window.append(computed_jerk)

    return avg_acc_per_window, jerk_per_window

    Function to calculate hand movement amplitude and smoothness of hand movement (jerk metric) from accelerometer data
    collected from a wrist worn wearable device.

    :param raw_accelerometer_data_df: Pandas DataFrame of raw accelerometer data. Columns = ['ts', 'x', 'y', 'z']
    :param fs: Sampling rate of raw accelerometer data (Float)
    :return: Computed hand movement amplitude (list) and smoothness of hand movement (jerk metric) (list) in 3 second
    windows
    
Function to calculate hand movement amplitude and smoothness of hand movement (jerk metric) from accelerometer data
collected from a wrist worn wearable device.
Function to calculate hand movement amplitude and smoothness of hand movement ( jerk metric ) from accelerometer data collected from a wrist worn wearable device .
def calculate_amplitude_and_smoothness_features(raw_accelerometer_data_df, fs):
    filtered_data_df = preprocess.band_pass_filter(raw_accelerometer_data_df, fs, [0.25, 3.5], 4,
                                        channels=['x', 'y', 'z'])
    bp_headers = ['x_bp_filt_[0.25, 3.5]', 'y_bp_filt_[0.25, 3.5]', 'z_bp_filt_[0.25, 3.5]']
    filtered_data_df = filtered_data_df[bp_headers]
    avg_acc_per_window = []
    jerk_per_window = []
    total_samples = filtered_data_df.shape[0]
    window_samples = fs * 3.0
    total_windows = round(total_samples / float(window_samples))
    for win in range(int(total_windows)):
        current_win_start = int(window_samples * win + 1)
        current_win_end = int(current_win_start + window_samples - 1)
        if current_win_end > filtered_data_df.shape[0]:
            window_data_df = filtered_data_df.loc[current_win_start:, :]
        else:
            window_data_df = filtered_data_df.loc[current_win_start:current_win_end, :]
        window_data_df.reset_index(drop=True, inplace=True)
        window_data_df = window_data_df[bp_headers]
        window_data_df['mag'] = np.sqrt(
            (window_data_df['x_bp_filt_[0.25, 3.5]'] ** 2) + (window_data_df['y_bp_filt_[0.25, 3.5]'] ** 2) + (
            window_data_df['z_bp_filt_[0.25, 3.5]'] ** 2))
        combined_amplitude = compute_rms(window_data_df.mag.tolist())
        avg_acc_per_window.append(combined_amplitude)
        computed_jerk_df = sf.jerk_metric(window_data_df, fs, ['mag'])
        computed_jerk = computed_jerk_df.mag_jerk_ratio.values[0]
        jerk_per_window.append(computed_jerk)
    return avg_acc_per_window, jerk_per_window
def calculate_amplitude_and_smoothness_features ( raw_accelerometer_data_df , fs ) : filtered_data_df = preprocess . band_pass_filter ( raw_accelerometer_data_df , fs , [ 0.25 , 3.5 ] , 4 , channels = [ 'x' , 'y' , 'z' ] ) bp_headers = [ 'x_bp_filt_[0.25, 3.5]' , 'y_bp_filt_[0.25, 3.5]' , 'z_bp_filt_[0.25, 3.5]' ] filtered_data_df = filtered_data_df [ bp_headers ] avg_acc_per_window = [ ] jerk_per_window = [ ] total_samples = filtered_data_df . shape [ 0 ] window_samples = fs * 3.0 total_windows = round ( total_samples / float ( window_samples ) ) for win in range ( int ( total_windows ) ) : current_win_start = int ( window_samples * win + 1 ) current_win_end = int ( current_win_start + window_samples - 1 ) if current_win_end > filtered_data_df . shape [ 0 ] : window_data_df = filtered_data_df . loc [ current_win_start : , : ] else : window_data_df = filtered_data_df . loc [ current_win_start : current_win_end , : ] window_data_df . reset_index ( drop = True , inplace = True ) window_data_df = window_data_df [ bp_headers ] window_data_df [ 'mag' ] = np . sqrt ( ( window_data_df [ 'x_bp_filt_[0.25, 3.5]' ] ** 2 ) + ( window_data_df [ 'y_bp_filt_[0.25, 3.5]' ] ** 2 ) + ( window_data_df [ 'z_bp_filt_[0.25, 3.5]' ] ** 2 ) ) combined_amplitude = compute_rms ( window_data_df . mag . tolist ( ) ) avg_acc_per_window . append ( combined_amplitude ) computed_jerk_df = sf . jerk_metric ( window_data_df , fs , [ 'mag' ] ) computed_jerk = computed_jerk_df . mag_jerk_ratio . values [ 0 ] jerk_per_window . append ( computed_jerk ) return avg_acc_per_window , jerk_per_window
Function to calculate hand movement amplitude and smoothness of hand movement (jerk metric) from accelerometer data
collected from a wrist worn wearable device.
Function to calculate hand movement amplitude and smoothness of hand movement ( jerk metric ) from accelerometer data collected from a wrist worn wearable device .
'''
    Function to calculate hand movement amplitude and smoothness of hand movement (jerk metric) from accelerometer data
    collected from a wrist worn wearable device.

    :param raw_accelerometer_data_df: Pandas DataFrame of raw accelerometer data. Columns = ['ts', 'x', 'y', 'z']
    :param fs: Sampling rate of raw accelerometer data (Float)
    :return: Computed hand movement amplitude (list) and smoothness of hand movement (jerk metric) (list) in 3 second
    windows
    ''' # Pre-process data # Bandpass filter between 0.25-3.5 # Segment into 3 second windows # Compute Avg RMS -> Amplitude of hand movement # Compute Jerk -> Smoothness of hand movement
Computed hand movement amplitude (list) and smoothness of hand movement (jerk metric) (list) in 3 second
windows
Computed hand movement amplitude ( list ) and smoothness of hand movement ( jerk metric ) ( list ) in 3 second windows
raw_accelerometer_data_df
Pandas DataFrame of raw accelerometer data.
Pandas DataFrame of raw accelerometer data .
fs
Sampling rate of raw accelerometer data (Float)
Sampling rate of raw accelerometer data ( Float )