Adelsbach/VSIPL
Core Programming Reference Guide
DD-00016-015
Core

This manual is preliminary and incomplete.
While our Core implementation implements all functions given in the standard we are still working on completing this documentation.

Please refer to the VSIPL standard for a complete function reference of the Core profile until we have completed work on this documentation.

4.6.8 vsip_vpolar_p - Convert Polar Coordinates to Cartesian

void vsip_vpolar_f(const vsip_cvview_f *a, const vsip_vview_f *r, const vsip_vview_f *s);
Description

This function converts complex numbers from a complex vector into their polar coordinate representation (magnitude and phase). The operation performs element-wise conversion from Cartesian to polar coordinates:

ri= |ai|

si=arg(ai)

for all i from 0 to n-1, where n is the length of the vectors, ri is the magnitude, and si is the phase (angle in radians) of the complex number ai.

Parameters
Example

vsip_cvview_f *complex_signal; 
vsip_vview_f *magnitudes, *phases; 
vsip_length n = 10; 
 
// Create vectors 
complex_signal = vsip_cvcreate_f(n, VSIP_MEM_NONE); 
magnitudes = vsip_vcreate_f(n, VSIP_MEM_NONE); 
phases = vsip_vcreate_f(n, VSIP_MEM_NONE); 
 
// Initialize complex signal (e.g., with some complex values) 
for (vsip_length i = 0; i < n; i++) { 
    float real = cos(2 * M_PI * i / n); 
    float imag = sin(2 * M_PI * i / n); 
    vsip_cvput_f(complex_signal, i, VSIP_CMPLX_F(real, imag)); 
} 
 
// Convert to polar coordinates 
vsip_vpolar_f(complex_signal, magnitudes, phases); 
 
// The magnitudes and phases vectors now contain the polar representation 
// of your complex signal 
 
// Print some results 
printf("Magnitude and Phase (first 3 elements):\n"); 
for (vsip_length i = 0; i < 3; i++) { 
    printf("Element %ld: Magnitude = %.4f, Phase = %.4f radians\n", 
           i, vsip_vget_f(magnitudes, i), vsip_vget_f(phases, i)); 
} 
 
// Clean up 
vsip_cvalldestroy_f(complex_signal); 
vsip_valldestroy_f(magnitudes); 
vsip_valldestroy_f(phases);
Notes