永发信息网

二阶通用滤波器用C语言怎么编程

答案:2  悬赏:70  手机版
解决时间 2021-02-07 16:17
  • 提问者网友:战皆罪
  • 2021-02-07 09:14
二阶通用滤波器用C语言怎么编程
最佳答案
  • 五星知识达人网友:蓝房子
  • 2021-02-07 09:52
shorth[],shorty[]){inti,j,sum;for(j=0;j>15;}}2voidfir(shortx[],shorth[],shorty[]){inti,j,sum0,sum1;shortx0,x1,h0,h1;for(j=0;j>15;y[j+1]=sum1>>15;}}3voidfir(shortx[],shorth[],shorty[]){inti,j,sum0,sum1;shortx0,x1,x2,x3,x4,x5,x6,x7,h0,h1,h2,h3,h4,h5,h6,h7;for(j=0;j>15;y[j+1]=sum1>>15;}}
全部回答
  • 1楼网友:未来江山和你
  • 2021-02-07 11:09
这个可比你想象的复杂多了,s是个复变量,1/(s+1)极点在-1,要想用c语言写,必须理解清楚下面几个问题: 1、输入必须是个有限序列,比如(x+yi),x和y分别是两个长度为n的数组 2、要过滤的频率,必须是个整型值,或者是个整型区间 3、输出结果同样是两个长度为n的数组(p+qi) 4、整个程序需要使用最基本的复数运算,这一点c语言本身不提供,必须手工写复函数运算库 5、实现的时候具体算法还需要编,这里才是你问题的核心。 我可以送你一段fft的程序,自己琢磨吧,和matlab的概念差别很大: #include #include #include #include #include #include #include "complex.h" extern "c" { // discrete fourier transform (basic version, without any enhancement) // return - without special meaning, constantly, zero int dft (long count, ccomplex * input, ccomplex * output) { assert(count); assert(input); assert(output); ccomplex f, x, t, w; int n, i; long n = abs(count); long inversing = count < 0? 1: -1; for(n = 0; n < n ; n++){ // compute from line 0 to n-1 f = ccomplex(0.0f, 0.0f); // clear a line for(i = 0; i < n; i++) { t = input[i]; w = harmonicpi2(inversing * n * i, n); x = t * w; f += x; // fininshing a line }//next i // save data to outpus memcpy(output + n, &f, sizeof(f)); }//next n return 0; }//end dft int fft (long count, ccomplex * input, ccomplex * output) { assert(count); assert(input); assert(output); int n = abs(count); long inversing = count < 0? -1: 1; if (n % 2 || n < 5) return dft(count, input, output); long n2 = n / 2; ccomplex * ieven = new ccomplex[n2]; memset(ieven, 0, sizeof(ccomplex) * n2); ccomplex * oeven = new ccomplex[n2]; memset(oeven, 0, sizeof(ccomplex) * n2); ccomplex * iodd = new ccomplex[n2]; memset(iodd , 0, sizeof(ccomplex) * n2); ccomplex * oodd = new ccomplex[n2]; memset(oodd , 0, sizeof(ccomplex) * n2); int i = 0; ccomplex w; for(i = 0; i < n2; i++) { ieven[i] = input[i * 2]; iodd [i] = input[i * 2 + 1]; }//next i fft(n2 * inversing, ieven, oeven); fft(n2 * inversing, iodd, oodd ); for(i = 0; i < n2; i++) { w = harmonicpi2(inversing * (- i), n); output[i] = oeven[i] + w * oodd[i]; output[i + n2] = oeven[i] - w * oodd[i]; }//next i return 0; }//end fft void __stdcall fft( long n, // serial length, n > 0 for dft, n < 0 for idft - inversed discrete fourier transform double * inputreal, double * inputimaginary, // inputs double * amplitudefrequences, double * phasefrequences) // outputs { if (n == 0) return; if (!inputreal && !inputimaginary) return; short n = abs(n); ccomplex * input = new ccomplex[n]; memset(input, 0, sizeof(ccomplex) * n); ccomplex * output= new ccomplex[n]; memset(output,0, sizeof(ccomplex) * n); double rl = 0.0f, im = 0.0f; int i = 0; for (i = 0; i < n; i++) { rl = 0.0f; im = 0.0f; if (inputreal) rl = inputreal[i]; if (inputimaginary) im = inputimaginary[i]; input[i] = ccomplex(rl, im); }//next i int f = fft(n, input, output); double factor = n; //factor = sqrt(factor); if (n > 0) factor = 1.0f; else factor = 1.0f / factor; //end if for (i = 0; i < n; i++) { if (amplitudefrequences) amplitudefrequences[i] = output[i].getreal() * factor; if (phasefrequences) phasefrequences[i] = output[i].getimaginary() * factor; }//next i delete [] output; delete [] input; return ; }//end fft int __cdecl main(int argc, char * argv[]) { fprintf(stderr, "%s usage:\n", argv[0]); fprintf(stderr, "public declare sub fft lib \"wfft.exe\" \ (byval n as long, byref inputreal as double, byref inputimaginary as double, \ byref freqamplitude as double, byref freqphase as double)"); return 0; }//end main };//end extern "c"
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