LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Fast way to measure duty cycle and phase for large data set?

Solved!
Go to solution

I have two input signals that have 4000 cycles per capture. I would like to be able to calculate the duty cycle and phase for each cycle, and then be able to find max, min, and average. I'm wondering if there is a fast way to calculate the duty cycle and phase, as I don't want to wait 20 minutes between runs while it runs through a loop. I'm thinking calculating them all may just always end up taking too long, but wanted to see if anyone has had experience with this before.

0 Kudos
Message 1 of 6
(3,632 Views)

You may want to post some example data, and some code showing how you are currently doing it.  I've used some techniques mentioned here:

 

https://forums.ni.com/t5/LabVIEW/Detect-PWM-Drop-Out/m-p/3556128#M994987

 

And here:

 

https://forums.ni.com/t5/LabVIEW/Two-Threshold-Analog-to-Digital/m-p/2738970#M809660

 

To perform signal integrity on a PWM ensuring that the PWM value doesn't change much from cycle to cycle (standard deviation).  20 minutes sounds crazy and there must be lots of inefficiencies, or you are sampling at a couple gigahertz. 

0 Kudos
Message 2 of 6
(3,616 Views)

20 mins was an exaggeration, just what it feels like. Right now I have it set to only do the first 1000, just to speed it up some, and it is taking 26 secs from the start of the capture to being done calculating. Ideally I'd like for all 4000 to be captured and calculated in under 10 seconds. Which is why I'm thinking it may just not be feasible. I'm thinking will end up having to do just the first couple hundred.

 

The current vi is kinda messy right now. We had an old picoscope laying around, and playing with it to see if it will work for what we want before getting a newer one, so I haven't put much effort into keeping it clean as none of it will be used in a final product.

0 Kudos
Message 3 of 6
(3,613 Views)

One easy speed-up is to replace the While loops around the Pulse Measurements with For loops and enable loop iteration parallelism. Beyond that, I wonder if it would help if after each pulse measurement you used the pulse center output to take a subset of your waveform, excluding the first pulse, before running it through Pulse Measurements.vi again. That way it won't have to repeatedly search through the waveform to find the next pulse to measure.This would preclude iteration parallelism, however.

0 Kudos
Message 4 of 6
(3,598 Views)
Solution
Accepted by topic author randomguy77

Okay try this.  It is a VI that calculates the period and duty cycle of every cycle of a waveform, given the high and low threshold.  You didn't provide any typical data so I generated some.  For my test I generated a square wave with 10,000 cycles of a 100Hz 20% wave, at a sample rate of 10Khz, which generated 1,000,000 samples.  It took 12ms to calculate the duty cycle, and period of all 10,000 cycles (well 9,998 cycles since the first and last were partial).  I included two demos, one which does the timing test I just describe and another that graphs the analog, thresholds, and boolean thresholded data on a single graph for testing.  Improvements could likely still be made.

0 Kudos
Message 5 of 6
(3,586 Views)

That worked amazingly well. Threw it into my VI and it calculated all of the data pretty much instantly. Thank you.

0 Kudos
Message 6 of 6
(3,553 Views)