LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two Threshold Analog to Digital

Solved!
Go to solution

I was asked to develop some code that would take a signal in on an analog, then convert it to a digital, then perform frequency, duty cycle, and signal integrity testing on it.  The built in NI functions for performing these tasks were insufficient because we needed to be able to detect a single drop out of a cycle.  With a real world signal I realize there maybe noise and a having a single threshold to convert from a analog to a digital may show transitions that aren't there and so I planned on developing some kind of debounce code.

 

Instead someone mentioned using two thresholds, one for the low and one for the high, and to only consider the signal transitioning if it goes above the high, after going below the low.  

 

Attached is my attempt at that method.  This VI simulates a sine wave with a bunch of noise then does a single theshold to show how imperfect it can be.  Then using that same signal it does a two level theshold which works much better but has a slight shift in the time domain, and the beginning will contain unknown values because neither transition has occured with the first sample.

 

Any pointers or suggestions to improve my implementation is appreciated.  Thanks.

 

EDIT: This does use an OpenG function from the Array palette.

0 Kudos
Message 1 of 6
(6,441 Views)

Why so many loops when you just need one?

 

 


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
Message 2 of 6
(6,428 Views)

@crossrulz wrote:

Why so many loops when you just need one? 

 


Well partially because I also need to know at which indices the transitions occur at.  But still adding the extra XOR code to your modification is still probably much faster I'll update and give it a try.

 

EDIT: And actually the digitized version is not needed in my application at all, and will likely have a boolean control to generate it, with the default being false.  Transition times is really all I care about at the moment but wanted to visualize them which is why I added it.

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

If you need the indecies, then use a conditional autoindexing tunnel with the i.  When there is a transition, you 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
(6,420 Views)
Solution
Accepted by topic author Hooovahh

I did some deletions to your code and converted to 2012 for you.  Also added the indeices coming out.


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
Message 5 of 6
(6,412 Views)

@crossrulz wrote:

I did some deletions to your code and converted to 2012 for you.  Also added the indeices coming out.


Thanks.  Quick test shows that with 50,000 samples your code is roughly 10 times faster then mine.

0 Kudos
Message 6 of 6
(6,407 Views)