Slow Wave Sleep enhancement, using OpenBCI [2019, complete open source project]

edited January 2019 in Research
Hi there,
My name is Alec Sheffield, I am an undergraduate researcher at Colorado College. I am working with Nina Friedman, who has posted here in the past, on an independent study using the OpenBCI. At our school we take four classes a semester, one at a time for 3.5 weeks. That means that currently we are working full time on our project, and this is our third day.

We are trying to replicate the study here

Auditory Closed-Loop Stimulation of the Sleep Slow Oscillation Enhances Memory

Essentially researchers took data from a prefrontal EEG while participants slept after performing a memory exercise. The EEG was filtered between .25-4 Hz, and slow waves were detected when the signal crossed a threshold amplitude of -80 microvolts.  Once the slow waves were detected, two beeps of pink noise were presented at the top of the next two slow wave up peaks, increasing both the amplitude and number of slow waves, ultimately improving memory consolidation. After detection, the program only needed two parameters which were found manually be analyzing a participants EEG data from a prior night. The parameters were the time between detection and the first up-peak, and then the time between the first and second up-peaks. Ideally we would like to create a program which can find the parameters without manual input.

Initially we were going to work on the project on cloudbrain, but the developer informed us that cloudbrain is not ready and we should look to other options. He recommended just coding it in python ourselves, something we are definitely exploring. The issue is that neither of us has tremendous programming experience, and we only have a month to complete this project. My focus is strongly on neuroscience, physics, and math, so my programming abilities are currently not what I would I like, but one has to make sacrifices for school. I am working on programming independently, but I don't want my EEG usage this month to be limited by my current programming experience.

I was wondering if anyone had any guidance towards programs or packages we should look into for our project. I have python and matlab, along with python-MNE, anaconda, EEGlab, and brainstorm. I also have openvibe, metabrain, and neurovibe. If anyone is interested, we would love for someone with more experience to help guide us and help out with the programming aspects. I'd like to be able to actually perform the slow-wave sleep stimulation as soon as possible, so I could perform testing on the long-term effects of the stimulation.  Thanks in advance for any help, I'm so grateful to have this opportunity thanks to the OpenBCI team, and I know from browsing the forums that the people here are incredibly knowledgeable and experienced with EEG usage.

Have a wonderful day,
Alec


