巴特沃斯低通滤波器(C语言)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
能实行,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;
}