FIRGen
Generates finite filter coefficients by windowing infinite filter coefficients. The low-pass, high-pass, band-pass, and band-stop filter coefficients are supported. The supported windows are the Bartlett window, Blackman window, Hamming window, and Hann window.
This function computes the len coefficients h(n) for the FIR filter with the cutoff frequency freq(F) by converting ideal infinite filter coefficients hd(n) via windowing window(n).
The main formula is as follows:
.
For details about windowing, see the HMPP windowing functions.
.
The formula for the low-pass time domain is as follows:

The formula for the high-pass time domain is as follows:


The formula for the band-pass time domain is as follows:

The formula for the band-stop time domain is as follows:

The normalization formula for the low-pass time domain is as follows:

The normalization formula for the high-pass time domain is as follows:

The normalization formula for the band-pass time domain is as follows:

The normalization formula for the band-stop time domain is as follows:

The FIRGen function calling process is as follows:
- Initialize the buffer by calling Init.
- Call the main function.
- Release the buffer by calling Release.
The function interface is declared as follows:
- Initialization:
HmppResult HMPPS_FIRGenInit_64f(int32_t tapsLen, uint8_t **buffer);
- Main functions:
HmppResult HMPPS_FIRGenLowpass_64f(double freq, double *taps, int32_t tapsLen, HmppWinType winType, HmppBool doNormal, uint8_t *buffer);
HmppResult HMPPS_FIRGenHighpass_64f(double freq, double *taps, int32_t tapsLen, HmppWinType winType, HmppBool doNormal, uint8_t *buffer);
HmppResult HMPPS_FIRGenBandpass_64f(double freqLow, double freqHigh, double *taps, int32_t tapsLen, HmppWinType winType, HmppBool doNormal, uint8_t *buffer);
HmppResult HMPPS_FIRGenBandstop_64f(double freqLow, double freqHigh, double *taps, int32_t tapsLen, HmppWinType winType, HmppBool doNormal, uint8_t *buffer);
- Memory release:
HmppResult HMPPS_FIRGenRelease(uint8_t *buffer);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
tapsLen |
Length of the finite filter coefficient |
[5, INT_MAX] |
Input |
freq |
Cut-off frequency |
(0, 0.5) |
Input |
freqLow |
Low cut-off frequency |
(0, 0.5) and less than the value of freqHigh |
Input |
freqHigh |
High cut-off frequency |
(0, 0.5) and greater than the value of freqLow |
Input |
taps |
Pointer to the vector that stores calculated tap values |
The value cannot be NULL. |
Output |
winType |
Window type used in the computation |
HMPP_WIN_BARTLETT, HMPP_WIN_BLACKMAN, HMPP_WIN_HAMMING, or HMPP_WIN_HANN |
Input |
doNormal |
Whether to normalize filter coefficients |
HMPP_TRUE or HMPP_FALSE |
Input |
buffer (in the Init function) |
Pointer to the memory that stores the pointer to the buffer |
The value cannot be NULL. |
Output |
buffer (in the main and release functions) |
Pointer to the buffer |
The value cannot be 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_SIZE_ERR |
|
HMPP_STS_WIN_TYPE_ERR |
The window type is incorrect. |
HMPP_STS_OVERFLOW |
The function overflows. |
HMPP_STS_MALLOC_FAILED |
The Init function failed to allocate the memory required by the algorithm model. |
Note
- Before this interface is called for calculation, the Init interface must be called to initialize the buffer standard structure.
- After the buffer structure has been initialized, if a main function fails to be executed, the Release function must be used to release the buffer structure.
Example
#define TPAS_LEN_S 8
void FIRGenBandpassExample(void)
{
int32_t tapsLen = TPAS_LEN_S;
double freqLow = 0.05;
double freqHigh = 0.48;
HmppWinType winType = HMPP_WIN_BARTLETT;
HmppBool doNormal = HMPP_TRUE;
double taps[TPAS_LEN_S] = { 0.0 };
uint8_t *buffer = NULL;
HmppResult result;
result = HMPPS_FIRGenInit_64f(tapsLen, &buffer);
printf("HMPPS_FIRGenInit_64f result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
result = HMPPS_FIRGenBandpass_64f(freqLow, freqHigh, taps, tapsLen, winType, doNormal, buffer);
printf("HMPPS_FIRGenBandpass_64f result = %d\n", result);
HMPPS_FIRGenRelease(buffer);
buffer = NULL;
if (result != HMPP_STS_NO_ERR) {
return;
}
int32_t i;
printf("tapsLen = %d\ntaps =", tapsLen);
for(i = 0; i < tapsLen; ++i){
printf(" %f", taps[i]);
}
printf("\n");
}
Output:
HMPPS_FIRGenInit_64f result = 0 HMPPS_FIRGenBandpass_64f result = 0 tapsLen = 8 taps = -0.000000 0.010000 -0.196259 0.517494 0.517494 -0.196259 0.010000 -0.000000