LabVIEW

cancel
Showing results for
Did you mean:

how to count the number of cycles in sine wave

Hi,

I am new to Labview.  I have labview 8.2 version and my dataacquisition is NIDAQPAD6015.  I could write a program to generate a sine wave of desired frequency through simulate signal. My question is how do i measure the number of cycles for this sine wave as soon as I run the program. Hope my question  is clear.

Ravi Mokirala
Message 1 of 15
(13,258 Views)

Re: how to count the number of cycles in sine wave

Find the midpoint of the peak to peak amplitude (usually 0).  Count how many times this midpoint is crossed in one direction.
To count, use a For loop with shift registers.  Convert waveform to a data array.  Wire in data array to For loop with indexing enabled.  Also wire to shift register.  Compare current data with previous data from shift register.  Look for midpoint crossing.  Example:  if midpoint is 0, look for when the data goes from negative to positive.
- tbob

Inventor of the WORM Global
Message 2 of 15
(13,247 Views)

Re: how to count the number of cycles in sine wave

Do you mean using the 6015 or purely in LabVIEW? The 6015 has two counters if you want to count edges of an analog input.

Message Edited by Bill@NGC on 08-01-2007 10:26 PM

Message 3 of 15
(13,234 Views)

Re: how to count the number of cycles in sine wave

Hi Bob,

Thankyou for the reply. Can you just draw the block diagram so that I can understand it better.

Ravi Mokirala
Message 4 of 15
(13,209 Views)

Re: how to count the number of cycles in sine wave

Here is a vi that will count cycles.  The last data point must end completely equal to or above the first data point or it won't be counted.  Incomplete cycles will not be counted.

- tbob

Inventor of the WORM Global
Message 5 of 15
(13,194 Views)

Re: how to count the number of cycles in sine wave

Hi Bob,

Thank you for your response. As I am new to labview my questions may sound a bit crazy to you. How do I continuously increase the count of the cycles in sine wave i.e. I should get the cycle count as 1,2,3........50......100.... till I stop the test. The present  test shows a standard number i.e. 6 cycles. Your reply would be greatly appreciated. I am really sorry if I am troubling you a lot.

Thanks and  Regards

Ravi Mokirala

Message 6 of 15
(13,156 Views)

Re: how to count the number of cycles in sine wave

I used the Simulate Signal express vi in this one.  It will count the number of cycles generated until you press the stop button.

- tbob

Inventor of the WORM Global
Message 7 of 15
(13,128 Views)

Re: how to count the number of cycles in sine wave

Hi Bob,

Thank you very much for sending me the program. I really appreciate your help.

Thanks and Regards

Ravi Mokirala
Message 8 of 15
(13,098 Views)

Re: how to count the number of cycles in sine wave

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

Message Edited by James W on 03-11-2008 10:15 AM
CLD; LabVIEW since 8.0, Currently have LabVIEW 2015 SP1, 2018SP1 & 2020 installed
Message 9 of 15
(12,878 Views)

Re: how to count the number of cycles in sine wave

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.

- tbob

Inventor of the WORM Global
Message 10 of 15
(12,865 Views)