Skip to content

Commit

Permalink
Merge pull request #61 from sintel-dev/frequency_primitive
Browse files Browse the repository at this point in the history
Band rms
  • Loading branch information
SaraPido committed May 23, 2024
2 parents e33c955 + 3e232aa commit ffb3b41
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
30 changes: 30 additions & 0 deletions sigpro/aggregations/frequency/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,33 @@ def band_mean(amplitude_values, frequency_values, min_frequency, max_frequency):
selected_values = amplitude_values[selected_idx]

return np.mean(selected_values)


def band_rms(amplitude_values, frequency_values, min_frequency, max_frequency):
"""
Compute the rms values for a specific band.
Filter between a high and low band (inclusive) and compute the rms value for this
specific band.
Args:
amplitude_values (np.ndarray):
A numpy array with the signal values.
frequency_values (np.ndarray):
A numpy array with the frequency values.
min_frequency (int or float):
Band minimum.
max_frequency (int or float):
Band maximum.
Returns:
float:
rms value for the given band.
"""
lower_frequency_than = frequency_values <= max_frequency
higher_frequency_than = frequency_values >= min_frequency

selected_idx = np.ravel(np.where(higher_frequency_than & lower_frequency_than))
selected_values = amplitude_values[selected_idx]

return np.sqrt(np.mean(np.square(selected_values)))
21 changes: 21 additions & 0 deletions sigpro/basic_primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,24 @@ def __init__(self, min_frequency, max_frequency):
'min_frequency': min_frequency, 'max_frequency': max_frequency})
self.set_fixed_hyperparameters({'min_frequency': {'type': 'float'},
'max_frequency': {'type': 'float'}})


class BandRMS(primitive.FrequencyAggregation):
"""
BandRMS primitive class.
Filter between a high and low band (inclusive) and compute the rms value for this
specific band.
Args:
min_frequency (int or float):
Band minimum.
max_frequency (int or float):
Band maximum.
"""

def __init__(self, min_frequency, max_frequency):
super().__init__('sigpro.aggregations.frequency.band.band_rms', init_params={
'min_frequency': min_frequency, 'max_frequency': max_frequency})
self.set_fixed_hyperparameters({'min_frequency': {'type': 'float'},
'max_frequency': {'type': 'float'}})
37 changes: 37 additions & 0 deletions sigpro/primitives/sigpro/aggregations/frequency/band/band_rms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "sigpro.aggregations.frequency.band.band_rms",
"primitive": "sigpro.aggregations.frequency.band.band_rms",
"classifiers": {
"type": "aggregation",
"subtype": "frequency"
},
"produce": {
"args": [
{
"name": "amplitude_values",
"type": "numpy.ndarray"
},
{
"name": "frequency_values",
"type": "numpy.ndarray"
}
],
"output": [
{
"name": "value",
"type": "float"
}
]
},
"hyperparameters": {
"fixed": {
"min_frequency": {
"type": "float"
},
"max_frequency": {
"type": "float"
}
},
"tunable": {}
}
}

0 comments on commit ffb3b41

Please sign in to comment.