使用Python在实时信号上进行ECG数据分析 [英] ECG Data Analysis on a real-time signal in Python
问题描述
我正在使用Python从Arduino获得的信号中产生心电图(ECG)。我想对其进行一些分析,我尚不知道哪种分析类型尚待确定。但是我的问题是,是否可以对通过串行端口的实时数据流进行分析,还是先将数据保存为一个文本文件然后对其进行分析,是更容易/更好的方法。现在,我无法解决这个问题。一个额外的注意事项:我至少想检测信号的峰值(R波)和R-R间隔(这样我就可以测量每分钟的拍数)。
I am using Python to produce an electrocardiogram (ECG) from signals obtained by an Arduino. I want to perform some analysis on it, what type of analysis I do not know yet that is something I have yet to decide. However my question is, is it possible to do this analysis on a real time flow of data coming through the serial port, or is it easier/better to save the data first to suppose a text file and then perform analysis on it. Right now I can't wrap my head round how to do it. An extra note: I would at the very minimum like to detect the peaks of the signal (R wave) and the R-R interval (so I can measure the beats per minute).
到目前为止,这是我在Python上所拥有的:
Here is what I have on Python thus far:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
import matplotlib.figure as mfig
import PyQt4.QtGui as gui, PyQt4.QtCore as core
import collections
import time
import random
import serial
ser = serial.Serial('/dev/tty.usbmodem1411', 57600)
start_byte = 'S'
end_byte = 'F'
refreshMillis = 50
N = 200
xs = collections.deque(maxlen=N)
ys = collections.deque(maxlen=N)
app = gui.QApplication([])
fig = mfig.Figure()
canvas = FigureCanvasQTAgg(fig)
ax = fig.add_subplot(111)
ax.set_ylim([0,5])
line2D, = ax.plot(xs,ys)
canvas.show()
def process_line():
line = ser.readline()
data = map(float,line.split(" "))
xs.append(data[0])
ys.append(data[1])
line2D.set_data(xs,ys)
print data
xmin, xmax = min(xs),max(xs)
if xmin == xmax:
ax.set_xlim([xmin,xmin+1])
else:
ax.set_xlim([xmin,xmax])
canvas.draw()
timer = core.QTimer()
timer.timeout.connect(process_line)
timer.start(refreshMillis)
app.exec_()
ser.flush()
ser.close()
推荐答案
当然可以。首先保存起来比较容易,然后再进行数据分析,但是对定义的数据块执行此操作也没有问题。真正的问题是,您想进行哪种分析!您是否需要所有数据?或x秒的数据?您需要多少数据才能找到可靠的R和R-R值?在您的情况下,我首先将一些数据转储出去并处理它,以查看您的需求。然后,您可以稍后构建一个版本,使用发现的算法参数即时执行此操作。
Sure it's possible. It's easier to save it at first and then analyse the data later, but it's also no problem to do this on a definded chunk of data. The real question is, what kind of analysis do you want to do! Do you need all the data? or x seconds of data? How much data do you need to find reliable R and R-R values? In your case, I would first dump some data away and play with it to see what you need. You can then later build a version which does this on-the-fly with the discovered parameters of your algorithms.
这篇关于使用Python在实时信号上进行ECG数据分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!