当前位置:首页 » 编程语言 » 5阶巴特沃斯滤波器c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

5阶巴特沃斯滤波器c语言

发布时间: 2022-08-19 10:33:26

① 巴特沃斯滤波器

不是,巴特沃斯滤波器是一种典型的模拟原型滤波器,可以作为设计其它模拟、数字滤波器的原型。巴特滤波器本身的传递函数,你可以预先通过查表得到各阶的传递函数,但是里面的参数还不能确定,这要综合你所设计的滤波器的技术指标。
打个比方,你设计一个巴特沃斯低通滤波器的话,要有通带截止频率、阻带频率,用这2个指标去确定传递函数的参数,再结合你所设计滤波器的阶次才是完整的确定了参数的传递函数。
当然,上面举的只是一个低通模拟滤波器的设计,其它类型设计,根据不同类型,设计方法有差别。你自己看下资料就是了

c语言设计巴特沃斯低通滤波器fp=9khz,fs=15khz,ap=1dB,as=70dB

能实行,c语言不能显示图像,但是你要懂得如何用c调用matlab,过程比较复杂,这个程序任何参数都可以用,不限制

#include<engine.h>

#include<math.h>

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

doublecalcN(doublefp,doubleap,doublefs,doubleas)

{

doublei=pow(10,(as/10))-1;

doubletmp=ap/10;

doublej=pow(10,tmp)-1;

doublek=log10((i/j));

doublet=log10(fs/fp);

doubleN=0.5*k/t+1;

returnN;

};

intmain(void)

{

intfp,ap,fs,as;

printf("请输入fp:");

scanf("%d",&fp);

printf("请输入ap:");

scanf("%d",&ap);

printf("请输入fs:");

scanf("%d",&fs);

printf("请输入as:");

scanf("%d",&as);

intf=calcN(fp,ap,fs,as);

printf("N=%d ",f);

charlin[40];

char*str="N=";

lin[0]='';

charin[4];

itoa(f,in,10);

strcat(lin,str);

strcat(lin,in);

strcat(lin,";");

///////////////////////////////////////////////////////////

Engine*ep;

if(!(ep=engOpen(NULL)))

{

printf("openfailed!pleasetryagain ");

}

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([0201])");

engEvalString(ep,"xlabel('w/wc');");

engEvalString(ep,"ylabel('|H(jw)|^2');");

engEvalString(ep,"title('');");

engEvalString(ep,"grid;");

getchar();

//mxDestroyArray(xx);

//mxDestroyArray(yy);

//engClose(ep);

return0;

}

③ 如何用c语言实现截止频率为200hz的巴特沃斯低通滤波器

/* 6th Order Low Pass Butterworth */
/* Bilinear Transformation with Prewarping */
/* Sample Frequency = 100.0 Hz */
/* Standard Form */
/* Arithmetic Precision = 4 Digits */
/* */
/* Pass Band Frequency = 35.00 Hz */
/* */
/******************************************************************************/
/* */
/* Input Variable Definitions: */
/* Inputs: */
/* invar float The input to the filter */
/* initvar float The initial value of the filter */
/* setic int 1 to initialize the filter to the value of initvar */
/* */
/* There is no requirement to ever initialize the filter. */
/* The default initialization is zero when the filter is first called */
float DigFil(invar, initval, setic)
float invar, initval; int setic;

{
float sumnum, sumden; int i;
static float delay[7] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0};
static float znum[7] = {
.1477,
.8864,
2.216,
2.955,
2.216,
.8864,
.1477
};
static float zden[6] = {
2.183e-02,
.2099,
.8779,
2.055,
2.91,
2.38
};
if (setic==1){
for (i=0;i<=6;i++) delay[i] = .1058*initval;
return initval;
}
else{
sumden=0.0;
sumnum=0.0;
for (i=0;i<=5;i++){
delay[i] = delay[i+1];
sumden += delay[i]*zden[i];
sumnum += delay[i]*znum[i];
}
delay[6] = invar-sumden;
sumnum += delay[6]*znum[6];
return sumnum;
}
}

④ C或C++实现BUTTERWORTH滤波器

