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

IIRGen

Generates a low-pass or high-pass IIR filter.

HMPP can generate filters of the Butterworth and Chebyshev1 types. The Butterworth filter has a frequency response that is as flat as possible in the passband, and the Chebyshev1 filter has ripples in the passband.

The function interface is declared as follows:

HmppResult HMPPS_IIRGenLowpass_64f(double rFreq, double ripple, int order, double *pTaps, HmppsIIRFilterType filterType);

HmppResult HMPPS_IIRGenHighpass_64f(double rFreq, double ripple, int order, double *pTaps, HmppsIIRFilterType filterType);

Parameters

Parameter

Description

Value Range

Input/Output

rFreq

Cut-off frequency

(0, 0.5)

Input

ripple

Ripple when the filter type is HmppChebyshev1

(0, INT_MAX]. If the filter type is HmppChebyshev1, the value range is (0, 28].

Input

order

Order of the generated filter

[1, 12]

Input

filterType

Type of the generated filter

HmppButterworth or HmppChebyshev1

Input

pTaps

Taps of the generated filter

Not null

Output

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_GEN_ORDER_ERR

The generated order is beyond the range of [1, 12].

HMPP_STS_FILTER_FREQUENCY_ERR

The cut-off frequency is not within the range of (0, 0.5).

  • The filter type can only be HmppButterworth or HmppChebyshev1. Do not use other values. Otherwise, the result may be incorrect.
  • The convergence of an IIR filter is sensitive to the quantization error of tap a. Therefore, when using taps of the double type for single-precision computing, you need to confirm that the filter is converged.

Example

The following is the sample code for generating a high-pass filter and a low-pass filter using HMPP.

The high-pass filter is of the Butterworth type, order 9, 1000 Hz sampling frequency, and 400 Hz cut-off frequency. Equivalent code in MATLAB: [b,a] = butter(9,400/500,'high');

The low-pass filter is of the Chebyshev1 type, order 9, 1000 Hz sampling frequency, 400 Hz cut-off frequency, and 0.4 dB passband ripple. Equivalent code in MATLAB: [b,a] = cheby1(9, 0.4, 400/500);

#define ORDER 9
#define TAPS_LEN ((ORDER + 1) * 2)
void IIRGenExample() {
    HmppResult ret;
    double taps[TAPS_LEN];
    ret = HMPPS_IIRGenHighpass_64f(400.0 / 1000.0, 0, ORDER, taps, HmppButterworth);
    printf("IIRGenHighpass ret=%d\n", ret);
    for (int i = 0; i < TAPS_LEN; ++i) {
        printf("%lf ", taps[i]);
    }
    printf("\n");
 
    ret = HMPPS_IIRGenLowpass_64f(400.0 / 1000.0, 0.4, ORDER, taps, HmppChebyshev1);
    printf("IIRGenLowpass ret=%d\n", ret);
    for (int i = 0; i < TAPS_LEN; ++i) {
        printf("%lf ", taps[i]);
    }
    printf("\n");
}

Output:

IIRGenHighpass ret=0
0.000006 -0.000057 0.000229 -0.000534 0.000800 -0.000800 0.000534 -0.000229 0.000057 -0.000006 1.000000 5.386221 13.378550 19.961682 19.623982 13.137028 5.973215 1.775180 0.312381 0.024765 
IIRGenLowpass ret=0
0.080020 0.720182 2.880728 6.721698 10.082547 10.082547 6.721698 2.880728 0.720182 0.080020 1.000000 4.135535 8.510626 10.746179 9.121897 5.230419 1.958336 0.349120 -0.039936 -0.041825