Skip to content

Commit ffb3b41

Browse files
authored
Merge pull request #61 from sintel-dev/frequency_primitive
Band rms
2 parents e33c955 + 3e232aa commit ffb3b41

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

sigpro/aggregations/frequency/band.py

+30
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,33 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency):
2828
selected_values = amplitude_values[selected_idx]
2929

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

sigpro/basic_primitives.py

+21
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,24 @@ 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+
182+
class BandRMS(primitive.FrequencyAggregation):
183+
"""
184+
BandRMS primitive class.
185+
186+
Filter between a high and low band (inclusive) and compute the rms value for this
187+
specific band.
188+
189+
Args:
190+
min_frequency (int or float):
191+
Band minimum.
192+
max_frequency (int or float):
193+
Band maximum.
194+
"""
195+
196+
def __init__(self, min_frequency, max_frequency):
197+
super().__init__('sigpro.aggregations.frequency.band.band_rms', init_params={
198+
'min_frequency': min_frequency, 'max_frequency': max_frequency})
199+
self.set_fixed_hyperparameters({'min_frequency': {'type': 'float'},
200+
'max_frequency': {'type': 'float'}})
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)