///巴特沃斯滤波器,带增益
MatBoostButterworthFilter(constint&row,constint&col,constfloat&cutoff,constint&n,constfloat&boost)const
{
assert(row>1&&col>1);
assert(cutoff>0&&cutoff<0.5);
assert(n>=1);

if(boost>=1)
{
return(1-1/boost)*(BHPF(row,col,cutoff,n))+1/boost;
}
else
{
return(1-boost)*BLPF(row,col,cutoff,n)+boost;
}
}
///巴特沃斯高通滤波器
MatCIllumNorm::BHPF(constint&row,constint&col,constfloat&cutoff,constint&n)
{
return1-BLPF(row,col,cutoff,n);
}

///巴特沃斯低通滤波器
/*
-0.5
nistheorderofthefilter,thehighernisthesharper

1
f=--------------------
2n
1.0+(w/cutoff)
*/
MatBLPF(constint&row,constint&col,constfloat&cutoff,constint&n)
{
assert(row>1&&col>1);
assert(cutoff>0&&cutoff<0.5);
assert(n>=1);

MatX=Mat::zeros(row,col,CV_32F);
MatY=Mat::zeros(row,col,CV_32F);

if(col%2)
{
intt=-(col-1)/2;

for(intj=0;j<col;j++)
{
for(inti=0;i<row;i++)
{

X.at<float>(i,j)=((float)t)/(col-1);
}
t++;
}
}
else
{
intt=-col/2;

for(intj=0;j<col;j++)
{
for(inti=0;i<row;i++)
{
X.at<float>(i,j)=((float)t)/col;
}
t++;
}
}


if(row%2)
{
intt=-(row-1)/2;

for(inti=0;i<row;i++)
{
for(intj=0;j<col;j++)
{
Y.at<float>(i,j)=((float)t)/(row-1);
}
t++;
}
}
else
{
intt=-row/2;

for(inti=0;i<row;i++)
{
for(intj=0;j<col;j++)
{
Y.at<float>(i,j)=((float)t)/row;
}
t++;
}
}


MatH=Mat::zeros(row,col,CV_32F);

///计算频域的巴特沃斯分类器
for(inti=0;i<row;i++)
{
for(intj=0;j<col;j++)
{
floatx=X.at<float>(i,j);
floaty=Y.at<float>(i,j);
floatradius=sqrtf(x*x+y*y);

///1.0./(1.0+(radius./cutoff).^(2*n))
H.at<float>(i,j)=1.0/(1.0+std::pow(radius/cutoff,2*n));
}
}

///shift将中心点移到左上角
H=CenterShift(H);

returnH;
}

MatCenterShift(constMat&_src)
{
Matsrc=Mat_<float>(_src);
Matdst=Mat::zeros(src.rows,src.cols,src.type());

intN=src.rows;
intD=src.cols;

int*rowIndex=newint[N];
int*colIndex=newint[D];

memset(rowIndex,0,sizeof(rowIndex[0])*N);
memset(colIndex,0,sizeof(colIndex[0])*D);

///行顺序
intbegin=N/2;
for(inti=0;i<N;i++)
{
rowIndex[i]=begin;
begin++;
if(begin>=N)
{
begin=0;
}
}

///列顺序
begin=D/2;
for(inti=0;i<D;i++)
{
colIndex[i]=begin;
begin++;
if(begin>=D)
{
begin=0;
}
}

///重新排序
for(inti=0;i<N;i++)
{
for(intj=0;j<D;j++)
{
dst.at<float>(i,j)=src.at<float>(rowIndex[i],colIndex[j]);
}
}

///释放
delete[]rowIndex;
delete[]colIndex;
rowIndex=NULL;
colIndex=NULL;

returndst;
}

⑤ 怎样设计巴特沃斯带通滤波器参数,以及主要参数

