Hi guys,
I'm trying to plot a real time signal with python and PyQtGraph has improved the speed a lot, but still with some delay. The data comes from a DLL and it's store in a NumPy Vector.
I wan't to plot this buffer every 0.1s with 100 points(the signal has 1kHz sampling rate). At the beginning this seems to work but after few seconds
starts to get behind the plot.
This is part of my code:
def coleta():
global cnt
global t
nsample = c_ulong(int(0.1 * sampleRate.value))
status = emgSampleNSeconds(handle.value, 50)
if status == 0:
print("Inicia a amostragem")
else:
print("Não foi possível iniciar a amostragem")
emgIsSampling(handle.value, byref(isSampling))
canal = c_ulong(0)
emgbuffer = (c_double * nsample.value)()
emgDataPlot = np.zeros(10000, dtype=float)
curve1 = p1.plot(emgDataPlot, pen='r')
sleepVar = 0.1
pltStart = pg.ptime.time()
while isSampling:
time.sleep(sleepVar)
emgGetRealUnitDataBlock(handle.value, canal.value, emgbuffer, byref(nsample))
now = time.time()
for value in emgbuffer:
emgDataPlot = np.append(emgDataPlot, value)
if len(emgDataPlot) > sampleRate.value * 10:
emgDataPlot = np.delete(emgDataPlot, 0)
if t == 0:
p1.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted
t += 1
curve1.setData(emgDataPlot)
app.processEvents()
#print(t)
emgIsSampling(handle.value, byref(isSampling))
#p1.enableAutoRange(True, True)
print(pltStart - pg.ptime.time())
What I need to do?
Thanks.