Message Edited by Bill@NGC on 08-01-2007 10:26 PM
Thats code looks very useful. I could use it too, I just have one question... What if you don't know the offset? I want to:
1) Verify the waveform exists - I can use this code to do that,
2) Capture a sequence of n cycles after verification, - (again use count to do this)
3) Get the RMS current for the whole cycle. - should be simple
Problem: Signal can be simulated in code, but in real life it's coming from a DAQ capture on a 6229 card. The rest of the circuit is hardware and I don't know what the offset might be from 0V.
Thanks in advance for any help - James
To find the offset (which in this case is the Y value midpoint around which the sine wave is symetrical):
Capture more than one cycle. Find the min and max values. Subtract Min from Max and divide by 2. Then subtract this result from the Max value (or add the result to the Min value). This is the offset.
To count the number of cycles where the offset is unknown, just use the first data point value as a reference. If the next data point is more positive, then count the number of times that the first data point is repeated and the next data point is more positive. Of course with DBL data type, you probably would not get the exact same value as the first data point, so you need to use In Range with a very tiny limit. It all depends on your signal amplitude, frequency, and sampling rate.
Example: Lets say your first data point value is 0.5 and the 2nd point is 0.55. You need to look for another value that is between 0.48 and 0.52. Then read the very next data point value. If it is greater than the previous value, add one to the cycle count. If it is less than, you are at half a cycle, do not add to the count.