FIR滤波器的C语言程序
解决时间 2021-02-20 01:53
- 提问者网友:沉默的哀伤
- 2021-02-19 16:35
#include
#define length 256
int input[length],output[length];
static int filter(int xin[],int xout[],int n, int h[]);
static void dataIO(void);
static int h[37]={ -78,-152,-210,-173,18,355,737,983,903,413,-374,
-1139,-1443,-910,582,2792,5154,6963,7640,6963,5154,2792,582,-910,
-1443,-1139,-374,413,903,983,737,355,18,-173,-210,-152,-78};
static int x1[length+37];
static int filter(int indata[],int outdata[],int n,int h[])
{
int i,j;
long sum;
for(i=0;i x1[n+i-1]=indata[i];
for(i=0;i<(n-1);i++)
x1[n-i-2]=indata[length-i-1];
for(i=0;i {
sum=0;
for(j=0;j sum+=(long)h[j]*x1[i-j+n-1];
outdata[i]=sum>>15;
}
return 1;
}
void main()
{
while(1)
{
dataIO();
filter(input,output,19,h);
}
}
static void dataIO()
{
return;
}
谁能告诉我程序第二行的length是啥意思?是我这组需要滤波数据的个数么??
最佳答案
- 五星知识达人网友:青尢
- 2021-02-19 17:21
length==256
全部回答
short h[], short y[])
{
int i, j, sum; for (j = 0; j < 100; j++) {
sum = 0;
for (i = 0; i < 32; i++)
sum += x[i+j] * h[i];
y[j] = sum >> 15;
}
}
2
void fir(short x[], short h[], short y[])
{
int i, j, sum0, sum1;
short x0,x1,h0,h1; for (j = 0; j < 100; j+=2) {
sum0 = 0;
sum1 = 0;
x0 = x[j];
for (i = 0; i < 32; i+=2){
x1 = x[j+i+1];
h0 = h[i];
sum0 += x0 * h0;
sum1 += x1 * h0;
x0 = x[j+i+2];
h1 = h[i+1];
sum0 += x1 * h1;
sum1 += x0 * h1;
}
y[j] = sum0 >> 15;
y[j+1] = sum1 >> 15;
}
}
3
void fir(short x[], short h[], short y[])
{
int i, j, sum0, sum1;
short x0,x1,x2,x3,x4,x5,x6,x7,h0,h1,h2,h3,h4,h5,h6,h7; for (j = 0; j < 100; j+=2) {
sum0 = 0;
sum1 = 0;
x0 = x[j];
for (i = 0; i < 32; i+=8){
x1 = x[j+i+1];
h0 = h[i];
sum0 += x0 * h0;
sum1 += x1 * h0;
x2 = x[j+i+2];
h1 = h[i+1];
sum0 += x1 * h1;
sum1 += x2 * h1;
x3 = x[j+i+3];
h2 = h[i+2];
sum0 += x2 * h2;
sum1 += x3 * h2;
x4 = x[j+i+4];
h3 = h[i+3];
sum0 += x3 * h3;
sum1 += x4 * h3;
x5 = x[j+i+5];
h4 = h[i+4];
sum0 += x4 * h4;
sum1 += x5 * h4;
x6 = x[j+i+6];
h5 = h[i+5];
sum0 += x5 * h5;
sum1 += x6 * h5;
x7 = x[j+i+7];
h6 = h[i+6];
sum0 += x6 * h6;
sum1 += x7 * h6;
x0 = x[j+i+8];
h7 = h[i+7];
sum0 += x7 * h7;
sum1 += x0 * h7;
}
y[j] = sum0 >> 15;
y[j+1] = sum1 >> 15;
}
}
我要举报
大家都在看
推荐资讯