If your waves are always oscillating around zero it would be quite easy.
All you had to do was scan the array for the first transition of zero,
i.e. going from positive to negative or from negative to positive (which of these transitions is actually irrelevant). The first transition is the starting point of the cycle.
Then you need to find the 2
nd and 3
rd transition in the same fashion. The second transition is at the half cycle interval and the third transistion is the end point of your cycle.
If want to extract more cycles remember the third transition and take that as the starting point of the next cycle to extract.
Now for the case where your data might not oscillate around zero:
Just normalize it like this in the following pseudo code:
double total = 0.0;
foreach(OscillatorValue ov in oscillatorValues)
{
total += ov.Value;
}
double average = total / oscillatorValues.Length;
foreach(OscillatorValue ov in oscillatorValues)
{
ov.Value -= average;
}
A couple of hints:
- When you start at the beginning of the buffer and have no knowledge of the previous state of the wave, there are cases you might want to consider this start also as a transition.
- The normalization should be done on a copy of your buffer.
- Alway normalize before searching for a cycle if you can't be sure if the wave oscillates around zero.
That should help you get started. :)
Regards,
Manfred