import scipy.signal as signal import numpy as np import pylab as pl import matplotlib.pyplot as plt import matplotlib import pandas as pd import matplotlib.pyplot as plt pd.set_option('display.max_columns', 1000) pd.set_option('display.max_rows', 1000) pd.set_option('display.max_colwidth', 1000) ''' 一阶滞后滤波法 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 path = 'C:/Users/asus/Desktop/第4章作业/卡尔曼滤波数据.xlsx' data_B = pd.read_excel(path, header=None) x1= list(data_B.iloc[::, 0]) x2= list(data_B.iloc[::, 0]) y=[] y=FirstOrderLag(x1,0.48) ax1 = plt.subplot(1,2,1) ax2 = plt.subplot(1,2,2) plt.sca(ax1) plt.plot(x2, color="g") # 测量值 plt.sca(ax2) plt.plot(y, color="r") # 预测值 plt.show() 将python代码转化成matlab代码
时间: 2024-04-11 14:31:21 浏览: 157
python signal测试的使用 python信号处理函数的使用测试 from scipy import signal
import numpy as np
import scipy.io
a = 0.48
def first_order_lag(inputs, a):
tmpnum = inputs[0]
for index, tmp in enumerate(inputs):
inputs[index] = (1-a)*tmp + a*tmpnum
tmpnum = tmp
return inputs
path = 'C:/Users/asus/Desktop/第4章作业/卡尔曼滤波数据.xlsx'
data_B = pd.read_excel(path, header=None)
x1= list(data_B.iloc[::, 0])
x2= list(data_B.iloc[::, 0])
y = first_order_lag(x1, a)
# Save data to MATLAB .mat file
scipy.io.savemat('data.mat', {'x2': x2, 'y': y})
阅读全文