saftig.filtering.lms¶
Least Mean Squares filter
Classes¶
LMS filter implementation |
Functions¶
|
Module Contents¶
- saftig.filtering.lms._lms_loop(witness, target, n_filter, idx_target, filter_state, normalized, step_scale, coefficient_clipping)¶
- Parameters:
witness (numpy.typing.NDArray) –
target (numpy.typing.NDArray) –
n_filter (int) –
idx_target (int) –
filter_state (numpy.typing.NDArray) –
normalized (bool) –
step_scale (float) –
coefficient_clipping (float) –
- Return type:
tuple[numpy.typing.NDArray, numpy.typing.NDArray, int, int]
- class saftig.filtering.lms.LMSFilter(n_filter, idx_target, n_channel=1, normalized=True, step_scale=0.1, coefficient_clipping=np.nan)¶
Bases:
saftig.filtering.common.FilterBaseLMS filter implementation
- Parameters:
n_filter (int) – Length of the FIR filter (how many samples are in the input window per output sample)
idx_target (int) – Position of the prediction
n_channel (int) – Number of witness sensor channels
normalized (bool) – if True: NLMS, else LMS
coefficient_clipping (float) – If set to a positive float, FIR filter coefficients will be limited to this value. This can increase filter stability.
step_scale (float) – the learning rate of the LMS filter
>>> import saftig as sg >>> n_filter = 128 >>> witness, target = sg.evaluation.TestDataGenerator(0.1).generate(int(1e5)) >>> filt = sg.filtering.LMSFilter(n_filter, 0, 1) >>> filt.condition(witness, target) >>> prediction = filt.apply(witness, target) # check on the data used for conditioning >>> residual_rms = sg.evaluation.rms(target-prediction) >>> residual_rms > 0.05 and residual_rms < 0.15 # the expected RMS in this test scenario is 0.1 True
- filter_state: numpy.typing.NDArray¶
- normalized: bool¶
- step_scale: float¶
- coefficient_clipping: float¶
- filter_name: str = 'LMS'¶
- reset()¶
reset the filter coefficients to zero
- condition(witness, target)¶
Use an input dataset to condition the filter
- Parameters:
witness (collections.abc.Sequence | numpy.typing.NDArray) – Witness sensor data
target (collections.abc.Sequence | numpy.typing.NDArray) – Target sensor data
- Return type:
None
- condition_multi_sequence(witness, target)¶
Similar to condition(), but expects multiple sequences
- Parameters:
witness (collections.abc.Sequence | collections.abc.Sequence[collections.abc.Sequence] | numpy.typing.NDArray) –
target (collections.abc.Sequence | numpy.typing.NDArray) –
- Return type:
None
- apply(witness, target=None, pad=True, update_state=False)¶
Apply the filter to input data
- Parameters:
witness (collections.abc.Sequence | numpy.typing.NDArray) – Witness sensor data
target (collections.abc.Sequence | numpy.typing.NDArray | None) – Target sensor data (is ignored)
pad (bool) – if True, apply padding zeros so that the length matches the target signal
update_state (bool) – if True, the filter state will be changed. If false, the filter state will remain
- Returns:
prediction
- Return type:
numpy.typing.NDArray
- apply_multi_sequence(witness, target=None, pad=True, update_state=False)¶
Apply the filter to input data
Similar to apply() but expects multiple sequences.
- Parameters:
witness (collections.abc.Sequence | numpy.typing.NDArray) –
target (collections.abc.Sequence | numpy.typing.NDArray | None) –
pad (bool) –
update_state (bool) –
- Return type:
collections.abc.Sequence[numpy.typing.NDArray]