#define N 10 // number of FIR coefficients.
#define BLKSIZE 20 // block size of samples filtered each time.
#define M (N + BLKSIZE - 1)
float workbuf[M] = {0}; // history + current input block, initialize to 0.
// float h[N]: array of fir filter coefficients.
// float x[BLKSIZE]: array of input samples block
// float y[BLKSIZE]: array of samples block after filtering
void fir(float h[N], float x[BLKSIZE], float y[BLKSIZE])
{
int i, j;
float *p;
// copy current input block to work buffer
// workbuf[N-1] = x[0], workbuf[N] = x[1],
// workbuf[N+1] = x[2], ..., workbuf[M-1] = x[BLKSIZE-1];
for (i=0; i<BLKSIZE; i++)
{
workbuf[i+N-1] = x;
}
// FIR filter loop
for (i=0; i<BLKSIZE; i++)
{
p = &workbuf[i+N-1];// each y needs right starting x.
for (j=0; j<N; j++)
{
y += (h[j] * (*p--));
}
}
// copy last N-1 samples of x[n] to workbuf
// as history for next block
p = &x[BLKSIZE-1]; // p points the last element;
for (i=0; i<N-1; i++)
{
workbuf[N-2-i] = *p--;
}
}
/////////////////////////////////////////////////
代码源自论坛
没看明白,滤波的结果大了将近一倍的样子。
疑问是:如果一个周期的采样数BLKSIZE远远小于滤波器系数的个数N。
那后面
s the last element;
for (i=0; i<N-1; i++)
workbuf[N-2-i] = *p--;
这句话怎么理解。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>