天涯 发表于 2013-2-25 19:02:23

线性卷积c程序


#include<stdio.h>
/* y(n)=x(n)*h(n)
m--length of x(n);
n--length of h(n);
l=m+n-1 length of y(n)
*/
void conv(float x[],int m,float h[],int n,float y[],int l)
{
int i,j,k;
for(i=0; i<l; i++)
{
y=0.0;
for(j=0; j<m; j++)
{ k=i-j;
if(k>=0 && k<n)
y += x*h;
}
}
}
void main()
{
const int m=3;
const int n=3;
const int l=m+n-1;
const int a1=0;//x(n)左下标
const int a2=2;//x(n)右下标
const int b1=4;//h(n)左下标
const int b2=6;//h(n)右下标
int c1;//卷积结果序列的左下标
int c2;//卷积结果序列的右下标
int i;
float x={1,1,1};
float h={1,1,1};
float y;
c1=a1+b1;
c2=a2+b2;
conv(x,m,h,n,y,l);
printf("result:\n");
for(i=0; i<l; i++)
printf("y(%d)=%f\n",c1+i,y);
}




页: [1]
查看完整版本: 线性卷积c程序