import numpy as np
import matplotlib.pyplot as plt
# 生成模拟传感器数据(示例数据)
sensor_data = np.random.randn(200) # 正态分布随机数据
# 定义低通滤波函数
def low_pass_filter(data, cutoff_freq):
filtered_data = np.copy(data)
for i in range(1, len(data)):
filtered_data[i] = (1 - cutoff_freq) * filtered_data[i - 1] + cutoff_freq * data[i]
return filtered_data
# 设置截止频率
cutoff_frequency = 0.2
# 应用低通滤波
filtered_sensor_data = low_pass_filter(sensor_data, cutoff_frequency)
# 绘制原始数据和滤波后数据
plt.figure(figsize=(10, 6))
plt.plot(sensor_data)
plt.plot(filtered_sensor_data)
plt.show()