python实现matlab中的filter函数
matlab中的filter函数:
y = filter(b,a,x)
python实现matlab中的filter函数
def filter_matlab(b,a,x): y = [] y.append(b[0] * x[0]) for i in range(1,len(x)): y.append(0) for j in range(len(b)): if i >= j : y[i] = y[i] + b[j] * x[i - j ] j += 1 for l in range(len(b)-1 ): if i >l: y[i] = (y[i] - a[l+1] * y[i -l-1]) l += 1 i += 1 return y
example:
取
b = [8,-3.5,0.5]
a = [1,-1.5,0.25]
x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
y = filter_matlab(b,a,x)函数的结果和matlab的filter函数结果一致,为
[8, 24.5, 52.25, 94.75, 156.5625, 243.65625, 363.84375, 527.3515625, 747.56640625, 1042.01171875, 1433.6259765625, 1952.43603515625, 2637.74755859375, 3541.0123291015625, 4729.581604003906, 6291.619323730469, 8342.533584594727, 11033.395545959473, 14561.959922790527, 19187.090997695923]
相关推荐
cuiguanjun 2020-07-26
Canethui 2020-05-31
Canethui 2020-05-30
cuiguanjun 2020-05-14
xiaoxue 2020-05-09
cuiguanjun 2020-03-01
wwwdownmacom 2020-09-14
wanff0 2020-07-26
HongAndYi 2020-07-04
知识小屋 2020-06-24
wanff0 2020-06-14
cuiguanjun 2020-06-13
liqing 2020-06-13
algorithmlixuan 2020-06-12
faustcao 2020-06-12
GerwelsJI 2020-06-09
zyazky 2020-06-08
cuiguanjun 2020-06-05
zyazky 2020-05-29