CartToPolar
Converts right-angle coordinates to polar coordinates.
The formula for calculating the polar angle is as follows:

The formula for calculating the radial distance is as follows:

The function interface declaration is as follows:
- Operations on integers:
HmppResult HMPPS_CartToPolar_16sc_S(const Hmpp16sc *src, int16_t *dstMagn, int16_t *dstPhase, int32_t len, double magnScale, double phaseScale);
- Operations on floating point numbers:
HmppResult HMPPS_CartToPolar_32f(const float *srcRe, const float *srcIm, float *dstMagn, float *dstPhase, int32_t len);
HmppResult HMPPS_CartToPolar_64f(const double *srcRe, const double *srcIm, double *dstMagn, double *dstPhase, int32_t len);
HmppResult HMPPS_CartToPolar_32fc(const Hmpp32fc *src, float *dstMagn, float *dstPhase, int32_t len);
HmppResult HMPPS_CartToPolar_64fc(const Hmpp64fc *src, double *dstMagn, double *dstPhase, int32_t len);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the complex source vector |
The value cannot be NULL. |
Input |
srcRe |
Pointer to the source vector which stores the real parts of complex elements |
The value cannot be NULL. |
Input |
srcIm |
Pointer to the source vector which stores the imaginary parts of complex elements |
The value cannot be NULL. |
Input |
len |
Vector length |
(0,INT_MAX] |
Input |
dstMagn |
Pointer to the destination vector which stores the radial distance of the vector elements |
The value cannot be NULL. |
Output |
dstPhase |
Pointer to the destination vector which stores the polar angle of the vector elements |
The value cannot be NULL. The value range is (–π, π]. |
Output |
magnScale |
Scale factor of the radial distance |
scale = 2n, where n is an integer. The value is within (0, INF). |
Input |
phaseScale |
Scale factor of the polar angle |
scale = 2n, where n is an integer. The value is within (0, INF). |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
Any of the specified pointers is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_STS_SCALE_ERR |
The value of magnScale or phaseScale is not within the range (0, INF) or is NaN. |
HMPP_STS_MALLOC_FAILED |
The Init function failed to allocate the memory required by the algorithm model. |
Example
#define SRC_LEN 8
void CartToPolarExample(void)
{
int32_t len = SRC_LEN;
float srcRe[SRC_LEN] = { 59.960567, 7.2509279, 1.7840941, 155.84264, 0.0020125117, 0.73378527, 4497.1704, 630.54828 };
float srcIm[SRC_LEN] = { 2.0548565, 0.00067954202, 0.028709119, 0.0001744011, 0.0054633785, 0.00063873257, 2293.6162, 7.3549595 };
float dstMagn[SRC_LEN] = { 0.0f };
float dstPhase[SRC_LEN] = { 0.0f };
HmppResult result = HMPPS_CartToPolar_32f(srcRe, srcIm, dstMagn, dstPhase, len);
printf("HMPPS_CartToPolar_32f result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
int32_t i;
printf("len = %d\ndstMagn =", len);
for(i = 0; i < len; ++i){
printf(" %f", dstMagn[i]);
}
printf("\ndstPhase =");
for(i = 0; i < len; ++i){
printf(" %f", dstPhase[i]);
}
printf("\n");
}
Output:
HMPPS_CartToPolar_32f result = 0 len = 8 dstMagn = 59.995770 7.250928 1.784325 155.842636 0.005822 0.733786 5048.288574 630.591187 dstPhase = 0.034257 0.000094 0.016090 0.000001 1.217856 0.000870 0.471626 0.011664