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

FIRLMS

Solves a filter and use the mean variance to correct the filter coefficient. The calculation of the main function involves two main procedures:

  1. Step 1: Obtain the result of dst. The formula is as follows:

    The dlyLine is added before src[0]. The following is an example:

    If the length of the src array (len) is 4 and the length of the taps array (tapsLen) is 3, the length of the dlyLine array is the value specified by tapsLen. The value range of dlyIndex is [0, tapsLen - 1].

    • If dlyIndex is 0, the actual src array can be regarded as dlyLine[1], dlyLine[2], src[0], src[1], src[2], and src[3].
    • If dlyIndex is 1, the actual src array can be regarded as dlyLine[2], dlyLine[0], src[0], src[1], src[2], and src[3].
    • If dlyIndex is 2, the actual src array can be regarded as dlyLine[0], dlyLine[1], src[0], src[1], src[2], and src[3].
  2. Step 2: Modify the taps array, that is, modify the filter coefficient. The formula is as follows:

    Each time a value of dst[n] is calculated, the value is used to update the taps array.

The function calling process is as follows:

  1. Initialize the FIRLMSPolicy structure by calling an initialization function.
  2. Call the main function.
  3. Obtain the modified filter array by calling GetTaps.
  4. Call Release to release the memory contained in the FIRPolicy function. (16s and 16sc use 32f and 32fc for initialization and release).

The function interface is declared as follows:

  • Obtaining the filter array:

    HmppResult HMPPS_FIRLMSGetTaps_32f(const HmppsFIRLMSPolicy_32f* policy, float *outTaps);

    HmppResult HMPPS_FIRLMSGetTaps32f_16s(const HmppsFIRLMSPolicy32f_16s* policy, float *outTaps);

  • Setting the delay line array and offset:

    HmppResult HMPPS_FIRLMSSetDlyLine_32f(HmppsFIRLMSPolicy_32f* policy, const float *dlyLine, int32_t dlyLineIndex);

    HmppResult HMPPS_FIRLMSSetDlyLine32f_16s(HmppsFIRLMSPolicy32f_16s* policy, const int16_t *dlyLine, int32_t dlyLineIndex);

  • Obtaining the delay line array and offset:

    HmppResult HMPPS_FIRLMSGetDlyLine_32f(const HmppsFIRLMSPolicy_32f* policy, float *dlyLine, int32_t *dlyLineIndex);

    HmppResult HMPPS_FIRLMSGetDlyLine32f_16s(const HmppsFIRLMSPolicy32f_16s* policy, int16_t *dlyLine, int32_t *dlyLineIndex);

  • Initialization:

    HmppResult HMPPS_FIRLMSInit_32f(HmppsFIRLMSPolicy_32f **policy, const float *taps, int32_t tapsLen, const float *dlyLine, int dlyLineIndex);

    HmppResult HMPPS_FIRLMSInit32f_16s(HmppsFIRLMSPolicy32f_16s **policy, const float *taps, int32_t tapsLen, const int16_t *dlyLine, int dlyLineIndex);

  • Main functions:

    HmppResult HMPPS_FIRLMS_32f(HmppsFIRLMSPolicy_32f *policy, const float *src, const float *ref, float *dst, int32_t len, float mu);

    HmppResult HMPPS_FIRLMS32f_16s(HmppsFIRLMSPolicy32f_16s *policy, const int16_t *src, const int16_t *ref, int16_t *dst, int32_t len, float mu);

  • Memory release:

    HmppResult HMPPS_FIRLMSRelease_32f(HmppsFIRLMSPolicy_32f *policy);

    HmppResult HMPPS_FIRLMSRelease32f_16s(HmppsFIRLMSPolicy32f_16s *policy);

Parameters

Parameter

Description

Value Range

Input/Output

src

Pointer to the source vector

The value cannot be NULL.

Input

ref

Pointer to the reference vector

The value cannot be NULL.

Input

dst

Pointer to the destination vector

The value cannot be NULL.

Output

len

Length of the source vector, reference vector, and destination vector

(0, INT_MAX]

Input

taps

Pointer to the filter vector

taps can be NULL in the Init function.

