-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess.py
More file actions
48 lines (45 loc) · 1.7 KB
/
preprocess.py
File metadata and controls
48 lines (45 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import matplotlib.pyplot as plt
from sklearn import preprocessing as prep
import pandas as pd
import numpy as np
def normalisasi(df):
kolom = list(df.columns)
kolom.remove('class')
kolom.remove('time')
#normalisasi data
scaler = prep.MinMaxScaler(feature_range=(-1,1))
# scaler = prep.StandardScaler()
rescale = np.abs(scaler.fit_transform(df[kolom]))
newdata = pd.DataFrame(rescale, columns=kolom)
newdata = pd.concat([df[['time','class']],newdata],axis=1)
return newdata
def butter_low_pass(df):
from scipy import signal
kolom = list(df.columns)
kolom.remove('class')
kolom.remove('time')
dataFilter = {}
for i in range(len(kolom)):
fs = 1000 #frekuensi sampling 1 kHz
nyqs = 0.5 * fs
fcut = 5 #frekuensi cut off 5 Hz
normal_fcut = fcut/nyqs
b,a = signal.butter(4, normal_fcut, btype="low", analog=False)
yfilter = signal.filtfilt(b,a,df[kolom[i]])
dataFilter[kolom[i]]= yfilter.T
return pd.concat([df[['time','class']],pd.DataFrame(dataFilter, columns = kolom)], axis=1)
def butter_high_pass(df):
from scipy import signal
kolom = list(df.columns)
kolom.remove('class')
kolom.remove('time')
dataFilter = {}
for i in range(len(kolom)):
fs = 1000 #frekuensi sampling 1 kHz
nyqs = 0.5 * fs
fcut = 5 #frekuensi cut off 5 Hz
normal_fcut = fcut/nyqs
b,a = signal.butter(4, normal_fcut, btype="high", analog=False)
yfilter = signal.filtfilt(b,a,df[kolom[i]])
dataFilter[kolom[i]]= yfilter.T
return pd.concat([df[['time','class']],pd.DataFrame(dataFilter, columns = kolom)], axis=1)