How to remove outliers from exponentially weighted moving mean in real-time?

3 Ansichten (letzte 30 Tage)
I am using MATLAB R2020a on a MacOS. I am calculating an exponentially weighted moving mean using the dsp.MovingAverage function and am trying to remove vector elements in real-time based on 2 conditions - if the new element causes the mean to exceed 1.5 times the 'overall' mean so far, or if it is below 0.5 times the 'overall' mean so far.
In other words, the weighted mean with the current element is compared to the previous weighted mean, and if the current element causes the weighted mean to increase above 1.5 times the previous mean or go below 0.5 times the previous mean, then it should be ignored and the recursive equation is instead applied to the next element, and so on. In the end, I'd like to have a vector containing the outliers removed.
This is the function I am using to calculate the exponentially weighted moving mean:
movavgExp = dsp.MovingAverage('Method', 'Exponential weighting', 'ForgettingFactor', 0.4);
mean_cycle_period_exp = movavgExp(cycle_period_step_change);
I would very much appreciate any suggestions on how to tackle this, thanks in advance!
  1 Kommentar
riccardo
riccardo am 9 Nov. 2020
I haven't had time to check the calcs, but the error is likely due to a zero-indexing conditions in the loop:
>> for i = 2:lenght....
.....
if x(i) > 1.5*(1 - 1/w(i - 1))* >>x(i - 2)<< + (1/w(i - 1))*x(i - 1)
i-2 = 0 at the start

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

riccardo
riccardo am 9 Nov. 2020
I am not sure what you ar eaiming at, here:
>>
% Calculate moving mean with weights manually
x = zeros(length(cycle_period_step_change), 1);
x(1) = 2;
>>
"x" is an array of zeros, with a leading "2".
The plot you've shown is just the consequence of it, with a smooth transition from 2 -> 0, due to the averaging. Am I missing something ?
  24 Kommentare
riccardo
riccardo am 24 Nov. 2020
In RT you cannot interpolate, but you could try extrapolating a "candidate outlier" point using the gradient based on the last 2 accepted average values.
The problem arise when you find several adjacent/consecutive outliers: in this case the latest 2 acceptable values may be "too far back".
Cai Chin
Cai Chin am 24 Nov. 2020
Hi riccardo, I was wondering how this extrapolation could be done in code?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by