加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

一般卷积实现程序

(2022-11-11 16:27:05)
标签:

上机作业二(1)

分类: 《信号分析与处理》课
#include "stdio.h"
#define MM 501
#define NN 501
#define LL MM+NN-1
main()
{ void conv();
  float x[MM],h[NN],y[LL];
  char fx[60],fh[60],fy[60];
  float dt;
  int m,n,l;
  int i;
  FILE *fp1,*fp2,*fp3;
  printf("Please input file name of x(t)\n");
  scanf("%s",fx);
  printf("Please input file name of h(t)\n");
  scanf("%s",fh);
  printf("Please input file name of y(t)\n");
  scanf("%s",fy);
  printf("Please input sample interval(dt>=0.002)\n");
  scanf("%f",&dt);
  m=n=(int)(1.0/dt+0.5)+1;
  l=m+n-1;
  printf("M=%d  N=%d  L=%d\n",m,n,l);
  fp1=fopen(fx,"w");
  for(i=0;i
    { x[i]=i*dt;
      fprintf(fp1,"%8.3f.4f\n",i*dt,x[i]);
    }
  fclose(fp1);
  fp2=fopen(fh,"w");
  for(i=0;i
    { h[i]=1.0;
      fprintf(fp2,"%8.3f.4f\n",i*dt,h[i]);
    }
  fclose(fp2);
  conv(x,m,h,n,y,l);
  fp3=fopen(fy,"w");
  for(i=0;i
    {
      fprintf(fp3,"%8.3f.4f\n",i*dt,dt*y[i]);
    }
  fclose(fp3);
}
void conv(x,m,h,n,y,l)
float x[],h[],y[];
int m,n,l;
{ int k,i;
  for(k=0;k
    { y[k]=0.0;
      for(i=0;i
if(k-i>=0&&k-i<=n-1)y[k]=y[k]+x[i]*h[k-i];
    }
  return;
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有