title: Peak detection / Slice discrete data
body: <p>I have been given a task, that given discrete data, like this</p>
  
  <p><a href="https://i.stack.imgur.com/HVwh6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HVwh6.png" alt="enter image description here"></a></p>
  
  <p>I need to slice it into 5 pieces, determined by the template it creates.</p>
  
  <p>I am not allowed to guess a template, because every input looks different.</p>
  
  <p>My approach was to find peaks in the data (above or below zero), then use that pattern of peaks to slice the data. Here is what I got: (not for the above data)</p>
  
  <p><a href="https://i.stack.imgur.com/4FxAg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4FxAg.png" alt="enter image description here"></a></p>
  
  <p>The top graph is the peaks in the graph, and because I know I have exactly 5 pieces, and 15 points, I can say that every piece has 3 points, and then slice it, which is the second graph in that picture.</p>
  
  <p>Out of 40 inputs, I managed to do this only for 5 of them, because my "peak detection" algorithm is very very basic.</p>
  
  <p>What peak detection algorithm should I use, that can also find local minimums, and has PHP implementation / simple psudo code? I am a beginner in this field of data analyzing, so I need your tips.</p>
  
  <p>Finally, am I even going in the right direction on how to slice this data? or is there a better known way to do it?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>My bad for not explaining before: the goal of this slicing, is to create a uniform not-time dependent model for a slice, meaning that long and short pieces will be the same length, and that is for each peak. If this is done per slice, just stretching, the data looks noisy, like this: (this is still in development, so I didn't write it before)
  <a href="https://i.stack.imgur.com/q5jr0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q5jr0.png" alt="enter image description here"></a></p>
  
  <p>And I don't know how to do it without the peaks, because every slice has different times for different parts (1 second, 1.1 seconds, etc)</p>