How to remove unwanted values from a vector on a real-time basis?

1 visualización (últimos 30 días)
Cai Chin
Cai Chin el 11 de Nov. de 2020
Comentada: Mathieu NOE el 17 de Nov. de 2020
Hi, I am using MATLAB R2020a on a MacOS. I am trying to calculate an exponentially weighted moving mean whilst simultaneously removing outlier values. In other words, I am trying to compare the exponentially weighted mean with the current sample included to the previous one and if it exceeds 1.5 times the previous value or goes below 0.5 times the previous value, I would like it to be removed whilst keeping the acceptable values in a vector 'x'.
I am using the algorithm used by the dsp.MovingAverage function for this. At the moment, I have created a while loop which goes through my input signal 'cycle_periods' and calculates the moving mean using the algorithm. It then compares it to a scalar 'mavCnd' and either keeps or removes it. A separate index 'j' is a record of the indices of the previously accepted elements. At the end of the loop, the 'tail' of outliers is removed. However, I cannot seem to be able to remove the outliers and the signal is not smoothed.
% Calculate successive weights to test how they change with different FF
% values
lambda = 0.8;
w = zeros(length(cycle_periods),1);
w(1) = 1; % initialize the weight for the first sample
for i = 2:length(cycle_periods)
w(i) = lambda*w(i - 1) + 1; % calculate the successive weights
end
% Calculate exponentially weighted moving mean manually whilst removing
% outliers in real-time
x = cycle_periods; % array for exponentially weighted means
i = 2; % index for counting through input signal
j = 2; % index for counting through accepted exponential mean values
while i <= length(cycle_periods)
mavCnd = (1 - 1/w(j))*x(j - 1) + (1/w(j))*cycle_periods(i);
if mavCnd < 1.5*(x(j - 1)) && mavCnd > 0.5*(x(j - 1)) % Identify high and low outliers
x(j) = mavCnd;
cycle_index(j) = i;
j = j + 1;
end
i = i + 1;
end
% Scrap the tail
x(j - 1:end)=[];
% Indices of valid and invalid elements
idxCycle = [1:length(cycle_periods)];
cycle_periods(cycle_index) % List of valid points
cycle_periods(idxCycle(~ismember(idxCycle, cycle_index))); % List of removed outliers
I would very much appreciate any help with this. Thanks in advance
  1 comentario
Mathieu NOE
Mathieu NOE el 17 de Nov. de 2020
hello
so nobody here to help ? i'll give it a try if you still need assistance
do you have some data to test the code ?
tx

Iniciar sesión para comentar.

Respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by