巴特沃斯低通滤波器(C语言)word版本
- 格式:doc
- 大小:95.50 KB
- 文档页数:5
能实行,c语言不能显示图像,但是你要懂得如何用c调用matlab,过程比较复杂,这个程序任何参数都可以用,不限制
#include
#include
#include
#include
#include
double calcN(double fp,double ap, double fs, double as)
{
double i = pow(10,(as/10)) - 1;
double tmp = ap/10;
double j = pow(10,tmp) - 1;
double k = log10((i/j));
double t = log10(fs/fp);
double N = 0.5*k/t + 1;
return N;
};
int main(void)
{
int fp,ap,fs,as;
printf("请输入fp:");
scanf("%d", &fp);
printf("请输入ap:");
scanf("%d", &ap);
printf("请输入fs:");
scanf("%d", &fs);
printf("请输入as:");
scanf("%d", &as);
int f = calcN(fp, ap, fs, as);
printf("N=%d\n",f);
char lin[40];
char *str = "N=\0";
lin[0]='\0';
char in[4];
itoa(f,in,10);
strcat(lin,str);
strcat(lin,in);
strcat(lin, ";");
/////////////////////////////////////////////////////////// Engine *ep;
if(!(ep = engOpen(NULL)))
{
printf("open failed! please try again\n");
}
engSetVisible(ep, 0);
//mxArray *xx = mxCreateDoubleMatrix(1,N,mxREAL);
// mxArray *yy = mxCreateDoubleMatrix(1,N,mxREAL);
// memcpy(mxGetPr(xx),N*sizeof(double));
// memcpy(mxGetPr(yy),N*sizeof(double));
// engPutVariable(ep,"xx",xx);
//engPutVariable(ep,"yy",yy);
engEvalString(ep, "n=0:0.01:2;");
engEvalString(ep, lin);
engEvalString(ep, "[z,p,k]=buttap(N);");
engEvalString(ep, "[b,a]=zp2tf(z,p,k);");
engEvalString(ep, "[H,w]=freqs(b,a,n);");
engEvalString(ep, "magH=(abs(H)).^2;");
engEvalString(ep, "plot(w,magH);");
engEvalString(ep, "axis([0 2 0 1])");
engEvalString(ep, "xlabel('w/wc');");
engEvalString(ep, "ylabel('|H(jw)|^2');");
engEvalString(ep, "title('Butterworth analog filter prototype');");
engEvalString(ep, "grid;"); getchar();
//mxDestroyArray(xx);
// mxDestroyArray(yy);
// engClose(ep);
return 0;
}