Rate This Document
Findability
Accuracy
Completeness
Readability

PolarToCart

Converts polar coordinates to rectangular coordinates.

The formulas are as follows:

The function interface declaration is as follows:

  • Operations on integers:

    HmppResultHMPPS_PolarToCart_16sc_S(constint16_t*srcMagn, constint16_t*srcPhase, Hmpp16sc*dst, int32_tlen, doublemagnScale, double phaseScale);

  • Operations on floating-point numbers:

    HmppResultHMPPS_PolarToCart_32f(constfloat*srcMagn, constfloat*srcPhase, float*dstRe, float*dstIm, int32_tlen);

    HmppResultHMPPS_PolarToCart_64f(constdouble*srcMagn, constdouble*srcPhase, double*dstRe, double*dstIm, int32_tlen);

    HmppResultHMPPS_PolarToCart_32fc(constfloat*srcMagn, constfloat*srcPhase, Hmpp32fc*dst, int32_tlen);

    HmppResultHMPPS_PolarToCart_64fc(constdouble*srcMagn, constdouble*srcPhase, Hmpp64fc*dst, int32_tlen);

Parameters

Parameter

Description

Value Range

Input/Output

srcMagn

Pointer to the source vector which stores the radial distances of the vector elements

The value cannot be NULL.

Input

srcPhase

Pointer to the source vector which stores the polar angles of the vector elements

The value cannot be NULL.

Input

len

Vector length

(0, INT_MAX]

Input

dst

Pointer to the destination vector which stores the complex numbers

The value cannot be NULL.

Output

dstRe

Pointer to the source vector which stores the real parts of the complex numbers

The value cannot be NULL.

Output

dstIm

Pointer to the source vector which stores the imaginary parts of the complex numbers

The value cannot be NULL.

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 PolarToCartExample(void)
{
    int32_t len = SRC_LEN;
    float srcMagn[SRC_LEN] = { 4.94, -2.39, -6.89, 54602.84, 8.17, 9.61, -7.003, 8.9 };
    float srcPhase[SRC_LEN] = { 4.0, 2.67, -1.02, -1.23, -6.84, -5.73, 3.89, 9.54 };
    float dstRe[SRC_LEN] = { 0.0f };
    float dstIm[SRC_LEN] = { 0.0f };

    HmppResult result = HMPPS_PolarToCart_32f(srcMagn, srcPhase, dstRe, dstIm, len);
    printf("HMPPS_PolarToCart_32f result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }

    int32_t i;
    printf("len = %d\ndstRe =", len);
    for(i = 0; i < len; ++i){
        printf(" %f", dstRe[i]);
    }
    printf("\ndstIm =");
    for(i = 0; i < len; ++i){
        printf(" %f", dstIm[i]);
    }
    printf("\n");
}

Output:

HMPPS_PolarToCart_32f result = 0
len = 8
dstRe = -3.228999 2.129122 -3.605992 18250.328125 6.935862 8.176719 5.131613 -8.840986
dstIm = -3.738604 -1.085790 5.871024 -51462.562500 -4.317721 5.049095 4.765349 -1.023208