08-09-2023 11:06 AM - edited 08-09-2023 11:12 AM
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.
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)?
Solved! Go to Solution.
08-09-2023 01:53 PM
08-09-2023 02:06 PM
Here is a LV2018 version.
08-09-2023 03:12 PM - edited 08-09-2023 03:21 PM
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)
08-09-2023 05:18 PM - edited 08-09-2023 05:21 PM
Weird question
What happens if you add pi(sgl), take the remainder mod 2pi and subtract pi?
No loop needed.
08-10-2023 12:46 AM - edited 08-10-2023 12:49 AM
@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...