我要评分
获取效率
正确性
完整性
易理解

AutoCorrNorm

Calculates the normalized autocorrelation of the src vector whose length is srcLen and stores the result in the dst vector. Normalization supports normal, biased, and unbiased autocorrelation modes. The calculation formulas are as follows:

The function is called as follows:

  1. Initialize the HmppsCorrPolicy_32f structure by calling an initialization function.
  2. Call the main function.
  3. Call Release to release the memory contained in the HmppsCorrPolicy_32f function.

The function interface is declared as follows:

  • Initialization:

    HmppResult HMPPS_AutoCorrInit_32f(int32_t srcLen, int32_t dstLen, HmppAlgMode calcMode, HmppsCorrPolicy_32f **policy);

    HmppResult HMPPS_AutoCorrInit_64f(int32_t srcLen, int32_t dstLen, HmppAlgMode calcMode, HmppsCorrPolicy_64f **policy);

    HmppResult HMPPS_AutoCorrInit_32fc(int32_t srcLen, int32_t dstLen, HmppAlgMode calcMode, HmppsCorrPolicy_32fc **policy);

    HmppResult HMPPS_AutoCorrInit_64fc(int32_t srcLen, int32_t dstLen, HmppAlgMode calcMode, HmppsCorrPolicy_64fc **policy);

  • Main functions:

    HmppResult HMPPS_AutoCorrNorm_32f(const float *src, int32_t srcLen, float *dst, int32_t dstLen, HmppNormMode normMode, HmppsCorrPolicy_32f *policy);

    HmppResult HMPPS_AutoCorrNorm_64f(const double *src, int32_t srcLen, double *dst, int32_t dstLen, HmppNormMode normMode, HmppsCorrPolicy_64f *policy);

    HmppResult HMPPS_AutoCorrNorm_32fc(const Hmpp32fc *src, int32_t srcLen, Hmpp32fc *dst, int32_t dstLen, HmppNormMode normMode, HmppsCorrPolicy_32fc *policy);

    HmppResult HMPPS_AutoCorrNorm_64fc(const Hmpp64fc *src, int32_t srcLen, Hmpp64fc *dst, int32_t dstLen, HmppNormMode normMode, HmppsCorrPolicy_64fc *policy);

  • Memory release:

    HmppResult HMPPS_CorrRelease_32f(HmppsCorrPolicy_32f *policy);

    HmppResult HMPPS_CorrRelease_64f(HmppsCorrPolicy_64f *policy);

    HmppResult HMPPS_CorrRelease_32fc(HmppsCorrPolicy_32fc *policy);

    HmppResult HMPPS_CorrRelease_64fc(HmppsCorrPolicy_64fc *policy);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source vector

The value cannot be NULL.

Input

srcLen

Length of the source vector

(0, INT_MAX]

Input

dst

Pointer to the destination vector

The value cannot be NULL.

Output

dstLen

Length of the destination vector

The value cannot be NULL.

Input

algMode

Algorithm model used for the calculation (defined in the HmppAlgMode enumeration type. See Enumeration Types.)

The value is an element of HmppAlgMode:

  • HMPP_ALG_AUTO
  • HMPP_ALG_DEFAULT
  • HMPP_ALG_FFT

Input

normMode

Data normalization mode (defined in the HmppNormMode enumeration type. See Enumeration Types.)

The value is an element of HmppNormMode:

  • HMPP_NORM_NORMAL
  • HMPP_NORM_BIASED
  • HMPP_NORM_UNBIASED

Input

policy

(in the Init function)

Pointer to the memory that stores CorrPolicy

The value cannot be NULL.

Output

policy

(In the main function and the Release function)

Pointer to the CorrPolicy structure

The value cannot be NULL.

Input

Return Value

  • Success: HMPP_STS_NO_ERR
  • Failure: An error code is returned.

Error Codes

Error Code

Description

HMPP_STS_NO_ERR

No error occurs.

HMPP_STS_NULL_PTR_ERR

Any of the specified pointers is NULL.

HMPP_STS_SIZE_ERR

The value of srcLen or dstLen is less than or equal to 0.

HMPP_STS_MISMATCH

The size of the problem that the Init function applies for memory does not match the size of the problem that is actually calculated in the main function.

HMPP_STS_OVERFLOW_ERR

The problem size of the FFT acceleration model is too large.

HMPP_STS_MALLOC_FAILED

The Init function failed to allocate the memory required by the algorithm model.

Note

  • Before this interface is called for calculation, the Init interface must be called to initialize the HmppsCorrPolicy_32f standard structure.
  • The initialization of the HmppsCorrPolicy_32f structure needs to be applied for in the Init function. You cannot apply for or define this structure by yourself.
  • src and dst cannot be the same array. Otherwise, the result may be incorrect.
  • When the HMPP_ALG_AUTO or HMPP_ALG_FFT mode is used, the "OVERFLOW" error message is displayed if the values of srcLen and dstLen are large.

Example

void AutoCorrNorm_Example()
{
    const int len = 10;
    float src[len];
    float dst[len];
    int32_t srcLen = len;
    int32_t dstLen = len;

    for (int i = 0; i < srcLen; ++i) {
        src[i] = 1;
    }
    HmppsCorrPolicy_32f *policy = NULL;
    HmppResult result = HMPPS_AutoCorrInit_32f(srcLen, dstLen, HMPP_ALG_AUTO, &policy);
    if (result != HMPP_STS_NO_ERR) {
        printf("Init failed");
        return;
    }
    result = HMPPS_AutoCorrNorm_32f(src, srcLen, dst, dstLen, HMPP_NORM_NORMAL, policy);
    if (result != HMPP_STS_NO_ERR) {
        printf("AutoCorr failed");
        return;
    }
    for (int i = 0; i < dstLen; ++i) {
        printf("%.2f ", dst[i]);
    }
    HMPPS_CorrRelease_32f(policy);
}

Output:

10 9 8 7 6 5 4 3 2 1