物探论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 685|回复: 0

线性卷积c程序

[复制链接]
发表于 2013-2-25 19:02:23 | 显示全部楼层 |阅读模式
#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[j]*h[k];
}
}
}
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[m]={1,1,1};
float h[n]={1,1,1};
float y[l];
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);
}




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|物探论坛 ( 鄂ICP备12002012号 微信号:iwutan )

GMT+8, 2024-5-2 14:59 , Processed in 0.116636 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表