calculate FFT graph from Cyton samples, using python

gregpalmergregpalmer Madison
edited May 2021 in Software

Hi,
I recently purchased the cyton+daisy board with the electrode cap.
I am trying to get the data that I log in the openbci gui into python in the fft format (the data that the gui uses to produce the live fft plot). Is there a way to do this?
Since the gui creates files in the .txt or .bdf format, is there a command that can read in the file and then transform to the fft format? Or does the board itself do the fft?

Thanks in advance for your help!

@wjcroft @retiutut @ Andrey1994 @evaesteban

Comments

  • retiututretiutut Louisiana, USA
  • retiututretiutut Louisiana, USA
    edited May 2021

    You can collect data directly using BrainFlow Python Binding. Then, you can retrieve user defined Band Power levels.

    https://brainflow.readthedocs.io/en/stable/Examples.html#python-band-power

    I'm not a big MNE user, but there is also compatibility with MNE:

    https://brainflow.readthedocs.io/en/stable/Examples.html#python-mne-integration

  • "I am trying to get the data that I log in the openbci gui into python in the fft format"

    GUI stores raw unprocessed data, you can read it as a tsv file(with custom multiline header) and convert to pandas dataframe but you will need to calc fft by yourself. Another option to get fft data from the gui is networking widget.

  • @Andrey1994
    Thanks!
    If the file from the gui was at location "eeg/example.txt", what would my command be to read it in? I am just a little confused since the file is in .txt format and you are suggesting to read it in as a tsv.
    Thanks in advance!

  • Using the raw data that is logged from the openbci gui, how can you process it into power vs frequency?
    I have been trying to do this for the last two days and Im not really making any progress so any help would be greatly appreciated!

  • wjcroftwjcroft Mount Shasta, CA

    @gregpalmer, hi.

    I merged your new thread (with above comment), into this existing thread you previously started. There are many Python DSP (digital signal processing) libraries available, that can perform FFT.

    https://www.google.com/search?q=python+dsp+fft
    https://realpython.com/python-scipy-fft/

    As Andrey and Richard mentioned previously, there are (at least) two ways to approach this:

    • make a recording CSV file from the GUI, then read that into your Python program, parsing the samples in the file and calling the FFT library routine. This will result in an array of "frequency bins", that show the power or amplitude of the sample range, at each frequency. For example you might have each 'bin' correspond to a 1 Hz range. 0 to 1, 1 to 2, 2 to 3, etc.
    • another way to go is to use the Brainflow library to process the data streaming from Cyton in real-time. In that case you do not need to first record with the GUI. https://brainflow.readthedocs.io/en/stable/Examples.html#python-band-power

    Regards, William

  • @wjcroft, Thank you very much! That really solves it for me!
    This does spark an additional question: Does the Cyton board do a different FFT than a python library? In other words, is there any reason to prefer one method on the grounds of signal quality?

  • wjcroftwjcroft Mount Shasta, CA

    All FFT libraries should produce accurate results. The OpenBCI_GUI is not written in Python, but instead in Processing / Java. It's calling on Brainflow library routines.

    https://brainflow.org/

    Brainflow has language bindings for a wide range of popular languages, including Python, Java, C++, C#, Matlab, etc.

    William

Sign In or Register to comment.