-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
75 lines (52 loc) · 1.5 KB
/
utils.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import numpy as np
import feature_extraction
from scipy.fftpack import fft
def mean_feature(data):
return np.mean(data)
def std(data):
return np.std(data)
def median(data):
return np.median(data)
def crossing_rate(data):
change = 0
pos = data[0] >= 0
for i in range(1, len(data)):
if data[i] < 0 and pos==True:
change += 1
pos = False
elif data[i] > 0 and pos==False:
change += 1
pos = True
return change
def max_abs(data):
return np.max(np.absolute(data))
def min_abs(data):
return np.min(np.absolute(data))
def max_raw(data):
return np.max(data)
def min_raw(data):
return np.min(data)
def spectral_centroid(data):
fft_magnitude = abs(fft(data))
sampling_rate = 40
lt = feature_extraction.spectral_centroid_spread(fft_magnitude, sampling_rate)
return lt[0]
def spectral_spread(data):
fft_magnitude = abs(fft(data))
sampling_rate = 40
lt = feature_extraction.spectral_centroid_spread(fft_magnitude, sampling_rate)
return lt[1]
def spectral_entropy_freq(data):
n_short_blocks = 1
return feature_extraction.spectral_entropy(abs(fft(data)), n_short_blocks)
def spectral_entropy_time(data):
n_short_blocks = 1
return feature_extraction.spectral_entropy(data, n_short_blocks)
def spectral_flux(data, prev_data):
return feature_extraction.spectral_flux(abs(fft(data)), abs(fft(prev_data)))
def spectral_rolloff(data):
return feature_extraction.spectral_rolloff(data, 0.9)
def max_freq(data):
return (np.max(abs(fft(data))))
def rms(data):
return np.sqrt(np.mean(data ** 2))