本文主要实现将一维时序数据进行幅值归一化
1. 导包
import numpy as np
import math
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
2. 自定义函数
def normalized(origin_signal):
y = origin_signal - np.mean(origin_signal)
y = y / np.max(np.abs(y))
return y
3. 完整代码
import numpy as np
import math
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
def normalized(origin_signal):
y = origin_signal - np.mean(origin_signal)
y = y / np.max(np.abs(y))
return y
data = [1,2,4,3,5,2,7,5,2,6,5,9,10,2,5,4,3]
origin_signal = np.array(data)
normalized_data = normalized(origin_signal)
plt.plot(origin_signal)
legend = "原始数据"
plt.legend(legend)
plt.show()
plt.plot(normalized_data)
legend = "幅值归一化"
plt.legend(legend)
plt.show()
4. 效果展示
原始信号:
幅值归一化信号: