OpenBCI GUI FFT LSL Hangup

jstiegerjstieger Carnegie Mellon University

Hello!

I'm pulling the FFT output of the OpenBCI Gui through LSL to python and I'm trying to plot the data using pyQTgraph. The plotting seems to work for a while, but then the python qtgraph freezes. I'm using a mac and for some reason if I "look at all the windows" (and bring the OpenBCI GUI back into view) the GUI appears frozen, but then it starts up again. After bringing the gui back into view the python program works again too. Do you know what could be causing this/how to address this issue? I've tried sampling the data slower than the gui frame rate, but the issue still seems to keep occurring.

Thanks!

Comments

  • wjcroftwjcroft Mount Shasta, CA

    Mentioning Richard @retiutut, who is the GUI developer / enhancer. Very soon the GUI will be streamlined by dropping the separate 'Hub' process. Instead using the new Brainflow libraries. Brainflow also supports Python and many other languages.

    https://brainflow.readthedocs.io/en/stable/

    Additionally, it is not hard to invoke DSP functions from Python libraries. Thus you could do your own FFT.

    https://www.google.com/search?q=python+dsp+library

    Regards, William

  • wjcroftwjcroft Mount Shasta, CA

    @jstieger, can you mention your computer setup there, OS, hardware, year, etc.? Have you tried this on other machines? Richard tells me he has had multiple streams going with no issues.

  • retiututretiutut Louisiana, USA

    Please post the full Python code (as text) you are using so that this can be replicated by others.

  • jstiegerjstieger Carnegie Mellon University
    edited February 2020

    Thanks for the comments!
    Unfortunately I only own one machine, so I need to make the code work on my laptop.

    System:
    Mac OSMojave 10.14
    MacBook Pro (Retina, 15-inch, Mid 2014)
    Processor: 2.5 GHz Intel Core i7
    memory: 16 GB 1600 MHz DDR3
    Graphics: NVIDIA GeForce GT 750M 2048 MB
    Intel Iris Pro 1536 MB

    Code:
    from pyqtgraph.Qt import QtCore, QtGui
    import pyqtgraph as pg
    import pyqtgraph.opengl as gl
    import numpy as np
    from scipy import interpolate
    from pylsl import StreamInlet, resolve_stream
    import time
    from scipy.interpolate import griddata

    FFT_MAX_HZ = 20
    
    streams = resolve_stream('type', 'EEG')
    
    inlet = StreamInlet(streams[0])
    
    app = QtGui.QApplication([])
    w = gl.GLViewWidget()
    w.show()
    w.setWindowTitle('pyqtgraph example: GLSurfacePlot')
    w.setCameraPosition(distance=50)
    
    elec_angles = [108,72,144,126,54,36,180,162,18.0,0.0,202.5,225,315,337.5,247.5,292.5]
    freq_radius = [i for i in range(1,21)]
    
    def pol_to_cart_rays(theta,r):
        x = []
        y = []
        ratio = (2*np.pi)/360
        for angle in theta:
            for radius in r:
                x.extend([radius*np.cos(angle*ratio)])
                y.extend([radius*np.sin(angle*ratio)])
    
        return np.asarray(x),np.asarray(y)
    
    x, y = pol_to_cart_rays(elec_angles, freq_radius)
    x_vec = np.linspace(np.min(x),np.max(x),100)
    y_vec =  np.linspace(np.min(y),np.max(y),100)
    X_grid, Y_grid = np.meshgrid(x_vec,y_vec)
    
    
    FFT_MAX = 20
    
    p4 = gl.GLSurfacePlotItem(x=x_vec, y = y_vec, shader='heightColor', computeNormals=False, smooth=False)
    p4.shader()['colorMap'] = np.array([0.2, 2, 0.5, 0.2, 1, 1, 0.2, 0, 2])
    w.addItem(p4)
    
    FFT_dat = np.zeros(x.shape)
    def update():
        global p4, z, index
        for i in range(16): # each of the 16 channels here
            sample, timestamp = inlet.pull_sample()
            FFT_dat[(i*FFT_MAX):(i+1)*FFT_MAX] = np.log(sample[:FFT_MAX])
    
        z_interp = griddata((x, y), FFT_dat, (X_grid, Y_grid), method='cubic')
        p4.setData(z=z_interp)
    
    timer = QtCore.QTimer()
    timer.timeout.connect(update)
    timer.start(40)
    
    
    if __name__ == '__main__':
        import sys
        if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
            QtGui.QApplication.instance().exec_()
    
  • retiututretiutut Louisiana, USA

    Can you please also share a link to a screen recording with a brief description? This way there is no confusion as to what is actually happening.

Sign In or Register to comment.