# Auxiliary Data Transformations

This section presents code examples for conversion from the Cartesian to polar representation of complex data and vice versa.

## Conversion from Cartesian to polar representation of complex data

// Cartesian->polar conversion of complex data

// Cartesian representation: z = re + I*im

// Polar representation: z = r * exp( I*phi )

#include <mkl_vml.h>

void

variant1_Cartesian2Polar(int n,const double *re,const double *im,

double *r,double *phi)

{

vdHypot(n,re,im,r); // compute radii r[]

vdAtan2(n,re,im,phi); // compute phases phi[]

}

void

variant2_Cartesian2Polar(int n,const MKL_Complex16 *z,double *r,double *phi,

double *temp_re,double *temp_im)

{

vzAbs(n,z,r); // compute radii r[]

vdPackI(n, (double*)z + 0, 2, temp_re);

vdPackI(n, (double*)z + 1, 2, temp_im);

vdAtan2(n,temp_re,temp_im,phi); // compute phases phi[]

}

## Conversion from polar to Cartesian representation of complex data

// Polar->Cartesian conversion of complex data.

// Polar representation: z = r * exp( I*phi )

// Cartesian representation: z = re + I*im

#include <mkl_vml.h>

void

variant1_Polar2Cartesian(int n,const double *r,const double *phi,

double *re,double *im)

{

vdSinCos(n,phi,im,re); // compute direction, i.e. z[]/abs(z[])

vdMul(n,r,re,re); // scale real part

vdMul(n,r,im,im); // scale imaginary part

}

void

variant2_Polar2Cartesian(int n,const double *r,const double *phi,

MKL_Complex16 *z,

double *temp_re,double *temp_im)

{

vdSinCos(n,phi,temp_im,temp_re); // compute direction, i.e. z[]/abs(z[])

vdMul(n,r,temp_im,temp_im); // scale imaginary part

vdMul(n,r,temp_re,temp_re); // scale real part

vdUnpackI(n,temp_re,(double*)z + 0, 2); // fill in result.re

vdUnpackI(n,temp_im,(double*)z + 1, 2); // fill in result.im

}

Parent topic: Fourier Transform Functions Code Examples