LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Zero-crossing function

Solved!
Go to solution

Hi,

 

I found this zero-crossing function in one of the old forums and I'm trying to understand how it works. In my case I have two sine waves, instead of one square pulse but I can't really figure out how this function works. I know that first, the waves are generated then you get their attributes, the data values go into the zero-crossing detector that controls the case statement but I don't know how the trigger time and time interaval are used to build the array, I think the timestamp outside the 'for' loop is for storing the previous itteration of the zero-crossings but I'm not really sure.I have no clue what happens in the final step before the zero-crossing times are subtarcted, as in the threshold array and so on. I've read how each function individually but I can't add the blocks together.

 

So I was wondering if someone could please explain how this works?

 

Thanks

0 Kudos
Message 1 of 6
(4,434 Views)

The first two loops are just finding the timestamps of the zero crossings (for the sine wave) or the rising edge (for the square wave).  If the zero crossing or edge was found, add the timestamp of that point to an array.

 

The last loop is looking for the time differences between the rising edge and the previous zero crossing.  The Threshold 1D Array is used to find the last time stamp of the sinusoid's zero crossings that come before the iteration's square wave rising edge.  Then the two times are subtracted.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 6
(4,422 Views)

I understand the general process of the overall function and I kinda understand the final loop of the block diagram. But I'm not sure why dt is mutiplied to the current loop iteration. Isn't t0 the start time of the waveform, then why is it added to the result from the multiplication. I think then the answer is added to the array, why is the big timestamp array going to the top of build array. If someone could explain this in bit more detail that would be greatly appreciated. Sorry for the trouble.

 

Thanks

0 Kudos
Message 3 of 6
(4,417 Views)

To get the time of the indexed value, you have to multiply dt by the sample index and then add T0.  It is basic math.  T = dt*i + T0.

 

To add items to an array, we are using a shift register to hold the array then Build Array to add to the array.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 6
(4,412 Views)

Lets say your dt value is 0.001 (1 ms) and you have array of data (lets say 100 samples. So to calculate the time of each sample the dt is multiplied with the iteration count which starts from 0 by multiplying the dt with i value 0. Similarly if you want to calculate the timing of 50th sample multiply dt with the iteration so you would arrive at 49 ms, the same for other samples.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 5 of 6
(4,410 Views)
Solution
Accepted by topic author kg21

Adding to what crossrulz said, it helps to understand what the code you're looking at is.

 

It would appear you don't quite understand what t0 and dt are.  t0 is the time at the initial point in the waveform.  This can be a wide variety of times rather than simply 0.  dt is the amount of time between samples.  If we multiply the iteration by dt, we know how much time has passed since the first sample.  After 0, 0dt is the same as 0s.  From there, 1dt, 2dt, 3dt, etc can all be calculated to a value measuring time.  But, it's only measuring "time since the first sample."  If it's only measuring that, the timestamp could be meaningless.  If you want to convert the time since first sample to an actual time, you need to add the initial time to it.  As an example, if dt is 1s and t0 is 4:00:00pm, after 3 samples we are at 2dt so 2 seconds.  Do we care about 2 seconds or 4:00:02?

 

The "big timestamp array" is being fed into what is called a shift-register.  You can use this register to pass values between iterations of a loop.  Before the loop, we feed an uninitialized array into the shift register.  The first time the build array is used, it's fed an empty array and the first timestamp to save.  This is then output to the shift register on the right side of the loop.  This value is passed to the next iteration.  It will persist until we reach the build array for the second time.  Now, the 1 element array is fed into the top input of the build array and a new timestamp is added to the end of the array.  This will continue with the n-sized array being fed to the top input and the newest timestamp being added to the end to make an array of size n+1.  If we want to maintain all of the timestamps, we need logic similar to this.  You could plug it into the bottom and the new timestamp to the top.  This would put the newest timestamps in the first element of the array.  You just want to include the old array so you keep all of the timestamps instead of just the most recent.

Message 6 of 6
(4,377 Views)