-1

Given an array V, which is the numerical solution of a system of differential equations, I want to determine the local, positive peaks of this array. Every time I have such a peak whose value is greater than 0 I code a bit equal to 1 and every time I have a peak with a negative value I code a bit equal to 0(I cannot use findpeaks).

I have tried the following:

function Suite_bits = message_digital(V)
j = 1;
bit(1) = 0;
for i=2:numel(V)-1
    if V(i-1)<V(i) && V(i+1)<V(i)
        if V(i)>0
            bit(j) = 1;
            j = j + 1; 
        else
            bit(j) = 0;
            j = j + 1;
        end 
    end
    Suite_bits = bit;
end

But due to some minor anomalies in the vector V, fluctuations of the values between steps (remember V is the solution of a numerically solved ode system with a step h = 0.1), I get more peaks than actually appear in the graph. Any ideas how I could fix this?

Desperados
  • 434
  • 5
  • 13
  • 2
    You may find the following useful. https://stackoverflow.com/questions/22583391/peak-signal-detection-in-realtime-timeseries-data – jodag Mar 24 '18 at 22:48

1 Answers1

0

Fluctuations of V vector can be avoided by use of the 'smooth' function provided by MATLAB. By default this function smooths data using a 5 point moving average. You can change the arguments of this function so that the moving average includes more or less than 5 points. Thus, depending on the magnitude of the fluctuations, this argument can be arranged so that fluctuations are smoothed and ignored by the algorithm. This is an example of code that could work:

function Suite_bits = message_digital(V)
j = 1;
V = smooth(V, 15);
bit(1) = 0;
for i=2:numel(V)-1
    if V(i)>V(i-1) && V(i)>V(i+1) 
        if V(i)>0
            bit(j) = 1;
            j = j + 1; 
        else
            bit(j) = 0;
            j = j + 1;
        end 
    end
    Suite_bits = bit;
end
end
Desperados
  • 434
  • 5
  • 13