#include<math.h>
#define FIRNUMBER 25
#define SIGNAL1F 1000
#define SIGNAL2F 4500
#define SAMPLEF 10000
#define PI 3.1415926
float InputWave()
float FIR()
float fHn[FIRNUMBER]={ 0.0,0.0,0.001,-0.002,-0.002,0.01,-0.009,
-0.018,0.049,-0.02,0.11,0.28,0.64,0.28,
-0.11,-0.02,0.049,-0.018,-0.009,0.01,
-0.002,-0.002,0.001,0.0,0.0
}
float fXn[FIRNUMBER]={ 0.0 }
float fInput,fOutput
float fSignal1,fSignal2
float fStepSignal1,fStepSignal2
float f2PI
int i
float fIn[256],fOut[256]
int nIn,nOut
main()
{
nIn=0nOut=0
f2PI=2*PI
fSignal1=0.0
fSignal2=PI*0.1
fStepSignal1=2*PI/30
fStepSignal2=2*PI*1.4
while ( 1 )
{
fInput=InputWave()
fIn[nIn]=fInput
nIn++nIn%=256
fOutput=FIR()
fOut[nOut]=fOutput
nOut++
if ( nOut>=256 )
{
nOut=0 /* 请在此句上设置软件断点 */
}
}
}
float InputWave()
{
for ( i=FIRNUMBER-1i>0i-- )
fXn[i]=fXn[i-1]
fXn[0]=sin(fSignal1)+cos(fSignal2)/6.0
fSignal1+=fStepSignal1
if ( fSignal1>=f2PI )fSignal1-=f2PI
fSignal2+=fStepSignal2
if ( fSignal2>=f2PI )fSignal2-=f2PI
return(fXn[0])
}
float FIR()
{
float fSum
fSum=0
for ( i=0i<FIRNUMBERi++ )
{
fSum+=(fXn[i]*fHn[i])
}
return(fSum)
}
clfclear%设置初值
f0=50
Ts=0.001
fs=1/Ts
NLen=512
n=0:NLen-1
%陷波器的设计
apha=-2*cos(2*pi*f0*Ts)
beta=0.96
b=[1 apha 1]
a=[1 apha*beta beta^2]
figure(1)
freqz(b,a,NLen,fs)%陷激旅波器特性显示
x=sin(2*pi*50*n*Ts)+sin(2*pi*125*n*Ts)%原信号
y=dlsim(b,a,x)%陷波器滤波处理
%对信号进行频明枝凳域变换。
xfft=fft(x,NLen)
xfft=xfft.*conj(xfft)/NLen
y1=fft(y,NLen)
y2=y1.*conj(y1)/NLen
figure(2)%滤除前后的信号对比。
subplot(2,2,1)plot(n,x)grid
xlabel('Time (s)'搭凳)ylabel('Amplitude')title('Input signal')
subplot(2,2,3)plot(n,y)grid
xlabel('Time (s)')ylabel('Amplitude')title('Filter output')
subplot(2,2,2)plot(n*fs/NLen,xfft)axis([0 fs/2 min(xfft) max(xfft)])grid
xlabel('Frequency (Hz)')ylabel('Magnitude (dB)')title('Input signal')
subplot(2,2,4)plot(n*fs/NLen,y2)axis([0 fs/2 min(y2) max(y2)])grid
xlabel('Frequency (Hz)')ylabel('Magnitude (dB)')title('Filter output')
如果是低频电路就好办了.首先你要做的是一个滤波器的设计,这个滤波器是带阻滤波器.不过你还是要确定你的滤波器的过度带宽度,因为过度带宽度越大,那么谐振电路的级数也就越少,成本也小
然后是计算参数,根据阻抗匹配原理姿悄,确定你使用的是串联谐振还是并联谐振电路
计算好参数,最好用尘仿计算机算吧.把滤波器参数转换为电感电容还有电阻的参数,你可以参考滤波器方面的书
大致是这样
不迹兄渣过这只是我的想法,在你的设计中,能不能用这样的滤波器替代我就不清楚了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)