Comments

  • I meant Brainbay by the way, not metabrain. My bad.
  • wjcroftwjcroft Mount Shasta, CA
    Alec, hi.

    You and Nina have chosen an interesting and challenging project. I'll just mention a couple of things that caught my eye. I only glanced at the paper for a minute or so.

    Wiring up a subject for a sleep EEG study could be challenging. As you can see in their paper or video, they used a full head elastic cap that holds the electrodes in place. They might have also used a special gel injected in the cap holes that does not dry out over night. I don't know what materials sleep labs use if they don't have such caps. But I have heard that in the bad old days they would even temporarily 'glue' on separate electrodes to the head using a yuchy thing called Colloidion. The full head cap is definitely an advancement. The Ten20 paste in the kits is usable for some period of time, but I don't know that it would last all night without drying out. That's what they used the Collodion for, as a sealant. Maybe if you had a swim cap on over that?

    I myself have not experienced a night in a sleep lab, but I did have a loaner device, Stephen LaBerge's early Lucid Dreaming Mask, that involved a mask with LEDs and sensors, connected via cables to a bedside computer. Concept sounds reasonable. I was never able to really sleep well with it, was getting tangled up in the wires, etc.

    They show a pattern recognition algorithm in the paper, but my impression is that this only runs during a certain sleep stage? How are you going to categorize the sleep stages in real time? I guess you'll have your partner there by the bedside staying up all night looking for the right stage in which to engage the feedback. This sounds doable, but also potentially draining on the person gathering the data. Sleep stage recognition is a whole subject in itself.

    The suggestion by the Cloudbrain guy seems correct, to code your algorithm in Python. The signal recognition shown in the paper is unique enough, I don't think you'll find pre-built support for it in any of the EEG packages you mention. Although there might be some sleep specific EEG software out there, I don't know. You might try writing the authors to see what they used.

    Be aware that some users have reported the OpenBCI module can momentarily get frozen when collecting very long datasets, typically an hour+. There is a way to automatically reset out of that condition usually by doing a soft reset. Or if your monitor is present there at bedside, they can do whatever manual reset is needed.

    Best regards,

    William

  • Hi William, I actually have been in communication with the author for a while now. They actually only used a single electrode for their slow wave detection, the full cap was just for analysis of the evoked slow waves. They used Matlab for their analysis, and I believe they just used an alpha beta ratio to determine the N3 phase of sleep.

    Do you recommend we start from scratch with python? I was thinking of using the Openvibe python module, considering that Openvibe already has the ability to perform a butterworth bandwidth filter, as well as fourier transformation. My only fear with that is that it'd make it more difficult for any programmers to know to help me, for I'm not sure how much of a learning curve there is to using python within openvibe.

    I've never worked with real-time data in python, but I imagine there must be a way to have a variable be assigned to the most recent filtered EEG value. At that point I would think we would just need to perform a simple for loop for the necessary sleep stage conditions and the amplitude.  

    Thanks for all your help, it was wonderful to meet you William. If you have any more advice or could direct us to some code that could help us get started, that would be fantastic.  And again, if anyone is very interested in the project and would be willing to mentor us a bit, it'd be very appreciated. It's a really exciting area of research.
  • wjcroftwjcroft Mount Shasta, CA
    So are the authors willing to share any of their code with you? Did they use Matlab for the REALTIME biofeedback, or was it just used for post analysis of session recordings? Did they also use EEGLAB / BCILAB? If they're not willing to share their entire codebase with you, could they show you a code snippet of their delta trough recognition algorithm?

    Python libraries are available which do signal processing,

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

    So you don't really need OpenViBE for filters or FFTs. I'll mention Jeremy Frey @jfrey here, he is an OpenViBE wizard. If you are just starting out in programming, you may find the Python easier to deal with than the C++ that OpenViBE is based on. And the Python DSP libraries are likely easier to get up to speed with than the mountain of MATLAB / EEGLAB.

    Chip has some Python EEG code here,

    https://github.com/chipaudette/EEGHacker

    Regards, William

  • Hey William,
    Actually the authors did not even use a sleep stage recognition algorithm, they simply watched and waited until they saw slow waves.  That's what we are planning to do for now, especially since people could nap rather sleep for a full night.  They did share their delta trough recognition algorithm with me.

    We've actually had a great amount of success using openvibe to initially filter the data, and then export the data as a csv file which we can process in python in real time. I've successfully made a program that can make a beep in response to a blink, which is detected very similarly to slow waves. We should be implementing our program to sleeping people next week, so we'll see which hurdles we encounter.

    Thanks for all your help William, it has given us a lot to think about. If we encounter any more specific issues, I can post again. Is it better if I just continue updating this thread, or should I start a new one when we have a new problem?

    Yours truly,
    Alec
  • wjcroftwjcroft Mount Shasta, CA
    Alec, hi. Just continue posting on this thread. Great progress!

  • Interesting stuff.  Any updates?  Did the experiment produce any results?

    I've never heard of 3.5 week semesters.  Don't see how that could work well.
    I remember getting burned on transferring from a quarter system to a semester system based college.  Ended up a partial credit short in a few areas.
  • wjcroftwjcroft Mount Shasta, CA
    Alec, Jake, hi.

    Just saw this article today. Philips announced their SmartSleep EEG device at CES this January. And it is based exactly on the same research you sited. The headband looks to be well designed. Not sure when it will ship, but much anticipation.




    ----

    And peripherally related, the whole arena of lucid dream enhancing tech.



    Jay Mutzafi @jaymutzafi tracks lucid tech and has a system in prototype as well.


    Regards,

    William

  • theorethically, now everyone with an OpenBCI can enhance their slow-wave sleep like mentioned above.


    Not dependent on OpenBCI_GUI, and once the hardware is setup, Ubuntu 18.04 LTS is installed, then it should work out of the box.

    Tutorial on the software maybe soon, maybe not soon, who knows, but usable (and thoroughly tested in research setting) already.
  • wjcroftwjcroft Mount Shasta, CA
    Frederick, wow congratulations.

    "...it should work out of the box".  Your tutorial is certainly welcome. I'm sure you could get some more users on board as well.

    I see you have a 2017 post on the Community page,


    Could you 'clone' parts of that and add your additional links/info, then re-post with your latest title? (Something like "Slow Wave Sleep SWS enhancement with OpenBCI".)

    The original photo was,


    You likely have something better from your poster? What about a photo by someone at the bedside of a SWS user, showing how the laptop, Cyton, cables, electrodes are positioned. The photo above (also on your poster), shows close to a 16 (Cyton+Daisy) channel setup. Could SWS also work with 8 channels? I know the commercial units Philips etc, are just using a limited number of channels on their headband.

    Thanks so much for keeping us up to date.

    William

  • Hi guys, thanks for reviving this thread! I apologize for not updating with my progress, I got caught up in the project and have since moved on to focus on other research topics.

    I was able to replicate Ngo's algorithm, and I tweaked it a bit such that it doesn't require a test night of sleep to define any individual parameters. I was able to increase the amplitude and number of slow waves in a train, but have yet to test any effects on memory/cognition. 

    I didn't have access to many test subjects, and since I didn't feel comfortable testing this on myself long-term with no knowledge of long-term effects I can't comment on that. I'd be a bit surprised if this has that much to offer healthy people in terms of cognition; some studies have already noted a compensatory decrease in SWS after the stimulation ends. That was just within a single night of stimulation, so who knows what'd happen if this was used daily. Nonetheless, in populations with impaired SWS such as the elderly or certain disease states, I feel this holds a lot of promise.

    Frederick, your software looks great. My program only played beeps at the peaks of slow waves during slow wave sleep, when I have time I'll definitely try out your program. I've always been interested in the memory replay research using words/more complex auditory cues, looks really cool! 
Sign In or Register to comment.