Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing an application for an oscilloscope in c# .NET, I am drawing different kinds of waves (sine, square etc..) with the help of zedgraph control.
My values are stored in a buffer of size 1024 and I need to get a single cycle from a wave which means I have to get the values from a wave only for a single cycle from array.

Thank you!
Posted
Updated 24-Dec-10 20:27pm
v3

1 solution

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 2nd and 3rd 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:

C#
double total = 0.0;
// Sum total of all values in buffeer
foreach(OscillatorValue ov in oscillatorValues)
{
    total += ov.Value;
}
// Calculate average of buffer
double average = total / oscillatorValues.Length;
// Normalize the buffer by subtracting the average
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
 
Share this answer
 
v5
Comments
Sergey Alexandrovich Kryukov 25-Dec-10 3:22am    
Manfred, will your method work if the signal is "almost periodic"; because accurately periodic signal is not likely? Also, no matter how you process data, there should be cases when period is not detected at all, so whole buffer should be shown? Finally, there could be cases in between, when period is not detected or detected with low validity, depending on some parameters?

Based on that, don't you think some kind of fuzzy set algorithm should be used? Or I'm trying to complicate?

My idea would be to avoid solving this problem at all, putting forward better UI design idea instead. Think about this: if I want to overview some signal, even certainly periodic, I always feel more comfortable if a period is shown with some piece of signal around it; and if period is marked with something. This is human psychology: we see periodic pattern only if we see some sign of repeated pattern.
Manfred Rudolf Bihy 25-Dec-10 3:42am    
@SAKRyukow: You are right of course, there are edge cases that are not covered in my answer, but I wasn't set out give him a complete solution. He was having difficulties in starting and I pointed out a way to go.

As to the fuzzy set algorithm I have no idea what that is all about :)

And 3rd he didn't say he wanted to extract a cycle in order to display it. He could be doing that for all kinds of reasons. Maybe he wants to do the extraction just to automatically mark a complete cycle in his UI. If you're feeling a bit talkative you can always ask OP what it is all about :)
Thanks for your comment though!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900