⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 数字带通滤波器的设计过程。共3个源程序。其中
💻 CPP
字号:
/*
主程序,能实现两个输入X(n)与h(n)的卷积,输出结果Y(n),
并将其存储在"y.txt"文本中。
程序中的注释之间为程序运行时,显示h(n)及X(n)的结果在屏幕上的部分程序,
可以根据用户的需要进行显示或屏蔽。
*/
#include "stdio.h"
#include "dos.h"
#include "conio.h"
#include "firwin.c"
main()
{
 double x[2000],h[200],y[1800],fln,fhn,fs;
 int i=0;
 int j,n,n2;
 FILE *fp1,*fp2,*fp3;
 printf("input the filter order n:\n");
 scanf("%d",&n);
 printf("input low frequency fln:\n");
 scanf("%lf",&fln);
 printf("input high frequency fhn:\n");
 scanf("%lf",&fhn);
 printf("input sample frequency fs:\n");
 scanf("%lf",&fs);
 fln=fln/fs;
 fhn=fhn/fs;
 firwin(n,fln,fhn,h);
/******************
 for(i=0;i<n;i++)
 printf("h[%d]=%lf\n",i,h[i]);
******************/
 /*****************
 if((fp3=fopen("h.txt","w"))==NULL)
  {
    printf("can not open 'h.txt'!\n");
    exit(0);
   }
 for(i=0;i<n;i++)
 fprintf(fp3,"%lf\n",h[i]);
 fclose(fp3);
 printf("h[n] is right!\n");
 ******************/
i=0;
if((fp1=fopen("x.txt","r"))==NULL) /***get the data from '*.txt'!!***/
 {
  printf("cannot open file 'x.txt'!\n");
  exit(0);
 }
 while(fscanf(fp1,"%lf",&x[i])!=EOF)
 i++;
fclose(fp1);
/***********
for(i=0;i<1500;i++)
printf("x[%d]=%lf",i,x[i]);
***********/
for(i=0;i<200;i++)
   h[i]=h[199-i];
for(j=0;j<1800;j++)
{
   y[j]=0.0;
   for(i=0;i<200;i++)
    {
      y[j]+=x[j+i]*h[i];
    }
 printf("y[%d]=%lf",j,y[j]);
}
if((fp2=fopen("y.txt","w"))==NULL)
 {
    printf("cannot open file 'y.txt'!\n");
    exit(0);
 }
for(i=0;i<1800;i++)
fprintf(fp2,"%12.6lf\n",y[i]);
fclose(fp2);
printf("\nready!\n ");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -