CrossCorrNorm
Calculates the normalized cross-correlation between the src1 vector whose length is src1Len and the src2 vector whose length is src2Len, and stores the result in the dst vector. Normalization supports normal, biased, and unbiased autocorrelation modes. The calculation formulas are as follows:




The function calling process is as follows:
- Initialize the HmppsCorrPolicy_32f structure by calling Init.
- Call the main function.
- Call Release to release the memory contained in the HmppsCorrPolicy_32f function.
The function interface declaration is as follows:
- Initialization:
HmppResult HMPPS_CrossCorrInit_32f(int32_t src1Len, int32_t src2Len, int32_t dstLen, int32_t lowLag, HmppCalcMode calcMode, HmppsCorrPolicy_32f **policy);
HmppResult HMPPS_CrossCorrInit_64f(int32_t src1Len, int32_t src2Len, int32_t dstLen, int32_t lowLag, HmppCalcMode calcMode, HmppsCorrPolicy_64f **policy);
HmppResult HMPPS_CrossCorrInit_32fc(int32_t src1Len, int32_t src2Len, int32_t dstLen, int32_t lowLag, HmppCalcMode calcMode, HmppsCorrPolicy_32fc **policy);
HmppResult HMPPS_CrossCorrInit_64fc(int32_t src1Len, int32_t src2Len, int32_t dstLen, int32_t lowLag, HmppCalcMode calcMode, HmppsCorrPolicy_64fc **policy);
- Main functions:
HmppResult HMPPS_CrossCorrNorm_32f(const float *src1, int32_t src1Len, const float *src2, int32_t src2Len, float *dst, int32_t dstLen, int32_t lowLag, HmppNormMode normMode, HmppsCorrPolicy_32f *policy);
HmppResult HMPPS_CrossCorrNorm_64f(const double *src1, int32_t src1Len, const double *src2, int32_t src2Len, double *dst, int32_t dstLen, int32_t lowLag, HmppNormMode normMode, HmppsCorrPolicy_64f *policy);
HmppResult HMPPS_CrossCorrNorm_32fc(const Hmpp32fc *src1, int32_t src1Len, const Hmpp32fc *src2, int32_t src2Len, Hmpp32fc *dst, int32_t dstLen, int32_t lowLag, HmppNormMode normMode, HmppsCorrPolicy_32fc *policy);
HmppResult HMPPS_CrossCorrNorm_64fc(const Hmpp64fc *src1, int32_t src1Len, const Hmpp64fc *src2, int32_t src2Len, Hmpp64fc *dst, int32_t dstLen, int32_t lowLag, 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 |
|---|---|---|---|
src1 |
Pointer to the first source vector |
The value cannot be NULL. |
Input |
src1Len |
Length of the first source vector |
(0, INT_MAX] |
Input |
scr2 |
Pointer to the second source vector |
The value cannot be NULL. |
Input |
src2Len |
Length of the second source vector |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
dstLen |
Length of the destination vector |
(0, INT_MAX] |
Input |
lowLag |
Minimum cross-correlation lag |
[INT_MIN,INT_MAX] |
Input |
algMode |
Algorithm model used for calculation. The value can be HMPP_ALG_AUTO, HMPP_ALG_DEFAULT or HMPP_ALG_FFT. |
HMPP_ALG_AUTO HMPP_ALG_DEFAULT HMPP_ALG_FFT |
Input |
normMode |
Data normalization mode. The value can be HMPP_NORM_NORMAL, HMPP_NORM_BIASED or HMPP_NORM_UNBIASED. |
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 |
src1Len, src2Len 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 and define this structure by yourself.
- src1 and src2 must not be the same array with dst. 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 src1Len, src2Len or dstLen is large.
Example
void CrossCorrNorm_Example()
{
const int src1Len = 10;
const int src2Len = 5;
const int dstLen = 10;
float src1[src1Len];
float src2[src2Len];
float dst[dstLen];
HmppsCorrPolicy_32f *policy = NULL;
for (int i = 0; i < src1Len; ++i) src1[i] = 1;
for (int i = 0; i < src2Len; ++i) src2[i] = 1;
int lowLag = -1;
HmppResult result = HMPPS_CrossCorrInit_32f(src1Len, src2Len, dstLen, lowLag, HMPP_ALG_AUTO, &policy);
if (result != HMPP_STS_NO_ERR) {
printf("Init failed");
return;
}
result = HMPPS_CrossCorrNorm_32f(src1, src1Len, src2, src2Len, dst, dstLen, lowLag, HMPP_NORM_NORMAL, policy);
if (result != HMPP_STS_NO_ERR) {
printf("CrossCorr failed");
return;
}
for (int i = 0; i < dstLen; ++i) {
printf("%.2f ", dst[i]);
}
HMPPS_CorrRelease_32f(policy);
}
Output:
5 5 4 3 2 1 0 0 0 0