1. buttord (1)[N,wc]=buttord(wp,ws,αp,αs) 用于计算巴特沃斯数字滤波器的阶数N和3dB截止频率wc。 调用参数wp,ws分别为数字滤波器的通带、阻带截止频率的归一化值,要求:0≤wp≤1,0≤ws≤1。1表示数字频率pi。 αp,αs分别为通带最大衰减和组带最小衰减(dB)。 当ws≤wp时,为高通滤波器; 当wp和ws为二元矢量时,为带通或带阻滤波器,这时wc也是二元向量。 N,wc作为butter函数的调用参数。 (2)[N,Ωc]=buttord(Ωp,Ωs,αp,αs,‘s’) 用于计算巴特沃斯模拟滤波器的阶数N和3dB截止频率Ωc。 Ωp,Ωs,Ωc均为实际模拟角频率。 说明:buttord函数使用阻带指标计算3dB截止频率,这样阻带会刚好满足要求,而通带会有富余。 2.buttap(N) [z0,p0,k0]=buttap(N) 用于计算N阶巴特沃斯归一化(3dB截止频率Ωc=1)模拟低通原型滤波器系统函数的零、极点和增益因子。 说明:如果要从零、极点模型得到系统函数的分子、分母多项式系数向量ba、aa,可调用 [B,A]=zp2tf(z0,p0,k0) 3.butter (1)[b,a]=butter(N,wc,‘ftype’) 计算N阶巴特沃斯数字滤波器系统函数分子、分母多项式的系数向量b、a。 调用参数N和wc分别为巴特沃斯数字滤波器的阶数和3dB截止频率的归一化值(关于pi归一化),一般是调用buttord(1)格式计算N和wc。 系数b、a是按照z-1的升幂排列。 (2)[B,A]=butter(N,Ωc,‘ftype’,‘s’) 计算巴特沃斯模拟滤波器系统函数的分子、分母多项式系数向量ba、aa。 调用参数N和Ωc分别为巴特沃斯模拟滤波器的阶数和3dB截止频率(实际角频率),可调用buttord(2)格式计算N和Ωc。 系数B、A按s的正降幂排列。 tfype为滤波器的类型: ◇ftype=high时,高通;Ωc只有1个值。 ◇ftype=stop时,带阻阻;此时Ωc=[Ωcl,Ωcu],分别为带阻滤波器的通带3dB下截止频率和上截止频率。 ◇ ftype缺省时: 若Ωc只有1个值,则默认为低通; 若Ωc有2个值,则默认为带通;其通带频率区间Ωcl < Ω < Ωcu。 注意:所设计的带通和带阻滤波器系统函数是2N阶。因为带通滤波器相当于N阶低通滤波器与N阶高通滤波器级联。 相关文章: 数学思想及理论 均匀乱数 MDSC很可能,我已经用尽了现有原始数据的所有潜能 新

⑥ matlab设计巴特沃斯滤波器,这个分子和分母是什么意思啊,如图。怎么通过系数设计成C语言

NUMERATOR 分子
DENOMINATOR 分母
意识是 分子和分母多项式系数
GAIN 增益
通过滤波器后 幅值的线性变换值
你的y(n)=b(i)*x(n-i)-a(k)*y(n-k)是差分方程,这里用多项式系数方程
要通过系数设计C语言
就把滤波器系数和采样序列进行卷积
float IIR()
{
float fSum;
fSum=0.0;
for ( i=0;i<IIRNUMBER;i++ )
{
fSum+=(fXn[i]*fAn[i]);
fSum+=(fYn[i]*fBn[i]);
}
return(fSum);
}

⑦ 巴特沃斯数字高通滤波器

设计思路:用模拟滤波器原型设计法设计,然后经过频率转换变为相应的模拟滤波器,最后用双线性变换法将其变为相应的数字滤波器。其程序和结果图如下:N=5;Wn=250*2*pi; fs=1000/2;[z,p,k]=buttap(N); %模拟滤波器原型设计[Bap,Aap]=zp2tf(z,p,k);%零极点模型转换为传递函数模型[b,a]=lp2hp(Bap,Aap,Wn); %频率转换 [bz,az]=bilinear(b,a,fs);%双线性变换freqz(bz,az)

⑧ 巴特沃斯滤波器c语言实现

说的很对,滤波玩的就是增益(衰减)变化,不同的频率,不同的增益(衰减)。称幅频曲线。
1、巴特奥斯滤波器的截止频率指-3db通频带频率,也就是在这个频率以内保证畅通(通带)。
2、另一个指标叫做阻带,频率大于此值能够保证衰减大于某值

⑨ 就是关于巴特沃斯滤波器的程序的编写....

设计滤波器只要完成这两步就可以了,得到合适的b和a就算设计完了。
[N, Wn] = buttord(Wp, Ws, Rp, Rs);[b,a] = butter(N,Wn)

但是已知条件中的Wp和Ws是不能直接代入的,必需转换
Wp=Wp*2/fs;Ws=Ws*2/fs;这就是所谓的归一化。fs是信号的采样频率。如果题目中没有给出,可以根据人声特点取44100Hz。如果题目中给了,就用题目的采样频率。
Rp和Rs如果题目没有给,可以自己指定。一般可选Rp=1,Rs=40

高通,和上面过程一样

带通,过程一样,Wp=[1000 2000] Ws=[800 2500]