首页 > 其他分享 >一阶滞后滤波法

一阶滞后滤波法

时间:2023-01-04 10:37:25浏览次数:43  
标签:inputs noise sinx 滤波 plt 一阶 滞后 np import

代码如下

import scipy.signal as signal
import numpy as np
import pylab as pl
import matplotlib.pyplot as plt
import matplotlib

'''
一阶滞后滤波法
a:            滞后程度决定因子,0~1
'''
def FirstOrderLag(inputs,a):
    tmpnum = inputs[0]                            #上一次滤波结果
    for index,tmp in enumerate(inputs):
        inputs[index] = (1-a)*tmp + a*tmpnum
        tmpnum = tmp
    return inputs

a = np.array([1,2,3,4,5])
a = a.astype(np.float64)

print(FirstOrderLag(a,0.3))

#生成数据
x = np.arange(0,8.1,0.1)
y = np.sin(x*np.pi)
plt.plot(x,y,label='sinx')



#对y加入噪声
noise = np.random.normal(-0.2,0.2,len(x))
y = y + noise
plt.plot(x,y,label='sinx+noise')
print(y)

#对加入噪声的信号进行滤波

y = FirstOrderLag(y,0.4)
print(y)
plt.plot(x,y,label='sinx+noise+First')
plt.legend(['sinx','sinx+noise','sinx+noise+First'])
plt.show()

 

标签:inputs,noise,sinx,滤波,plt,一阶,滞后,np,import
From: https://www.cnblogs.com/lpj1393822011/p/17024145.html

相关文章