峰值检测
import matplotlib.pyplot as plt
import numpy as np
import h5py
def nms_3(data):
length=len(data)
ans=[]
for i in range(2,length-2):
if data[i] >= data[i-1] and data[i] >= data[i+1] :
ans.append(i)
return ans
if __name__ == '__main__':
f = h5py.File("data.hdf5", "r")
keys = f.keys()
pulse = []
time = []
for e in f['pulse']:
pulse.append(e)
for e in f['time']:
time.append(e)
print("the len of pulse is %d" % (len(pulse)))
print("the len of time is %d" % (len(time)))
pulse = np.array(pulse)
plt.figure()
# # 时间为横轴,单位转换复杂 不知道抽样频率。 还是以样本数量为横轴,刚好对应
# plt.plot(time, pulse)
# plt.xlabel('time') # 时间60s
# plt.title('time-pulse') # 添加图片标题
# 以样本数量为横轴,刚好对应
plt.plot(np.arange(len(pulse)), pulse)
plt.xlabel('Number of samples') # 样本数量 len(pulse)=len(time)
plt.title('Number of samples-pulse-pulse') # 添加图片标题
point = nms_3(pulse)
plt.plot(point, pulse[point], "o")
print(point)
plt.show()
exit()
峰值检测放大子图,看起来检测效果不怎么好