LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Efficient unwrap phase code (SGL precision)

Solved!
Go to solution

I wanted to implement an "unwrap phase" function that works with SGL data, since the built-in one (using lvanlys.dll) only accepts DBL data as input and would create conversion overhead. I followed the documentation and implemented the unwrap phase function as discrete Labview code (for loop with shift register), but the benchmark shows that my descrete implementation (with SGL data) runs twice as long as the lvanlys function (with DBL data). The issue is not SGL vs. DBL, this makes only ~10% difference in this case, so it must have to do with the implementation.

unwrap_bench.png

 

 

 

 

 

 

 

 

 

 

I also made a parallelized version of the discrete implementation (cutting the array into chunks, processing them in a parallel loop and stitching them back together), which just barely matches the speed of the built-in (lvanlys) function but uses much more CPU load (the built-in function appears to be single-threaded). Does the built-in function use a different implementation than what is stated in the documentation or is a native C implementation just that much faster (despite the DLL overhead)?

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

Can you "save for previous (2020 or below)" so more can have a look.

 

 

0 Kudos
Message 2 of 6
(1,370 Views)

Here is a LV2018 version.

0 Kudos
Message 3 of 6
(1,358 Views)
Solution
Accepted by topic author Novgorod

if you want fast code, you should avoid floating point division and make loop iterations independent

try to implement Matlabs phase unwrap algorithm (https://de.mathworks.com/help/dsp/ref/unwrap.html)

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

Weird question 

What happens if you add pi(sgl), take the remainder mod 2pi and subtract pi?

 

No loop needed.


"Should be" isn't "Is" -Jay
0 Kudos
Message 5 of 6
(1,311 Views)

@cordm: Thanks, this is much faster, even than the lvanlys function (the sign check should be done before the abs() function though :)). I didn't expect division to be so "expensive". The lvanlys version can handle jumps of multiples of 2pi, while the matlab version requires the discontinuities to be single steps of 2pi (positive or negative), but I think this can be added efficiently in the matlab version (only do division if there is a jump, not for every element) and it's a fringe use case anyway.

 

@JÞB: That sounds like the opposite, i.e. phase wrapping, not unwrapping...

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