FIRSR
Performs single-rate finite impulse response (FIR) filtering on a source vector. The single-rate basic FIR filter IP core is a single-rate FIR filter (input sampling rate = output sampling rate).
Calculates the linear point product of the taps vector (the length is tapsLen), the src vector (the length is len), and the dlySrc vector (the length is tapsLen – 1). The destination vector is stored in the dst vector, and the delay line vector is stored in the dlyDst vector.
The calculation formula is as follows:
.
x(0)...x(numIters) is the source vector and h(0)...h(tapsLen – 1) are the FIR filter coefficients. To compute the destination vector y(0)...y(tapsLen – 1), this function uses the dly vector of the delay line.
Example:
y(0)= h(tapsLen-1)* d(0)+h(tapsLen-2)* d(1)+...+h(1)*d(tapsLen -2)+h(0)*x(0)
y(1)= h(tapsLen-1)* d(1)+h(tapsLen-2)* d(2)+... +h(2)*d(tapsLen -2)+h(1)*x(0)+h(0)*x(1)
y(tapsLen-1)= h(tapsLen-1)* x(0)+...+h(1)* x(tapsLen-2)+h(0)* x(tapsLen-1)
In the preceding formula:
- d(0), d(1), d(2), and d(tapsLen –2) are elements of the dlySrc vector.
- The dlySrc and dlyDst vectors support null values:
- If dlySrc is null, this function uses an all-zero delay line.
- If dlyDst is null, this function does not copy any data to the destination delay line.
The function is called as follows:
- Initialize the FIRPolicy structure by calling an initialization function.
- Call the main function.
- 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 declaration is as follows:
- Initialization:
HmppResult HMPPS_FIRSRInit_32f(const float *taps, int32_t tapsLen, int32_t len, HmppAlgMode algType, HmppsFIRPolicy_32f **policy);
HmppResult HMPPS_FIRSRInit_64f(const double *taps, int32_t tapsLen, int32_t len, HmppAlgMode algType, HmppsFIRPolicy_64f **policy);
HmppResult HMPPS_FIRSRInit_32fc(const Hmpp32fc *taps, int32_t tapsLen, int32_t len, HmppAlgMode algType, HmppsFIRPolicy_32fc **policy);
HmppResult HMPPS_FIRSRInit_64fc(const Hmpp64fc *taps, int32_t tapsLen, int32_t len, HmppAlgMode algType, HmppsFIRPolicy_64fc **policy);
HmppResult HMPPS_FIRSRInit32f_32fc(const float *taps, int32_t tapsLen, int32_t len, HmppAlgMode algType, HmppsFIRPolicy_32f **policy);
- Main functions:
HmppResult HMPPS_FIRSR_16s(const int16_t *src, int16_t *dst, int32_t len, HmppsFIRPolicy_32f *policy, const int16_t *dlySrc, int16_t *dlyDst);
HmppResult HMPPS_FIRSR_32f(const float *src, float *dst, int32_t len, HmppsFIRPolicy_32f *policy, const float *dlySrc, float *dlyDst);
HmppResult HMPPS_FIRSR_64f(const double *src, double *dst, int32_t len, HmppsFIRPolicy_64f *policy, const double *dlySrc, double *dlyDst);
HmppResult HMPPS_FIRSR_16sc(const Hmpp16sc *src, Hmpp16sc *dst, int32_t len, HmppsFIRPolicy_32fc *policy, const Hmpp16sc *dlySrc, Hmpp16sc *dlyDst);
HmppResult HMPPS_FIRSR_32fc(const Hmpp32fc *src, Hmpp32fc *dst, int32_t len, HmppsFIRPolicy_32fc *policy, const Hmpp32fc *dlySrc, Hmpp32fc *dlyDst);
HmppResult HMPPS_FIRSR_64fc(const Hmpp64fc *src, Hmpp64fc *dst, int32_t len, HmppsFIRPolicy_64fc *policy, const Hmpp64fc *dlySrc, Hmpp64fc *dlyDst);
HmppResult HMPPS_FIRSR32f_32fc(const Hmpp32fc *src, Hmpp32fc *dst, int32_t len, HmppsFIRPolicy_32f *policy, const Hmpp32fc *dlySrc, Hmpp32fc *dlyDst);
- Memory release:
HmppResult HMPPS_FIRSRRelease_32f(HmppsFIRPolicy_32f *policy);
HmppResult HMPPS_FIRSRRelease_64f(HmppsFIRPolicy_64f *policy);
HmppResult HMPPS_FIRSRRelease_32fc(HmppsFIRPolicy_32fc *policy);
HmppResult HMPPS_FIRSRRelease_64fc(HmppsFIRPolicy_64fc *policy);
HmppResult HMPPS_FIRSRRelease32f_32fc(HmppsFIRPolicy_32f *policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
taps |
Pointer to the filter coefficient |
The value cannot be NULL. |
Input |
tapsLen |
Length of the FIR filter coefficient |
(0, INT_MAX] |
Input |
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
len |
Number of elements in the source vector |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
algMode |
Algorithm model used for calculation. The value can be HMPP_ALG_AUTO, HMPP_ALG_DEFAULT or HMPP_ALG_FFT. |
HMPP_ALG_AUTO HMPP_ALG_DEFAULT HMPP_ALG_FFT |
Input |
dlySrc |
Pointer to the vector that contains the source delay line values |
The vector can be NULL. If the vector is not NULL, the array length is tapsLen - 1. |
Input |
dlyDst |
Pointer to the vector that contains the destination delay line values |
The vector can be NULL. If the vector is not NULL, the array length is tapsLen - 1. |
Output |
policy (in the Init function) |
Pointer to the memory that stores the pointer to FIRPolicy |
The value cannot be NULL. |
Output |
policy (in the main and release functions) |
Pointer to the FIRPolicy structure |
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 |
The value of tapsLen or len is less than or equal to 0. |
HMPP_STS_ALG_TYPE_ERR |
The value of algMode is not supported. |
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 FIRPolicy standard structure.
- The initialization of the FIRPolicy structure needs to be applied for in the Init function. You cannot apply for and define this structure by yourself.
- After the FIRPolicy structure has been initialized, if a main function fails to be executed, the Release function must be used to release the structure.
- src and dst cannot be the same array. Otherwise, the result may be incorrect.
Example
#define TPAS_SIZE_S 8
#define SRC_SIZE_S 7
void FIRSRExample(void)
{
float taps[TPAS_SIZE_S] = { -0.023, -3.1463, 35.5304, -0.0622, 0.2213, 0.0127, 0.0183, 59.8159 };
float src[SRC_SIZE_S] = { 0.3065, -1.8737, -58.7455, 155.8426, -0.0294, 4.3917, -195.6575 };
float dlySrc[TPAS_SIZE_S - 1] = { 0.2107, -40.6842, 17.1776, -15.6654, -2.407, -0.8981, 0.2883 };
float dst[SRC_SIZE_S] = { 0.0f };
float dlyDst[TPAS_SIZE_S - 1] = { 0.0f };
int32_t tapsLen = TPAS_SIZE_S;
int32_t len = SRC_SIZE_S;
HmppAlgMode algType = HMPP_ALG_AUTO;
HmppsFIRPolicy_32f *policy = NULL;
HmppResult result;
result = HMPPS_FIRSRInit_32f(taps, tapsLen, len, HMPP_ALG_AUTO, &policy);
printf("HMPPS_FIRSRInit_32f result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
result = HMPPS_FIRSR_32f(src, dst, len, policy, dlySrc, dlyDst);
printf("HMPPS_FIRSR_32f result = %d\n", result);
HMPPS_FIRSRRelease_32f(policy);
policy = NULL;
if (result != HMPP_STS_NO_ERR) {
return;
}
int32_t i;
printf("dstLen = %d\ndst =", len);
for(i = 0; i < len; ++i){
printf(" %f", dst[i]);
}
printf("\ndlyDstLen = %d\ndst2 =", TPAS_SIZE_S - 1);
for(i = 0; i < TPAS_SIZE_S - 1; ++i){
printf(" %f", dlyDst[i]);
}
printf("\n");
}
Output:
HMPPS_FIRSRInit_32f result = 0 HMPPS_FIRSR_32f result = 0 dstLen = 7 dst = -24.064171 -2424.601318 1045.096069 -822.377380 -2721.383057 5486.669434 -15.829129 dlyDstLen = 7 dst2 = 0.306500 -1.873700 -58.745499 155.842606 -0.029400 4.391700 -195.657501