FIRMR
Performs multi-rate FIR filtering on a source vector.
Calculates the related linear point product of taps vector (the length is tapsLen), src vector (the length is numIters x downFactor), and dlySrc vector (the length is (tapsLen + upFactor - 1)/upFactor). The destination vector is stored in the dst vector, and the destination delay line vector is stored in dlyDst.
The formula is developed from the formula for FIRSR and defined as follows:
;
;
;
.
In the preceding formula:
- src is the combination of the delay line vector and the source vector.
- tapsN is a two-dimensional array of a specific sequence formed by FIR filter coefficients.
- upFactor is the factor by which the filtered signal is internally sampled. That is, upFactor - 1 zeros are inserted between each sample of the input signal.
- upPhase is the offset phase of a non-zero sample in the upFactor-length block of the upsampled input signal.
- downFactor is the factor by which the FIR response is internally downsampled. That is, downFactor – 1 output samples are discarded from each downFactor-length output block of the upsampled filter response.
- downPhase is the offset phase of a non-discarded sample in the block of the upsampled filter response.
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 FIRMR function calling process is 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_FIRMRInit_32f(const float *taps, int32_t tapsLen, int32_t upFactor, int32_t upPhase, int32_t downFactor, int32_t downPhase, HmppsFIRPolicy_32f **policy);
HmppResult HMPPS_FIRMRInit_64f(const double *taps, int32_t tapsLen, int32_t upFactor, int32_t upPhase, int32_t downFactor, int32_t downPhase, HmppsFIRPolicy_64f **policy);
HmppResult HMPPS_FIRMRInit_32fc(const Hmpp32fc *taps, int32_t tapsLen, int32_t upFactor, int32_t upPhase, int32_t downFactor, int32_t downPhase, HmppsFIRPolicy_32fc **policy);
HmppResult HMPPS_FIRMRInit_64fc(const Hmpp64fc *taps, int32_t tapsLen, int32_t upFactor, int32_t upPhase, int32_t downFactor, int32_t downPhase, HmppsFIRPolicy_64fc **policy);
HmppResult HMPPS_FIRMRInit32f_32fc(const float *taps, int32_t tapsLen, int32_t upFactor, int32_t upPhase, int32_t downFactor, int32_t downPhase, HmppsFIRPolicy_32f **policy);
- Main functions:
HmppResult HMPPS_FIRMR_16s(const int16_t *src, int16_t *dst, int32_t numIters, HmppsFIRPolicy_32f *policy, const int16_t *dlySrc, int16_t *dlyDst);
HmppResult HMPPS_FIRMR_32f(const float *src, float *dst, int32_t numIters, HmppsFIRPolicy_32f *policy, const float *dlySrc, float *dlyDst);
HmppResult HMPPS_FIRMR_64f(const double *src, double *dst, int32_t numIters, HmppsFIRPolicy_64f *policy, const double *dlySrc, double *dlyDst);
HmppResult HMPPS_FIRMR_16sc(const Hmpp16sc *src, Hmpp16sc *dst, int32_t numIters, HmppsFIRPolicy_32fc *policy, const Hmpp16sc *dlySrc, Hmpp16sc *dlyDst);
HmppResult HMPPS_FIRMR_32fc(const Hmpp32fc *src, Hmpp32fc *dst, int32_t numIters, HmppsFIRPolicy_32fc *policy, const Hmpp32fc *dlySrc, Hmpp32fc *dlyDst);
HmppResult HMPPS_FIRMR_64fc(const Hmpp64fc *src, Hmpp64fc *dst, int32_t numIters, HmppsFIRPolicy_64fc *policy, const Hmpp64fc *dlySrc, Hmpp64fc *dlyDst);
HmppResult HMPPS_FIRMR32f_32fc(const Hmpp32fc *src, Hmpp32fc *dst, int32_t numIters, HmppsFIRPolicy_32f *policy, const Hmpp32fc *dlySrc, Hmpp32fc *dlyDst);
- Memory release:
HmppResult HMPPS_FIRMRRelease_32f(HmppsFIRPolicy_32f *policy);
HmppResult HMPPS_FIRMRRelease_64f(HmppsFIRPolicy_64f *policy);
HmppResult HMPPS_FIRMRRelease_32fc(HmppsFIRPolicy_32fc *policy);
HmppResult HMPPS_FIRMRRelease_64fc(HmppsFIRPolicy_64fc *policy);
HmppResult HMPPS_FIRMRRelease32f_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 |
upFactor |
Multi-rate upsampling factor |
(0, INT_MAX] |
Input |
upPhase |
Phase of the upsampling signal |
[0, upFactor] |
Input |
downFacor |
Multi-rate downsampling factor |
(0, INT_MAX] |
Input |
downPhase |
Phase of the downsampling signal |
[0, downFacor] |
Input |
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
numIters |
Number of iterations associated with the number of samples filtered by the function. The (numIters * downFactor) elements of the source vector are filtered and the resulting (numIter * upFactor) samples are stored in the destination array. |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
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 + upFactor - 1)/upFactor. |
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 + upFactor - 1)/upFactor. |
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 numIters is less than or equal to 0. |
HMPP_STS_OVERFLOW_ERR |
The function overflows. |
HMPP_STS_FIRMR_FACTOR_ERR |
The sampling factor is less than or equal to 0. |
HMPP_STS_FIRMR_PHASE_ERR |
The phase is less than 0 or the factor is less than the phase. |
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 UP_FACTOR_SIZE_S 5
#define UP_PHASE_SIZE_S 4
#define DOWN_FACTOR_SIZE_S 3
#define DOWN_PHASE_SIZE_S 2
#define NUM_ITERS_SIZE_S 2
void FIRMRExample(void)
{
int32_t tapsLen = TPAS_SIZE_S;
int32_t upFactor = UP_FACTOR_SIZE_S;
int32_t upPhase = UP_PHASE_SIZE_S;
int32_t downFacor = DOWN_FACTOR_SIZE_S;
int32_t downPhase = DOWN_PHASE_SIZE_S;
int32_t numIters = NUM_ITERS_SIZE_S;
float taps[TPAS_SIZE_S] = { -0.023, -3.1463, 35.5304, -0.0622, 0.2213, 0.0127, 0.0183, 59.8159 };
float src[NUM_ITERS_SIZE_S * DOWN_FACTOR_SIZE_S] = { 0.3065, -1.8737, -58.7455, 155.8426, -0.0294, 4.3917 };
float dlySrc[(TPAS_SIZE_S + UP_FACTOR_SIZE_S - 1) / UP_FACTOR_SIZE_S] = { 0.2107, -40.6842};
float dst[NUM_ITERS_SIZE_S * UP_FACTOR_SIZE_S] = { 0.0f };
float dlyDst[TPAS_SIZE_S - 1] = { 0.0f };
HmppsFIRPolicy_32f *policy = NULL;
HmppResult result;
result = HMPPS_FIRMRInit_32f(taps, tapsLen, upFactor, upPhase, downFacor, downPhase, &policy);
printf("HMPPS_FIRMRInit_32f result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
result = HMPPS_FIRMR_32f(src, dst, numIters, policy, dlySrc, dlyDst);
printf("HMPPS_FIRMR_32f result = %d\n", result);
HMPPS_FIRMRRelease_32f(policy);
policy = NULL;
if (result != HMPP_STS_NO_ERR) {
return;
}
int32_t i;
int32_t dstLen = numIters * upFactor;
int32_t dlyLen = (tapsLen + upFactor - 1) / upFactor;
printf("dstLen = %d\ndst =", dstLen);
for(i = 0; i < dstLen; ++i){
printf(" %f", dst[i]);
}
printf("\ndlyDstLen = %d\ndst2 =", dlyLen);
for(i = 0; i < dlyLen; ++i){
printf(" %f", dlyDst[i]);
}
printf("\n");
}
Output:
HMPPS_FIRMRInit_32f result = 0 HMPPS_FIRMR_32f result = 0 dstLen = 10 dst = 2.530557 -1.708862 0.067828 -48.239738 1.327350 3.653970 -491.402649 34.487968 9320.820312 -0.101382 dlyDstLen = 2 dst2 = -0.029400 4.391700