<jupyter_start><jupyter_text>Note:- This notebook only process three types of experiment data which are:1. EMG measurement from three channels2. Elbow flexion / extension<jupyter_code>import os
import glob

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn

import scipy
from scipy import signal
from scipy.signal import freqz

import math

from butterworth import band_pass, low_pass, high_pass
from utils import full_wave_rectify, plot_signal_one, plot_multiple
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
xa = np.asarray(x)
vara = (1 / (len(xa) - 1)) * np.sum([s ** 2 for s in xa])
print(vara)
a = 4
print(np.sqrt(a))<jupyter_output>35.625
2.0<jupyter_text>Prepare feature extraction functions<jupyter_code>a = np.arange(10, 5831, 10)
j = 0
for i in range(len(a)):
    j += 1
print(j)
def getEMGfeatures(emg, window = 1, step = 1):
    """
    emg: filtered rectified EMG signal
    window: size of sliding windows
    step: number of step between two windows
    """
    endPt = len(emg)
    pts = np.arange(window, endPt, step)
    j = 0
    for i in range(len(pts)):
        j += 1
        sampleEMG = emg[pts[i] - window + 1:pts[i], :]
        pass
        
    
def getfeaturesTD(emg):
    pass<jupyter_output><empty_output><jupyter_text>Data Preprocessing1. Full-wave rectification2. Remove the noise from data by using Butterworth Filter3. Feature extraction4. Dimensionality Reduction (*Optional)5. Save the data as '.csv' file<jupyter_code># Setup the parameters of signal
f = 2000
# path = r'/home/jerry/GitHub/EMG_regressive_model/data_process/raw_data'
path = r'D:/GitHub/EMG_regressive_model/data_process/raw_data'
all_files = glob.glob(path+'/*.csv')
dfList = []
# Read .csv file by using panda
# for filename in all_files:
file = all_files[0]
saveName = file[-11:-4]
print(file)
allData = pd.read_csv(file, skiprows = 4, header = None)

# Create the dataframe for EMG data and Joint angle
emgData = allData.iloc[:, 3:6]
angleData = allData.iloc[:, 32:33]

#Convert the dataframe to numpy array
emg = emgData.to_numpy()
time = np.array([i/f for i in range(0, len(emg), 1)]) # sampling rate 2000 Hz
mean = np.mean(emg, axis = 0)
emgAvg = emg - mean

angle = angleData.to_numpy()

emgSize = emgAvg.shape

bpEmg = np.zeros(emgSize)

for i in range(emgSize[-1]):
    bandpass = low_pass(emgAvg[:, i],fs = f, low_pass = 600, order = 2)
    bpEmg[:, i] = bandpass


# Perform the full wave rectification
rectEmg = full_wave_rectify(bpEmg)


bpAngle = band_pass(angle, fs = f, high_band = 100, low_band = 10, order = 4, axs = -1, padB = True, pad = 0)

a = emg.shape
c = np.zeros(a)
for i in range(a[-1]):
    c[:, i] = emg[:, i]
print(type(c),'and', type(emg))
tit = ['EMG CH1', 'EMG CH2', 'EMG CH3']
filename = 'emgvstime_filter.png'
signal = [rectEmg[:, 0], rectEmg[:, 1], rectEmg[:, 2]]
t = [time, time, time]

plot_multiple(signal, t, 3, 'Time', 'EMG', tit, filename)
# Plot unfiltered EMG
rect = full_wave_rectify(emgAvg)
tit = ['EMG CH1', 'EMG CH2', 'EMG CH3']
filename = 'emgvstime_raw.png'
signal = [rect[:, 0], rect[:, 1], rect[:, 2]]
t = [time, time, time]

plot_multiple(signal, t, 3, 'Time', 'EMG', tit, filename)
row = 10
for i in range(11):
    for j in range(2):
        print(i, 'and', j)<jupyter_output>0 and 0
0 and 1
1 and 0
1 and 1
2 and 0
2 and 1
3 and 0
3 and 1
4 and 0
4 and 1
5 and 0
5 and 1
6 and 0
6 and 1
7 and 0
7 and 1
8 and 0
8 and 1
9 and 0
9 and 1
10 and 0
10 and 1
{'fraction_non_alphanumeric': 0.1317016317016317, 'fraction_numerical': 0.041666666666666664, 'mean_word_length': 3.883357041251778, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '606242', 'license': 'Apache-2.0', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1344, 'n_words': 443, 'path': 'data_process/.ipynb_checkpoints/DataPreprocess-checkpoint.ipynb', 'repo_name': 'jiruifu-jerry0219/UpperLimbEstimator', 'size': '3432'}