Alpha Detector on board or laptop

edited March 2015 in Software
Hi everyone,

I just got my 32bit V3 board, and I am currently playing with it trying to get used to it.. It's good to mention that I have learned a lot from Chip through his great blog, EEG Hacker.

For now, I am trying to build an Alpha Detector on board. But I am really not sure what is the best way to do it because I am totally new to hardware programming.

When I went through some posts on EEG Hacker blog, I was able to find my Alpha waves; using MATLAB & Python done by Chip. But I would like know, how to process the data and detect Alpha band on board?

Do I need to have another board (let's say Arduino UNO) to receive the data from OpenBCI board and program it to detect alpha waves (like what Chip does in here)?

I really wish that I can find a way to program PIC32 on chip to detect alpha waves.

Thanks 

Comments

  • biomurphbiomurph Brooklyn, NY
    edited January 2015
    You can change the code that is on the PIC. See this tutorial


    The OpenBCI_SD code compiles to only about a third of the available code space:
    Binary sketch size: 46932 bytes (of a 122880 byte maximum)
     32bit board has plenty of room to do DSP on board. So if you want to detect Alpha on board, you certainly can. I would imagine that some sort of filtering and threshold would be entailed. 

    So you don't need any extra microprocessor, it's already on the board!
  • I checked in Chip's Github and did not see the alpha detection Arduino source code from his November 2013 blog post. But @chipaudette likely has it available still on his laptop and may be able to add that to his repository. I'm sure he'll pop in here shortly.

    Here's some related DSP libraries,

    https://www.google.com/search?q=arduino+dsp+library
  • biomurphbiomurph Brooklyn, NY
    edited January 2015
    Note that some of those library components will need to be ported to work with the chipKIT.

    Chip used a Biquad filter in our V2 experiments. He based it on this 

    and modified it to work with-on Arduino.

    He may jump in here with more details...
  • Hi biomurph,

    Yep, this is what I am stuck with as of right now.

    I found a code on Chip's github:


    I am trying to port it to ChipKit, and hopefully I'll be able to do that.
  • Hello again :)..

    I just finished porting Biquad filter from "OBCI_8bit_streamData_Filter.ino" to  ---> "OpenBCI_32bit_SD.pde

    The file has been verified by MPIDE to be upload into OpenBCI V3_32 board.

    Now, I will try to implement an Alpha detector to be used on 32_bit board. There are multiple way of doing it but I like what Chip did, which is:
    "After doing my filtering, I then compute the RMS power of the signal. I simply square the single, apply a low-pass filter (another biquad from the code above), and take the square root. This gives you a running RMS estimate of the signal amplitude. Because of my filtering, this gives me a running estimate of the Alpha amplitude. I then light my LED and sound my buzzer based on the amount of Alpha energy."

  • biomurphbiomurph Brooklyn, NY
    Sweet!

    Do you have a blog or other RSS? It would be great to share your work on our community page

  • Hi Everyone,

    I think that I found that old code that ran on the OpenBCI V2 board.  I pushed it to my GitHub here:


    Note that it took quite a bit of tuning of the detection parameters for it to work right.  The tuning were probably specific to me and my brain and my setup on that particular day.  You'll probably have to re-tune it for you and your setup. 

    By "tuning", I mean that I had to tweak parameters so that it was sensitive to my Alpha without being *overly* sensitive.  If you are overly sensitive, noise and motion artifacts and eye blinks and other non-Alpha stuff could be falsely detected.  The relevant tuning primarily happens in "updateLED()", which is where it decides if the measured EEG levels warrant some sort of of light/sound response. This part of the code is not the easiest to follow, so feel free to re-write the whole thing.  There are many ways to solve this problem.

    I hope that you get it working on the 32-bit board!

    Chip
  • Hi Chip,

    Thank you very much for sharing your code.

    My plan is to first replicate your work on 32-bit board, then I'll try to improve the detection performance by involving some machine-learning algorithms along with different technique of filtering.

    Currently, I don't have a specific blog for my EEG hacking, but I'll definitely start one very soon to share with OpenBCI community. 

    Thanks to you all
  • Hey Everyone,

    I just recently received a V3 OpenBCI kit to use for my design project and have been reading through a lot of the forums and Chip's awesome blog. I was hoping for some guidance. I am wondering if the code Chip had made for the V2 board will be compatible with the V3?

    I am a huge novice in all of this hardware/software/DSP engineering and would really appreciate your help. My design project is to build a prosthetic hand that can be controlled with the OpenBCI kit. Initially we want to just be able to activate different hand movements using the BCI to detect specific brain waves.

    However as a first step, I just want to be able to replicate Chip's alpha detector. I made some progress with being able to upload code to the V3 Board (btw the openBCI tutorial's documentation needs to be revised, at least for the benefit of noobs like myself). Nevertheless, I was able to upload code to the board. I tried to compile Chip's alpha detector code but obviously there were some discrepancies since it was coded for an arduino and not a chipKIT. I definitely would need some guidance/direction as to how to fix that.

    Thanks for all your help thus for, looking forward to your responses.
  • Hi,

    For a complicated project like yours, I would suggest that you NOT do the alpha detection on the Arduino/chipKIT processor that is on the OpenBCI board itself.  I would recommend that you do the alpha detection on the PC, in the Processing GUI, or in your own software (, or in BrainBay or the other EEG processing packages).  It's a lot easier to debug the code on the PC than in the Arduino (or MPLAB) environment.  So, start on the PC.

    In the Processing GUI, we've done Alpha detection a number of times....mainly for controlling the little HexBug robots (blog posts here, code for V3 is here).  This code could be used to control your hand, instead.  Look in the file "EEG_Processing.pde", specifically in the class "EEG_Processing_User" under the function "process()". 

    You'll note that "process" has a version for one-person, which uses more than just Alpha.  I would suggest that you look instead for the version for multiple people, which looks just for Alpha, but on multiple EEG channels (each person would be on a different channel).  It simply looks for when the peak EEG frequency is in the Alpha band and it looks for when the peak is strong enough relative to the baseline level, as defined by the other EEG frequencies.

    Once it detects that there is sufficiently strong Alpha, it issues a serial command out to a 2nd Arduino, which is controlling the HexBug or flying fish.  You could use that Arduino to control your hand.

    Chip
  • edited March 2015
    Hi Chip,

    Thanks for the awesome project. I just got my OpenBCI board as well and trying to do your Alpha wave detector project on my OpenBCI v3.
    I got processing running and the Hex_bug OpenBCI GUI running fine as well. and only problem for me to convert the Hex_bug into a alpha wave detector is the physical pin out.

    i can see the analog pin is from A1-A7 and the 5V is on the same roll. but somehow my previous knowledge from arduino is not enough for me to understand how to get the power link back to GND and light up the LED. Is there anyway you can show me how to wire all the cables?

    If I remember correctly from the OpenBCI website it mentioned never connect the Analog pin back to GND or it might damage the board.

    Thank you so much for your reply

    -Yen
  • Hi Yen,

    I wasn't aware of this point that you made...

    >> If I remember correctly from the OpenBCI website it mentioned never connect the Analog pin back to GND or it might damage the board.

    If it weren't for this, I would have said that you could connect the LED (via the typical 330 Ohm resistor or whatever) to any of the points labeled GND (but not the ones labeled AGND).  But, if there really is a warning against doing that, then we probably shouldn't do it.

    Maybe @biomurph could give his opinion on this one?

    Chip

  • biomurphbiomurph Brooklyn, NY
    @antigenius there is a goof on the 8bit board, in that I did not add ease access to the digital GND right there where all the other 5V pins are (A0 to A7, RST, 5V). sorry!

    You can lash up to digital GND by connecting to the GND pin on the bottom of the board (under MOSI, MISO, SCLK) That little bus is for flashing the Arduino UNO bootloader onto the ATmega chip.

    Or, you can connect to GND by connecting to the GND pin on the diagonal bus between DVDD and MISO pins. 
    Please be careful using this later method, because the diagonal buss is 3V, and will not tolerate 5V under any circumstances. That's the danger. You can plug into the GND all day long (ground is ground...) but just don't accidentally jam 5V into any of the other pins there on the diagonal bus.

    If you see any pins labeled AGND, do NOT connect them to the ones labeled GND, and do NOT use them as ground taps for any of your custom digital circuitry. I spent alot of time and energy to create the quietest analog ground I could, and that would mess it up for sure!


    By the way, if you're modifying the OpenBCI 32bit code, you can now select the OpenBCI 32 board from the drop-down menu right inside mpide! Just go to our github and download the latest version. It contains a variant file and instructions for where to stick it are in the readme and also in our tutorial Have Fun!
  • Thanks for the reply. you guys are awesome!!

    -Yen  
  • edited May 2015
    Question on OpenBCI v1 vs v3

    I am trying to replicate the alpha wave detector circuit that Chip Audette did in late 2013. However, he used what I am assuming is either version 1 or 2. It is rectangular and seems to fit directly on top of an Arudino Uno. I have version 3 of the OpenBCI and was wondering if which pins are aligned with which between the Arduino and the BCI board.

    Also, I'd like to know which headers I need to attach/wire out of the BCI board.

    If anyone has any documentation or insight into this I would greatly appreciate it.
  • BraveNW, hi. I merged your question into this existing thread. See some of the previous posts. Another related thread is,

    http://openbci.com/forum/index.php?p=/discussion/166/detecting-alpha-waves

  • biomurphbiomurph Brooklyn, NY
    @braveneuroworlds,

    check out the docs pages we have up describing the hardware.

    Which board to you have, 8bit or 32bit?
  • I finally get the alpha wave control LED working on my v3.

    Basically took chip's OpenBCI_8bits_HexBug here.
    Check Library Hexbug.h and function issueCommand 

    from #digitalWrite(pins[command_pin_ind],LOW);  //ensure that the Arduino pin is set LOW to pull it to ground

    change it to  #digitalWrite(pins[command_pin_ind],HIGH);


    Then it will then trigger HIGH when alpha wave is being detected.
    I am only using A1(GND) and A3(left command = channel 2)

    Thank you chip once again for your awesome website!

     -Yen


  • So glad that you got it to work!

    Chip
  • Hello All!

    I'm new with OpenBCI and I wanted to do some DSP on board.
    I saw this thread and @chipaudette 's work really interested me. I also wanted to try to replicate it on the 32bit board but I'm having troubles merging what @chipaudette did with the "default" firmware provided by OpenBCI for the 32bit board.
    I can't open the link @alfahad sent in 2015... is there any work accomplished on this that I am missing?

    Thank you very much in advance for your help

Leave a Comment