LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect a 0 from a signal

Hi,

I use a function name "Sine Wave PtByPt" to generate a sine with a offset see below : 

 

Détection_0.jpg

Can you help me to find the zero point (here 2V) every period ? Thank for your helps.  

 

0 Kudos
Message 1 of 9
(2,495 Views)

For help with your LabVIEW code, you need to post your code (best done by attaching the VI that you used to generate the waveform).  But here's some math that might help you figure this out:

  1. A sinusoid of frequency "f", amplitude "a", bias "b" (also called "offset"), and phase "p" can be generated by a formula whose i-th point (i starting from 0) is given by sinpt(i) = b + sin (2*pi*f*i + p).
  2. The sinusoid is zero when its argument is an integer multiple of pi.
  3. From (1), the argument is 2*pi*f*i + p.
  4. From (2) and (3), 2*pi*f*i + p = n*pi (for integer n).
  5. Solve equation (4) to get the values of i for any integer value of n.

Bob Schor

0 Kudos
Message 2 of 9
(2,475 Views)

Hi,

Thanks for your answer, you can find my code in this attach 

0 Kudos
Message 3 of 9
(2,469 Views)

As long as you at lest one full cycle of data the "zero" you are looking for is simply the average.

 

"Mean PtBypt.vi"

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 9
(2,456 Views)

Hi Ben,

I'm not sure to understand your explanations, I know the average is in this case 2 (equal the offset of my signal) but I don't need this value but I need to detect the 0 (if you want every period of this signal) after I want to send this point 0 to a acquisition card. 

0 Kudos
Message 5 of 9
(2,449 Views)

I should have asked what you mean by "find the zero point".  I assumed that since you knew the offset was 2, you wanted the time that this occurred.  If you want, instead, to compute the offset, then Ben's answer (take the mean) will work as long as you have an integral number of cycles.

 

I notice from your code that you are generating a sinusoid with phase = 0.  The period of your waveform is 1/frequency.  I don't know what "sampling frequency" you are using, but it appears you take 1000 samples per waveform period, so the zeros come at samples 0, 500, 1000, 1500, ..., i.e. n * 500 for n = 0, 1, 2, ...

 

Bob Schor

0 Kudos
Message 6 of 9
(2,447 Views)

I am afraid you are not being clear in what you want.

 

If you do not want to know what the value is are you trying to figure when?

 

Give a context because I am more lost now than when I started reading this thread.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 9
(2,439 Views)

Hi Ben,

Sorry I was busy but now I have a VI to detect a 0 from my signal but sometimes I don't have the same period (see in this attached). Have you got an idea to resolve this problem ? Thanks

 

PS : in this example I'm working with Frequency=cte, Amplitude =cte, Offset=cte. It's just to observe. 

 

   

0 Kudos
Message 8 of 9
(2,356 Views)

It looks like you're successfully detecting your positive slope "zero-crossings" (or more accurately, threshold-crossings where your code sets a threshold of +2.0).  What you're writing to file is the first data point *after* crossing the threshold.   The time you associate with that data point is a query to system time at the moment your algorithm evaluates the data point.  It really isn't a good way to do things, though the problem probably won't show itself in this simple example code.

 

Ideally, you'll be heading toward a DAQ task using a hw clock that gives you deterministic timestamps for each sample.  Barring that, you should associate time with the sample as early as possible in the dataflow.

 

So then, once you have a *good* timestamp for each data point, you should actually make use of the feedback node.  When a crossing is detected, the feedback node gives you the data value just before the crossing.  With both the before and after values, you can interpolate to figure out the (estimated) timestamp when the crossing occurred.  When you identify the times *this* way, you'll get more consistent period measurements.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 9 of 9
(2,340 Views)