python求fir滤波器,矩形窗
import math
def sinc(x):
if x==0.0:
return 1.0
else:
return math.sin(math.pi*x)/math.pi/x
def impulse(x):
if x==0.0:
return 1.0
else :
return 0
N=9
#线性相位条件
k=(N-1)/2
#测试低通高通
fc=0.1
#测试带通带阻
f1=0.1
f2=0.2
#低通
for i in range(0,N,1):
print(2*fc*sinc(2*fc*(i-k)))
print('------------------------')
#高通
for i in range(0,N,1):
print(impulse(i-k)-2*fc*sinc(2*fc*(i-k)))
print('------------------------')
#带通
for i in range(0,N,1):
print(2*f2*sinc(2*f2*(i-k))-2*f1*sinc(2*f1*(i-k)))
print('------------------------')
#带阻
for i in range(0,N,1):
print(sinc(i-k)-2*f2*sinc(2*f2*(i-k))+2*f1*sinc(2*f1*(i-k)))
print('------------------------')
|