-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime_domain_features.py
58 lines (48 loc) · 1.19 KB
/
time_domain_features.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
from math import sqrt
from sklearn.metrics import mean_squared_error
import numpy as np
import scipy.stats as ss
def root_mean_square(data):
"""
Calculates root mean squared value of a given data
Parameters
----------
data : array_like
array of data to get root mean squared value from
Returns:
-------
rms : float
root mean squared value of the data
"""
data = np.square(data)
rms = sqrt(np.mean(data))
return rms
def energy(data):
"""
Calculate energy of a data set over a time domain
Parameters
----------
data : array like
array of data need to get energy from
Returns
-------
energy : float
energy of time domain data
"""
data = np.sum(np.square(np.abs(data)))
return data
def average_power(data):
"""Function that calculates average power of an array of data
Parameters
----------
data : array like
array of data of interest, to evaluate average power
Returns
-------
avg_power : float
numerical value of average power
"""
num = len(data)
data = energy(data)
avg_power = data/num
return avg_power