saftig.filtering.polylms¶
experiment in building a polynomial lms filter
Classes¶
Experimental non-linear LMS-like filter implementation |
Functions¶
|
Run an LMS filter over intput sequences. |
Module Contents¶
- saftig.filtering.polylms._lms_loop(witness, target, n_filter, idx_target, filter_state, normalized, step_scale, coefficient_clipping, order)¶
Run an LMS filter over intput sequences.
- Parameters:
witness (numpy.typing.NDArray) – Witness sensor data
target (numpy.typing.NDArray) – Target sensor data (is ignored)
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
filter_state (numpy.typing.NDArray) – The initial FIR filter state
normalized (bool) – if True: NLMS, else LMS
step_scale (float) – the learning rate of the LMS filter
n_channel – Number of witness sensor channels
order (int) – polynomial order of the filter
pad – if True, apply padding zeros so that the length matches the target signal
update_state – if True, the filter state will be changed. If false, the filter state will remain
coefficient_clipping (float) –
- Returns:
Prediction, Filter state, Target offset, Prediction length
- Return type:
tuple[numpy.typing.NDArray, numpy.typing.NDArray, int, int]
- class saftig.filtering.polylms.PolynomialLMSFilter(n_filter, idx_target, n_channel=1, normalized=True, step_scale=0.5, coefficient_clipping=np.nan, order=1)¶
Bases:
saftig.filtering.common.FilterBaseExperimental non-linear LMS-like filter implementation Implements: \(x[n] = \sum_p\sum_i\sum_t {w_i[n-t]}^pH_{it}\) where p is the polynomial order, i the channel and t the index within the filter
- 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
step_scale (float) – The learning rate of the LMS filter
coefficient_clipping (float) – If set to a positive float, FIR filter coefficients will be limited to this value. This can increase filter stability.
order (int) – Polynomial order of the filter
>>> import saftig as sg >>> n_filter = 128 >>> witness, target = sg.evaluation.TestDataGenerator(0.1).generate(int(1e5)) >>> filt = sg.filtering.PolynomialLMSFilter(n_filter, 0, 1, step_scale=0.1, order=2, coefficient_clipping=4) >>> filt.condition(witness, target) >>> prediction = filt.apply(witness, target) # check on the data used for conditioning >>> residual_rms = sg.evaluation.rms((target-prediction)[1000:]) >>> 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¶
- order: int¶
- filter_name: str = 'PolyLMS'¶
- 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
- apply(witness, target, 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) – 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