classifiers/resting_tremor_amplitude_classifier.py
def calculate_tremor_amplitude(raw_accelerometer_data_df, fs):
    '''
    Calculate tremor amplitude from raw accelerometer data collected from wearable sensor at wrist location.
    :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 tremor amplitude in 3 second windows (list)
    '''

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

    tremor_amplitudes_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 Tremor Amplitude
        window_data_df['mag'] = np.sqrt((window_data_df['x_bp_filt_[3.5, 7.5]']**2)+(window_data_df['y_bp_filt_[3.5, 7.5]']**2)+(window_data_df['z_bp_filt_[3.5, 7.5]']**2))
        combined_amplitude = compute_rms(window_data_df.mag.tolist())
        tremor_amplitudes_per_window.append(combined_amplitude)

    return tremor_amplitudes_per_window

    Calculate tremor amplitude from raw accelerometer data collected from wearable sensor at wrist location.
    :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 tremor amplitude in 3 second windows (list)
    
Calculate tremor amplitude from raw accelerometer data collected from wearable sensor at wrist location.
Calculate tremor amplitude from raw accelerometer data collected from wearable sensor at wrist location .
def calculate_tremor_amplitude(raw_accelerometer_data_df, fs):
    filtered_data_df = preprocess.band_pass_filter(raw_accelerometer_data_df, fs, [3.5, 7.5], 3,
                                                             channels=['x', 'y', 'z'])
    bp_headers = ['x_bp_filt_[3.5, 7.5]', 'y_bp_filt_[3.5, 7.5]', 'z_bp_filt_[3.5, 7.5]']
    filtered_data_df = filtered_data_df[bp_headers]
    tremor_amplitudes_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_[3.5, 7.5]']**2)+(window_data_df['y_bp_filt_[3.5, 7.5]']**2)+(window_data_df['z_bp_filt_[3.5, 7.5]']**2))
        combined_amplitude = compute_rms(window_data_df.mag.tolist())
        tremor_amplitudes_per_window.append(combined_amplitude)
    return tremor_amplitudes_per_window
def calculate_tremor_amplitude ( raw_accelerometer_data_df , fs ) : filtered_data_df = preprocess . band_pass_filter ( raw_accelerometer_data_df , fs , [ 3.5 , 7.5 ] , 3 , channels = [ 'x' , 'y' , 'z' ] ) bp_headers = [ 'x_bp_filt_[3.5, 7.5]' , 'y_bp_filt_[3.5, 7.5]' , 'z_bp_filt_[3.5, 7.5]' ] filtered_data_df = filtered_data_df [ bp_headers ] tremor_amplitudes_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_[3.5, 7.5]' ] ** 2 ) + ( window_data_df [ 'y_bp_filt_[3.5, 7.5]' ] ** 2 ) + ( window_data_df [ 'z_bp_filt_[3.5, 7.5]' ] ** 2 ) ) combined_amplitude = compute_rms ( window_data_df . mag . tolist ( ) ) tremor_amplitudes_per_window . append ( combined_amplitude ) return tremor_amplitudes_per_window
Calculate tremor amplitude from raw accelerometer data collected from wearable sensor at wrist location.
Calculate tremor amplitude from raw accelerometer data collected from wearable sensor at wrist location .
'''
    Calculate tremor amplitude from raw accelerometer data collected from wearable sensor at wrist location.
    :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 tremor amplitude in 3 second windows (list)
    ''' # Pre-process data # Bandpass filter between 3.5-7.5 # Segment into 3 second windows # Compute Tremor Amplitude
Computed tremor amplitude in 3 second windows (list)
Computed tremor amplitude in 3 second windows ( list )
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 )