Skip to content

Commit cc0c083

Browse files
committed
band rms
1 parent 08feb28 commit cc0c083

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

sigpro/aggregations/frequency/band.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency):
7+
78
"""Compute the mean values for a specific band.
89
910
Filter between a high and low band and compute the mean value for this specific band.
@@ -22,9 +23,46 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency):
2223
float:
2324
Mean value for the given band.
2425
"""
26+
2527
lower_frequency_than = frequency_values <= max_frequency
2628
higher_frequency_than = frequency_values >= min_frequency
2729
selected_idx = np.where(higher_frequency_than & lower_frequency_than)
2830
selected_values = amplitude_values[selected_idx]
2931

3032
return np.mean(selected_values)
33+
34+
35+
36+
def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency):
37+
38+
"""Compute the rms values for a specific band.
39+
40+
Filter between a high and low band (inclusive) and compute the rms value for this
41+
specific band.
42+
43+
Args:
44+
amplitude_values (np.ndarray):
45+
A numpy array with the signal values.
46+
frequency_values (np.ndarray):
47+
A numpy array with the frequency values.
48+
min_frequency (int or float):
49+
Band minimum.
50+
max_frequency (int or float):
51+
Band maximum.
52+
53+
Returns:
54+
float:
55+
rms value for the given band.
56+
"""
57+
58+
lower_frequency_than = frequency_values <= max_frequency
59+
higher_frequency_than = frequency_values >= min_frequency
60+
61+
selected_idx = np.ravel(np.where(np.ravel(higher_frequency_than & lower_frequency_than)))
62+
63+
selected_idx = [int(x) for x in selected_idx]
64+
65+
selected_values = np.array(amplitude_values)[selected_idx]
66+
67+
return np.sqrt(np.mean(np.square(selected_values)))
68+

sigpro/basic_primitives.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,22 @@ def __init__(self, min_frequency, max_frequency):
177177
'min_frequency': min_frequency, 'max_frequency': max_frequency})
178178
self.set_fixed_hyperparameters({'min_frequency': {'type': 'float'},
179179
'max_frequency': {'type': 'float'}})
180+
181+
class BandRMS(primitive.FrequencyAggregation):
182+
"""
183+
BandMean primitive class.
184+
185+
Filters between a high and low band and compute the mean value for this specific band.
186+
187+
Args:
188+
min_frequency (int or float):
189+
Band minimum.
190+
max_frequency (int or float):
191+
Band maximum.
192+
"""
193+
194+
def __init__(self, min_frequency, max_frequency):
195+
super().__init__('sigpro.aggregations.frequency.band.band_rms', init_params={
196+
'min_frequency': min_frequency, 'max_frequency': max_frequency})
197+
self.set_fixed_hyperparameters({'min_frequency': {'type': 'float'},
198+
'max_frequency': {'type': 'float'}})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "sigpro.aggregations.frequency.band.band_rms",
3+
"primitive": "sigpro.aggregations.frequency.band.band_rms",
4+
"classifiers": {
5+
"type": "aggregation",
6+
"subtype": "frequency"
7+
},
8+
"produce": {
9+
"args": [
10+
{
11+
"name": "amplitude_values",
12+
"type": "numpy.ndarray"
13+
},
14+
{
15+
"name": "frequency_values",
16+
"type": "numpy.ndarray"
17+
}
18+
],
19+
"output": [
20+
{
21+
"name": "value",
22+
"type": "float"
23+
}
24+
]
25+
},
26+
"hyperparameters": {
27+
"fixed": {
28+
"min_frequency": {
29+
"type": "float"
30+
},
31+
"max_frequency": {
32+
"type": "float"
33+
}
34+
},
35+
"tunable": {}
36+
}
37+
}

0 commit comments

Comments
 (0)