<span style="color:red"> This blog is out of date. Check out my new blog holder: <a href='https://sonictl.github.io'>sonictl.github.io</a></span>
<span style="color:red"> 本网站上的博文已经停止维护/更新了。 请移步到新的博客空间:<a href='https://sonictl.github.io'>sonictl.github.io</a></span>
直接型FIR滤波器的C语言实现
设输入数据x[N],输出数据y[N],滤波器系数h[n]
1.直接法(由y(m)=h(0)*x(m)+h(1)*x(m-1)+...+h(N-1)*x(m-n-1));
void fir(short x[], short h[], short y[])
{
int i,j;
long long sum;
for (j = 0; j < N; j++)
{
sum = 0;
for (i = 0; i < n; i++)
sum += x[j-i] * h[i];
y[j] = sum >> 15;
}
}
乘法器使用次数:N*n
2.逆推法:
void fir(short x[], short h[], short y[])
{
int i,j;
long sum;
for (j = 0; j < n; j++)
{
for (i = 0; i < N; i++)
{
sum = 0;
sum = h[j] * x[i]
y[i] += sum >> 15;
}
}
}
乘法器使用次数:N*n
3.倒序法:(输入输出可以是同一量)
void fir(short x[], short h[], short y[])
{
int i,j;
long long sum;
for (j = N; j > 0; j--)
{
sum = 0;
for (i = n; i > 0; i--)
sum += x[j-i] * h[i];
y[j] = sum >> 15;
}
}