Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Band rms #61

Merged
merged 6 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {}
}
}
Loading