Magnitude
Calculates the modulus of a complex vector.
The calculation formula is as follows:
.
The function interface declaration is as follows:
- Operations on floating-point numbers:
HmppResult HMPPS_Magnitude_16s32f(const int16_t *srcRe, const int16_t *srcIm, float *dst, int32_t len);
HmppResult HMPPS_Magnitude_16sc32f(const Hmpp16sc* src, float* dst, int32_t len);
HmppResult HMPPS_Magnitude_32f(const float* srcRe, const float* srcIm, float* dst, int32_t len);
HmppResult HMPPS_Magnitude_64f(const double* srcRe, const double* srcIm, double* dst, int32_t len);
HmppResult HMPPS_Magnitude_32fc(const Hmpp32fc* src, float* dst, int32_t len);
HmppResult HMPPS_Magnitude_64fc(const Hmpp64fc* src, double* dst, int32_t len);
- Operations on integers with scaling:
HmppResult HMPPS_Magnitude_16sc_S(const Hmpp16sc* src, int16_t* dst, int32_t len, double scale);
HmppResult HMPPS_Magnitude_32sc_S(const Hmpp32sc* src, int32_t* dst, int32_t len, double scale);
HmppResult HMPPS_Magnitude_16s_S(const int16_t *srcRe, const int16_t *srcIm, int16_t *dst, int32_t len, double scale);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the 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 |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
len |
Vector length |
scale = 2^n, where n is an integer. The value is within (0, INF). |
Input |
scale |
Scale factor |
[INT_MIN, INT_MAX] |
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 or dst is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 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 MagnitudeExample(void) {
float srcRe[BUFFER_SIZE_T] = {-0.10, 0.47, 11.54, 7.41, 9.14,
6.89, 2.73, 8.15, 9.29, 7.94};
float srcIm[BUFFER_SIZE_T] = {7.10, 3.12, 6.47, 3.87, 9.18,
8.64, 2.00, -1.04, 6.34, 5.19};
float dst[BUFFER_SIZE_T];
int32_t i;
HmppResult result = HMPPS_Magnitude_32f(srcRe, srcIm, dst, BUFFER_SIZE_T);
printf("result = %d \n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("dst =");
for (i = 0; i < BUFFER_SIZE_T; i++) {
printf(" %.2f ", dst[i]);
}
}
Output:
return = 0 dst = 7.10 3.16 13.23 8.36 12.95 11.05 3.38 8.22 11.25 9.49