I would like to speed up some MATLAB application by replacing a bottleneck section with a short C file.
At some stage I have to "normalize" a long complex array z. In MATLAB, complex array are kept as two separate arrays storing the real and imaginary parts. Hence, the problem is equivalent to computing a unit length 2D vector from an arbitrary length one.
Of course, it can be accomplished by the following simple code (MATLAB)
z_unit = z./abs(z);
This code is prone to problems when you get some zero vectors in your input. Hence, I use the following code
phase = angle(z); z_unit = exp(i * phase);
which is quite slow.
I tried to replace the angle function with my own implementation (based on atan2 from IPP) which immediately provided some improvement, but the following exp() is still expensive to compute.
I noticed there are Cartesian->polar conversion functions, however their precision is questionable. I tested 'phase' function which is faster than atan2 but its precision is worse.
Will be glad to get any advice here. Thank you.
P.S. Computing the absolute value abs(z) is also important.
IPP vector math domain library contains some transcedental math functions with specified (means guaranteed)accuracy, please check if that will helpful in your case. You can check ippvm.h file and IPP documentation, volume 1, signal processing.