[Scilab-users] Peaks and positions

Dang, Christophe Christophe.Dang at sidel.com
Tue Jan 29 09:09:58 CET 2013


Hello,

> My problem consist: a matrix like  [v,k1,k2]
[...]
> if I plot the values, Im gonna find "spikes" that means "errors

OK, I guess that a spike is a steep change in the value,
a huge derivative.

IMHO, you should compare 2 consecutive values in a column.
This can be done by subtracting
M(i+1, j) - M(i, j) (slope between 2 points)
then compare the absolute value with a given threshold.

Mind that a spike gives 2 consecutive high slopes,
one up and one down.

I suggest:

// *******************

// constants, to be adjusted according to your case
lowerthreshold = 0;
upperthreshold = 3;

// data with spikes

v = [1;2;3;4;10;6;7;8;9;10];
k1 = [1;2;3;4;5;6;7;0;9;10];

M = [v, k1];
disp(M); // display the initial matrix
clf;
plot(M(:,1), M(:,2), 'b-+');

// locate the zeros (or very small values if upperthreshold not 0)
[izeros, jzeros] = find(M <= lowerthreshold);

M(izeros, :) = []; // shrink the lines with zeros
disp(M); // display the matrix without zeros

// Detect the spikes
slope = M(2:$, :) - M(1:$-1,:); // Difference btw consecutive values
k = 0; // initialisation, k is the number of spikes so far
ispikes = []; // in case no spike is detected
for i = 1:size(slope, 'r')
    if abs(slope(i)) >= upperthreshold then
        k = k+1;
        ispikes(k) = i;
        i = i+1 // skip next slope which is also high
    end
end

M(ispikes, :) = [];; // shrink the lines with zeros
disp(M); // display the matrix without spikes
plot(M(:,1), M(:,2), 'r');

// *******************

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.





More information about the users mailing list