Rate This Document
Findability
Accuracy
Completeness
Readability

ZeroCrossing

Calculates the number of zero crossings of a vector.

The calculation mode is specified by the zcType parameter. The calculation result is saved in the address pointed to by pValZC. The calculation modes are as follows:

  • When ZCType = HMPPZCR, the calculation formula is:

  • When ZCType = HMPPZCXor, the calculation formula is:

  • When ZCType = HMPPZCC, the calculation formula is:

The declaration of the interface function is as follows:

HmppResult HMPPS_ZeroCrossing_16s32f(const int16_t *src, uint32_t len, float *valZcr, HmppZCType zcType);

HmppResult HMPPS_ZeroCrossing_32f(const float *src, uint32_t len, float *valZcr, HmppZCType zcType);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source vector

The value cannot be NULL.

Input

valZcr

Pointer to the calculation result

The value cannot be NULL.

Output

zcType

Mode of calculating zero crossings

HMPPZCR, HMPPZCXor, HMPPZCC

Input

len

Vector length

Positive number

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 input parameter src or valZCR contains null pointers.

HMPP_STS_SIZE_ERR

The value of len is 0.

HMPP_STS_RANGE_ERR

zcType is an invalid value.

Important Notes

When calling a function, ensure that the value type of len is unsigned and not a negative number.

Example

#define BUFFER_SIZE_T 10

void ZeroCrossingExample(void)
{
    float src[BUFFER_SIZE_T] = {1.64, 1.63, -1.09, 0.71, -3.20, -0.43, 0.41, -4.83, 5.36, -4.40};
    float valZCR[BUFFER_SIZE_T];
    (void)HMPPS_Zero_32f(valZCR, BUFFER_SIZE_T); //Initialize all elements of valZCR to 0.
    HmppZCType HmppZCR = HMPP_ZCR;

    HmppResult result = HMPPS_ZeroCrossing_32f(src, 10, valZCR, HmppZCR);
    printf("result = %d.\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("valZCR =");
    for (int i = 0; i < BUFFER_SIZE_T; i++) {
        printf(" %.2f", valZCR[i]);
    }
    printf("\n");
}

Output:

result = 0.
valZCR = 7.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00