IIRIIR
Initializes an IIR filter and performs zero-phase digital filtering on the input.
The filtering process is classified into forward filtering and inverse filtering. x(n) is stored in src, and the output y(n) is stored in dst. The following briefly explains zero-phase digital filtering.
Time-domain representation of a digital signal:




h(n) is the impulse response of a digital filter. The output sequence is obtained by removing L head signals and L tail signals from y4(n).
Frequency-domain representation:




Therefore, it can be deduced that:

That is, there is no phase offset between the output sequence and the input sequence.
order specifies the order of the forward filter and inverse filter. The length of the tap vector is 2 x (order + 1), and the elements are arranged as follows:

IIRIIRInit accepts a delay line vector whose length is order. The vector can be null. If it is null, an initial condition is generated for padding the delay line.
The function calling process is as follows:
- Call IIRIIRInit to perform initialization.
- Call IIRIIR to perform filtering.
- Call IIRIIRGetDlyLine or IIRIIRSetDlyLine to retrieve and set the delay line.
- Call IIRIIRRelease to release the memory requested by IIRIIRInit.
The function interface is declared as follows:
- Initialization:
HmppResult HMPPS_IIRIIRInit_32f(HmppsIIRPolicy_32f **policy, const float *taps, int order, const float *dlyLine);
HmppResult HMPPS_IIRIIRInit_64f(HmppsIIRPolicy_64f **policy, const double *taps, int order, const double *dlyLine);
- Obtaining the delay line:
HmppResult HMPPS_IIRIIRGetDlyLine_32f(const HmppsIIRPolicy_32f *policy, float *dlyLine);
HmppResult HMPPS_IIRIIRGetDlyLine_64f(const HmppsIIRPolicy_64f *policy, double *dlyLine);
- Setting the delay line:
HmppResult HMPPS_IIRIIRSetDlyLine_32f(HmppsIIRPolicy_32f *policy, const float *dlyLine);
HmppResult HMPPS_IIRIIRSetDlyLine_64f(HmppsIIRPolicy_64f *policy, const double *dlyLine);
- Filtering:
HmppResult HMPPS_IIRIIR_32f(const float *src, float *dst, int len, HmppsIIRPolicy_32f *policy);
HmppResult HMPPS_IIRIIR_64f(const double *src, double *dst, int len, HmppsIIRPolicy_64f *policy);
- Memory release:
HmppResult HMPPS_IIRIIRRelease_32f(HmppsIIRPolicy_32f *policy);
HmppResult HMPPS_IIRIIRRelease_64f(HmppsIIRPolicy_64f *policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
taps |
Pointer to filter taps |
Not null |
Input |
order |
Order of the IIR filter |
(0, INT_MAX] |
Input |
src |
Pointer to the source vector |
Not null |
Input |
dst |
Pointer to the destination vector |
Not null |
Output |
len |
Length of the source vector and destination vector |
[3 x order, INT_MAX] |
Input |
dlyLine (in the Init and setDly functions) |
Pointer to the delay line vector |
The vector can be null. If it is null, an initial condition is generated for padding the delay line. |
Input |
dlyLine (in the getDly function) |
Pointer to the delay line values |
Not null |
Output |
policy (in the Init function) |
Pointer to the pointer to the IIRIIRPolicy structure |
Not null |
Output |
policy (in the setDly function) |
Pointer to the IIRIIRPolicy structure |
Not null |
Input |
policy (in the filter and release functions) |
Pointer to the IIRIIRPolicy structure |
Not 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_LENGTh_ERR |
len ≤ 0 or len < 3 x order |
HMPP_STS_DIV_BY_ZERO_ERR |
Divide-by-zero error. |
HMPP_STS_CONTEXT_MATCH_ERR |
The policy state is incorrect (an incorrect Init function is used). |
HMPP_STS_MALLOC_FAILED |
The Init function failed to allocate the memory required by the algorithm model. |
- Before this interface is called for calculation, the Init interface must be called to initialize the IIRIIRPolicy standard structure.
- The initialization of the IIRIIRPolicy structure must be applied for in the Init function. You cannot apply for or define this structure by yourself.
- After the IIRIIRPolicy structure has been initialized, if the filtering operation fails, the Release function must be used to release the structure.
- IIRIIR requires the input data length of the filter be greater than or equal to 3 x order.
Example
#define ORDER 4
#define TAPS_LEN ( (ORDER + 1) * 2)
#define SRC_LEN 12
#define DLY_LEN ORDER
void IIRIIRExample(void) {
float taps[TAPS_LEN] = {0.0390, -0.1560, 0.2340, -0.1560, 0.0390, 1.0000, 0.9532, 0.7746, 0.2338, 0.0366};
float src[SRC_LEN] = {186, 431, 689, 206, 716, 90, 695, -153, 289, 291, 482, -21};
float dlySrc[DLY_LEN] = {123, 312, 781, 249};
float dlyDst[DLY_LEN];
float dst[SRC_LEN];
HmppsIIRPolicy_32f *policy = NULL;
HmppResult result;
result = HMPPS_IIRIIRInit_32f(&policy, taps, ORDER, dlySrc);
printf("HMPPS_IIRIIRInit_32f result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
result = HMPPS_IIRIIR_32f(src, dst, SRC_LEN, policy);
printf("HMPPS_IIRIIR_32f result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
int32_t i;
printf("dstLen = %d\ndst =", SRC_LEN);
for (i = 0; i < SRC_LEN; ++i) {
printf(" %f", dst[i]);
}
HMPPS_IIRIIRGetDlyLine_32f(policy, dlyDst);
printf("\ndlyDstLen = %d\ndlyDst =", DLY_LEN);
for (i = 0; i < DLY_LEN; ++i) {
printf(" %f", dlyDst[i]);
}
printf("\n");
HMPPS_IIRIIRRelease_32f(policy);
policy = NULL;
}
Output:
HMPPS_IIRIIRInit_32f result = 0 HMPPS_IIRIIR_32f result = 0 dstLen = 12 dst = 1265.131836 330.548798 -677.644104 32.452599 557.080872 -618.195129 370.672546 -161.901367 103.654419 -112.175522 88.226212 -16.978725 dlyDstLen = 4 dlyDst = -0.039000 0.117000 -0.117000 0.039000
