简体   繁体   English

Matlab中的函数过滤器

[英]Matlab function filter in c

I want to write the c code for the matlab filter but I don't obtain the same result; 我想为matlab过滤器编写C代码,但未获得相同的结果; the first members are correct but after, not. 前几个成员是正确的,但后面的不是。 I don't know what's wrong. 我不知道怎么了

void convolve(const double b[], size_t b_Len,
          const double h[], size_t h_Len,
          double result[],
          const double a[])
{
int i,j;
result[0]=b[0]*h[0];
for (i=1;i<h_Len+1;i++)
{
    result[i]=0;
    for (j=0;j<i+1;j++)
        result[i]=result[i]+b[j]*h[i-j];
    for (j=0;j<i;j++)
        result[i]=result[i]-a[j+1]*result[i-j-1];
}

Finally this is my code: 最后这是我的代码:

#include <stdio.h>
#include <stdlib.h>

#include "coef_b.h"
extern  double x[];

#define NN 48
#define MM 13
float a=1;
double result [NN];

void convolve(const real64_T b[], 
          const double x[], 
          double result[],
          const float a)
{
FILE *f;
int i,j,l,k;
double temp[96]={0};

for(i=0;i<48;i++)
    temp[48+i]=x[i];

    for(j=48;j<96;j++)
{
    for(l=0;l<13;l++)
        result[j-48]=result[j-48]+temp[j-l]*b[l];   
}

f =fopen("super_result.dat","w");
    for (k = 0; k<48; k++)
    {
        fprintf(f,"%lf\n",result[k]);
    }
    fclose(f);
    return;
}


 int main(void)
 {
 convolve(B,
       x,
       result,
       a);

  return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM