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

조회 수: 3 (최근 30일)
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
riccardo
riccardo 2020년 11월 9일
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

댓글을 달려면 로그인하십시오.

채택된 답변

riccardo
riccardo 2020년 11월 9일
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
riccardo
riccardo 2020년 11월 24일
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 2020년 11월 24일
Hi riccardo, I was wondering how this extrapolation could be done in code?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by