Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
10 changes: 5 additions & 5 deletions EDA-Artifact-Detection-Script.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

matplotlib.rcParams['ps.useafm'] = True
matplotlib.rcParams['pdf.use14corefonts'] = True
matplotlib.rcParams['text.usetex'] = True
matplotlib.rcParams['text.usetex'] = False


def getWaveletData(data):
Expand All @@ -29,7 +29,7 @@ def getWaveletData(data):

# Create wavelet dataframes
oneSecond = pd.date_range(start=startTime, periods=len(data), freq='1s')
halfSecond = pd.date_range(start=startTime, periods=len(data), freq='500L')
halfSecond = pd.date_range(start=startTime, periods=len(data), freq='500ms')

# Compute wavelets
cA_n, cD_3, cD_2, cD_1 = pywt.wavedec(data['EDA'], 'Haar', level=3) #3 = 1Hz, 2 = 2Hz, 1=4Hz
Expand Down Expand Up @@ -109,10 +109,10 @@ def getFeatures(data,w1,wH):

all_feat = np.hstack([statFeat,waveletFeat])

if np.Inf in all_feat:
if np.inf in all_feat:
print("Inf")

if np.NaN in all_feat:
if np.nan in all_feat:
print("NaN")

return list(all_feat)
Expand Down Expand Up @@ -308,7 +308,7 @@ def plotData(data,labels,classifierList,filteredPlot=0,secondsPlot=0):
plt.legend(['Raw SC','Filtered SC'],loc=0)

# Label and Title each subplot
plt.ylabel('$\mu$S')
plt.ylabel(chr(956) + "S")
plt.title(key)

# Only include x axis label on final subplot
Expand Down
16 changes: 8 additions & 8 deletions load_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _loadSingleFile_E4(filepath,list_of_columns, expected_sample_rate,freq):

# Get the startTime and sample rate
startTime = pd.to_datetime(float(data.columns.values[0]),unit="s")
sampleRate = float(data.iloc[0][0])
sampleRate = float(data.iloc[0].iloc[0])
data = data[data.index!=0]
data.index = data.index-1

Expand All @@ -116,17 +116,17 @@ def _loadSingleFile_E4(filepath,list_of_columns, expected_sample_rate,freq):

def loadData_E4(filepath):
# Load EDA data
eda_data = _loadSingleFile_E4(os.path.join(filepath,'EDA.csv'),["EDA"],4,"250L")
eda_data = _loadSingleFile_E4(os.path.join(filepath,'EDA.csv'),["EDA"],4,"250ms")
# Get the filtered data using a low-pass butterworth filter (cutoff:1hz, fs:8hz, order:6)
eda_data['filtered_eda'] = butter_lowpass_filter(eda_data['EDA'], 1.0, 8, 6)

# Load ACC data
acc_data = _loadSingleFile_E4(os.path.join(filepath,'ACC.csv'),["AccelX","AccelY","AccelZ"],32,"31250U")
acc_data = _loadSingleFile_E4(os.path.join(filepath,'ACC.csv'),["AccelX","AccelY","AccelZ"],32,"31250us")
# Scale the accelometer to +-2g
acc_data[["AccelX","AccelY","AccelZ"]] = acc_data[["AccelX","AccelY","AccelZ"]]/64.0

# Load Temperature data
temperature_data = _loadSingleFile_E4(os.path.join(filepath,'TEMP.csv'),["Temp"],4,"250L")
temperature_data = _loadSingleFile_E4(os.path.join(filepath,'TEMP.csv'),["Temp"],4,"250ms")

data = eda_data.join(acc_data, how='outer')
data = data.join(temperature_data, how='outer')
Expand Down Expand Up @@ -229,17 +229,17 @@ def interpolateDataTo8Hz(data,sample_rate,startTime):
if sample_rate<8:
# Upsample by linear interpolation
if sample_rate==2:
data.index = pd.date_range(start=startTime, periods=len(data), freq='500L')
data.index = pd.date_range(start=startTime, periods=len(data), freq='500ms')
elif sample_rate==4:
data.index = pd.date_range(start=startTime, periods=len(data), freq='250L')
data = data.resample("125L").mean()
data.index = pd.date_range(start=startTime, periods=len(data), freq='250ms')
data = data.resample("125ms").mean()
else:
if sample_rate>8:
# Downsample
idx_range = list(range(0,len(data))) # TODO: double check this one
data = data.iloc[idx_range[0::int(int(sample_rate)/8)]]
# Set the index to be 8Hz
data.index = pd.date_range(start=startTime, periods=len(data), freq='125L')
data.index = pd.date_range(start=startTime, periods=len(data), freq='125ms')

# Interpolate all empty values
data = interpolateEmptyValues(data)
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy==1.16.2
scipy==1.2.1
pandas==0.24.1
scikit-learn==0.20.3
matplotlib>=2.1.2
PyWavelets==1.0.2
numpy==2.2.0
scipy==1.14.1
pandas==2.2.3
scikit-learn==1.5.2
matplotlib>=3.9.3
PyWavelets==1.8.0