-
Notifications
You must be signed in to change notification settings - Fork 110
/
p_firdec.c
42 lines (40 loc) · 1.02 KB
/
p_firdec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <pal.h>
/**
* Computes a decimating FIR filter (direct-form) on input data 'x' using
* coefficient stored in 'h' and places result in 'r'. This function
* retains the address of the delay filter memory containing the previous
* delayed values to allow consecutive processing of blocks.
*
* @param x Pointer to input vector of 'n' elements
*
* @param h Pointer to filter coefficients.
*
* @param r Pointer to result vector of size nx/d.
*
* @param nx The number of input samples
*
* @param nh The number of coefficients of the filter.
*
* @param df Decimation factor. (1 output sample per 'd' input samples)
*
* @return None
*
*/
void p_firdec_f32(const float *x, const float *h, float *r,
int nx, int nh, int df)
{
int t;
int i;
for (t = 0; t < nh; ++t)
{
r[t] = 0;
for (i = 0; i <= t && t * df < nx; ++i)
r[t] += h[i] * x[t * df - i];
}
for (t = nh; t < nx; ++t)
{
r[t] = 0;
for (i = 0; i < nh && t * df < nx; ++i)
r[t] += h[i] * x[t * df - i];
}
}