-1

I have a matrix of measurements:

A=[x1,y1;x2,y2;x3,y3]

and my device had some interferences, so i want to delete measurements (rows) that are above 10 times the average between the neighboring points (the average y values).

example:

if A=[1,1; 2,300; 3,2; 4;4]

in this case, i want to delete the second row (it's clearly an anomaly).

Thank you

ValientProcess
  • 1,699
  • 5
  • 27
  • 43
  • http://stackoverflow.com/questions/25361871/removing-extreme-values-from-a-matrix-in-matlab ==> why u asking again? the answer didn't help? – lakshmen Aug 18 '14 at 13:03
  • it helped a-lot ! :) but i need to do it now with a moving average, and not the total one .. because the fit still looks bad – ValientProcess Aug 18 '14 at 13:06
  • Here you can find some answers: possible duplicate of [Matlab filter electical spikes in accelerometric data](http://stackoverflow.com/questions/19154067/matlab-filter-electical-spikes-in-accelerometric-data) – Robert Seifert Aug 18 '14 at 13:07
  • Thanks, but in there it's again the total average and not the moving average .. – ValientProcess Aug 18 '14 at 13:23
  • @RonMaor you mean because there is a general threshold? Well you could just make the threshold dynamic, shouldn't be much of a change. – Robert Seifert Aug 18 '14 at 13:31
  • @thewaywewalk how can i make it dynamic (according to the local points)? – ValientProcess Aug 18 '14 at 13:32
  • Sorry I don't have the time to help you specifically. It's just a starting point, you could do some own thoughts. – Robert Seifert Aug 18 '14 at 13:34

1 Answers1

1

find the moving average (considering n-1 neighbours, n must be odd ):

n = 3;
k = ones(n,1)/(n-1);
k((n+1)/2) = 0; %//leave out the point you're considering i.e. you kernel will be like [0.5,0,0.5] or [0.25,0.25,0,0.25,0.25] etc
av = conv2(A, k, 'same');

now compare if they're 10 times bigger than the local average

ind = A >= av*10;

then delete the rows:

A(~any(ind,2),:)
Dan
  • 45,079
  • 17
  • 88
  • 157
  • Thanks ! but A is a matrix, i can't convolve it with K – ValientProcess Aug 18 '14 at 13:21
  • You could instead do `conv(A(2,:),k,'same')` – Trogdor Aug 18 '14 at 13:57
  • @RonMaor sorry I should have used `conv2` which (I think) is the same as `[conv(A(1,:),k,'same'), conv(A(2,:),k,'same')]`. I've tested this on your example `A` and it removes the correct row. – Dan Aug 18 '14 at 14:03
  • @RonMaor however if you know that the first column is definitely going to go in order and not face anomalies (i.e. time data) then you should do as the other comments suggest and just convolve with the second column, and compare with the second column, and you won't need the `any` anymore – Dan Aug 18 '14 at 14:08