Normalize
Normalizes the elements of the real or complex vector by using offsets and the division operation. In this function normalization, the vector value is moved and scaled to a range, that is, linear normalization is performed.
For vector normalization, the calculation formula is: 
For in-place operation functions, the calculation formula is: 
The function interface is declared as follows:
- Operations on floating point numbers:
HmppResult HMPPS_Normalize_32f(const float *src, float *dst, int32_t len, float sub, float div);
HmppResult HMPPS_Normalize_64f(const double *src, double *dst, int32_t len, double sub, double div);
HmppResult HMPPS_Normalize_32fc(const Hmpp32fc *src, Hmpp32fc *dst, int32_t len, Hmpp32fc sub, float div);
HmppResult HMPPS_Normalize_64fc(const Hmpp64fc *src, Hmpp64fc *dst, int32_t len, Hmpp64fc sub, double div);
- In-place operations on floating-point numbers:
HmppResult HMPPS_Normalize_32f_I(float *srcDst, int32_t len, float sub, float div);
HmppResult HMPPS_Normalize_64f_I(double *srcDst, int32_t len, double sub, double div);
HmppResult HMPPS_Normalize_32fc_I(Hmpp32fc *srcDst, int32_t len, Hmpp32fc sub, float div);
HmppResult HMPPS_Normalize_64fc_I(Hmpp64fc *srcDst, int32_t len, Hmpp64fc sub, double div);
- Operations on integers with scaling:
HmppResult HMPPS_Normalize_16s_S(const int16_t *src, int16_t *dst, int32_t len, int16_t sub, int32_t div, double scale);
HmppResult HMPPS_Normalize_16sc_S(const Hmpp16sc *src, Hmpp16sc *dst, int32_t len, Hmpp16sc sub, int32_t div, double scale);
- In-place operations on integers with scaling:
HmppResult HMPPS_Normalize_16s_IS(int16_t *srcDst, int32_t len, int16_t sub, int32_t div, double scale);
HmppResult HMPPS_Normalize_16sc_IS(Hmpp16sc *srcDst, int32_t len, Hmpp16sc sub, int32_t div, double scale);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
srcDst |
Pointer to the source vector for in-place operations |
The value cannot be NULL. |
Input/Output |
len |
Vector length |
(0, INT_MAX] |
Input |
sub |
Subtraction (offset) factor |
Depending on the type |
Input |
div |
Denominator factor |
Non-0 |
Input |
scale |
Scale factor |
scale = 2^n, 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 |
The value of src, dst, or srcDst is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_STS_DIV_BY_ZERO_ERR |
The value of div is 0. |
HMPP_STS_SCALE_ERR |
The value of scale is not within the range (0, INF) or is NaN. |
Example
#define BUFFER_SIZE_T 10
void NormalizeExample(void)
{
float src[BUFFER_SIZE_T] = {3, 0, 2, -8, 3, 1, 7, 5, -2, 1};
float dst[BUFFER_SIZE_T];
float sub = 3;
float div = 5;
HmppResult result;
result = HMPPS_Normalize_32f(src, dst, BUFFER_SIZE_T, sub, div);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("dst =");
for (int i = 0; i < BUFFER_SIZE_T; i++) {
printf(" %.1f", dst[i]);
}
printf("\n");
}
Output:
result = 0 dst = 0.0 -0.6 -0.2 -2.2 0.0 -0.4 0.8 0.4 -1.0 -0.4