Input

tapsLen

Length of the filter vector

(0, INT_MAX]

Input

dlyLine

Pointer to the delay line vector

This parameter cannot be NULL in SetDIyLine.

This parameter can be NULL in the Init function.

Input

dlyLineIndex

Offset of the start element of the delay line

[INT_MIN, INT_MAX]

The actual value is mapped to [0, tapsLen)

Input

policy (in the Init function)

Pointer to the memory that stores the pointer to FIRLMSPolicy

The value cannot be NULL.

Output

policy (in the main and release functions)

Pointer to the DFTPolicy structure

The value cannot be NULL.

Input/Output

mu

Filter adaptation coefficient

Float type. The value needs to be adjusted based on the actual data.

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 len is less than or equal to 0.

HMPP_STS_FIR_LEN_ERR

The value of tapsLen is less than or equal to 0.

HMPPS_STS_POLICY_STATE_ERR

The status identifier of the policy structure is incorrect.

HMPP_STS_MALLOC_FAILED

Memory allocation failed.

Note

  • Before this interface is called for calculation, the Init interface must be called to initialize the FIRLMS standard structure.
  • The initialization of the FIRLMSPolicy structure needs to be applied for in the Init function. You cannot apply for or define this structure by yourself.
  • After the FIRLMSPolicy structure has been initialized, if a main function fails to be executed, the Release function must be used to release the structure.
  • After the main function is successfully called, the GetTaps function needs to be called to obtain the latest filter array from the policy.
  • src and dst cannot be the same array. Otherwise, the result may be incorrect.

Example

void FIRLMSExample(void)
{
    const int tapsLen = 7;
    const int len = 32;
    float src[len] = { 0.15275501, 0.143135, 0.31686401, 0.26976699, 0.72030699, 0.50592899, 0.486655, 0.706716, 0.68356198, 0.77510101, 
                              0.94214898, 1.05799, 1.29482, 1.14037, 1.43979, 1.44664, 1.55493, 1.57329, 1.68367, 1.70401, 1.85473, 1.86356, 
                              2.2176099, 2.1915801, 2.24248, 2.1015699, 2.25688, 2.26349, 2.5790999, 2.6948299, 2.4193299, 2.69561 };
    float ref[len];
    float dst[len];
    float taps[tapsLen];
    float mu = 0.0005;
    for (int i = 0; i < tapsLen; ++i) {
        taps[i] = 1.0 / tapsLen;
    }
    HmppsFIRLMSPolicy_32f *policy = NULL;

    HmppResult result = HMPPS_FIRLMSInit_32f(&policy, taps, tapsLen, NULL, 0);
    if (result != HMPP_STS_NO_ERR) {
        printf("HMPPS_FIRLMSInit_32f result = %d\n", result);
        return;
    }
    result = HMPPS_FIRLMS_32f(policy, src, ref, dst, len, mu);
    if (result != HMPP_STS_NO_ERR) {
        printf("HMPPS_FIRLMS_32f result = %d\n", result);
        return;
    }
    printf("Dst: ");
    for (int i = 0; i < len; ++i) {
        printf("%f ", dst[i]);
    }
    printf("\n");
    result = HMPPS_FIRLMSGetTaps_32f(policy, taps);
    if (result != HMPP_STS_NO_ERR) {
        printf("HMPPS_FIRLMSGetTaps_32f result = %d\n", result);
        return;
    }
    printf("Taps: ");
    for (int i = 0; i < tapsLen; ++i) {
        printf("%f ", taps[i]);
    }
    printf("\n");
    HMPPS_FIRLMSRelease_32f(policy);
}

Output:

Dst: 0.021822 0.042269 0.087532 0.126056 0.228895 0.297082 0.365800 0.443564 0.519442 0.570626 0.661690 0.704063 0.808335 0.893767 0.985927 1.080792 1.174086 1.177286 1.238281 1.184714 1.245834 1.165491 1.215122 1.248639 1.280253 1.287248 1.300077 1.297933 1.313811 1.096912 1.071277 0.833319
Taps: 0.031206 0.038017 0.041954 0.050642 0.050239 0.060425 0.061261