• Lucid Dreaming - Dream Views




    Results 1 to 16 of 16
    Like Tree9Likes
    • 4 Post By petko10
    • 1 Post By petko10
    • 2 Post By Nazrax
    • 1 Post By pointofbeing
    • 1 Post By anderj101

    Thread: Sofia-EOG - open source software and hardware for REM detection

    1. #1
      Member Achievements:
      1000 Hall Points Veteran Second Class

      Join Date
      May 2011
      Posts
      25
      Likes
      5

      Sofia-EOG - open source software and hardware for REM detection

      Hello everyone, I haven't posted in a long while, but I want to share my code and hardware concept for REM detection. It all started in this thread. I went quiet since then initially because I wanted to make a Kickstarter for the device. This apparently didn't happen, because I had problems with the hardware and insufficient time to solve them. I consider the concept proven though, since I've had some good recordings. It's unfortunate I lost so much time (not releasing my work as FOSS) with the idea for a Kickstarter, but better late than never.

      Project description:
      The hardware consists of a headband with three electrodes (two lateral ones and one in the centre of the forehead). I had the idea to use conductive thread instead of electrodes but I guess it changed its contact surface too much and/or there was some static electricity or whatever, but it was very hard to get good recordings with the sawn electrodes.
      The instrumental amplifier is the main (one of very few) electronic components. I use for now the AD620 wired pretty much as explained in this tutorial (it pretty much made the project possible, because I'm pretty lame with electronics still). I bought an AD8237 (which is freaking tiny) and had it soldered to a dev board, but I haven't gotten around testing it yet. So, the amplifier outputs analogue data in the same range as a microphone, so we hook it up as one - the output is connected to the microphone slot on the computer (the sound card).
      (btw all of the hardware costs like 10$ (without the soldering iron, that you might need))
      Some pictures from the archives:

      Above are the first and only working electrodes - just a wire soldered to that hardware part I don't know the name of. This picture is only to get an idea, since at the time I was using the headband to try the conductive wire. Here's a pic of that too:


      Here's my very first amplifier setup (not a very informative picture, but still):

      Since then I've fitted it with power supply from usb (not batteries). It's not the safest thing to do but I consider the risk for myself negligible and I don't have to deal with batteries.

      The software is my doing and resides in GitHub - here . The concept is that the application is like a control panel for a series of filters. Every filter is a process that pipes data in and out (read about pipes in unix processes if you want to get into it) . For now I have the input "filter" which is actually the command line application arecord - it just spews out the data from the microphone . This data is fed to the second filter - a "sum" filter I called it (it eliminates noise via outputting the sum for the last n samples , where n is such so the 60hz noise from the power grid is cancelled out but the slow eye movements are not). That's where I'm at. Here's a screenshot from an old record (only the sum-filter output is shown):


      The next step is to deal with the hardware noise, since at the moment the instrumental amplifier falls into some kind of noise-only state in some cases. Basically it works in the beginning or with some adjustment of the electrodes, but then when I try to make a night recording it gets into the noise state somewhere early in the night, and I have practically nothing in the morning. Somewhere in the beginning when I tried my first night recordings I think I had one or two that really showed the REM stages , but then I only viewed the records in Audacity and hadn't developed Sofia-EOG , so I can't compare.

      Btw Sofia-EOG , because I live in Sofia, Bulgaria, and it sounded like a good product name (Kickstarter-wise .. ), but it grew on me, so I'm sticking with it.

      The software is written in Qt, and as soon as someone wants to try it out - post on this thread or in a PM or in GitHub (preferably the first option) and I'll make a how-to for setting it up, maybe upload binaries, etc. It's in C++ and can be compiled for all Qt supported platforms (Win,Linux,Mac..) with minimal work.

      So that's that, thanks for reading, and I really hope that more people get their minds on this project so we can have a cheap EOG device for lucid dreamers.

    2. #2
      Artist in residence Achievements:
      Made lots of Friends on DV Tagger First Class Vivid Dream Journal 10000 Hall Points Veteran First Class
      Highlander's Avatar
      Join Date
      Apr 2011
      Gender
      Posts
      779
      Likes
      1797
      DJ Entries
      322
      Quote Originally Posted by petko10 View Post
      Since then I've fitted it with power supply from usb (not batteries). It's not the safest thing to do but I consider the risk for myself negligible and I don't have to deal with batteries.
      Hmm, I would seriously advise yourself and anybody testing your project to use batteries, no matter how inconvenient. Remember a fault in the PSU, without isolation is gambling with your life. Household mains current across the brain or your heart for example is capable of killing you.
      This includes running the laptop on batteries too.

      On a more lighter note - If you want to reduce noise further then I suggest replacing those copper electrodes in the picture with silver chloride ones and maintain optimum skin contact with a conductive gel maybe.

      UK users would need a 50 hz filter in the software. I don't know if this could be configured in the software panel or if you have a script for this?

      Good luck with the project and the testing BTW. I would help out but I'm really stuck for time, but it is something I will follow as I'm quite interested in these types of projects.
      Last edited by Highlander; 09-23-2015 at 07:00 PM.
      "Reject culture..." "Put the Art pedal to the metal!"
      - Terence McKenna

    3. #3
      Member Achievements:
      1000 Hall Points Veteran Second Class

      Join Date
      May 2011
      Posts
      25
      Likes
      5
      Quote Originally Posted by Highlander View Post
      Hmm, I would seriously advise yourself and anybody testing your project to use batteries, no matter how inconvenient. Remember a fault in the PSU, without isolation is gambling with your life. Household mains current across the brain or your heart for example is capable of killing you.

      On a more lighter note - If you want to reduce noise further then I suggest replacing those copper electrodes in the picture with silver chloride ones and maintain optimum skin contact with a conductive gel maybe.

      UK users would need a 50 hz filter in the software. I don't know if this could be configured in the software panel or if you have a script for this?

      Good luck with the project and the testing BTW. I would help out but I'm really stuck for time, but it is something I will follow as I'm quite interested in these types of projects.
      The filter cuts off everything below 50-60 herz. There is a filter configuration file that specifies the threshold. The conductance is not that big of a problem (I think) , I can't quite figure out what it is that scrambles the instrumental amplifier.
      Highlander likes this.

    4. #4
      Artist in residence Achievements:
      Made lots of Friends on DV Tagger First Class Vivid Dream Journal 10000 Hall Points Veteran First Class
      Highlander's Avatar
      Join Date
      Apr 2011
      Gender
      Posts
      779
      Likes
      1797
      DJ Entries
      322
      Your electrode/skin contact has to be optimum during the whole night. Plus the amp has to be furthest away from any sources of electrical noise, incidentally this includes even the computer itself.

      For example, I did an experiment one time using a scope. I put the probe on my skin where I noticed my body was acting like an antenna for the radiated 50 hz noise. (A pretty sinusodial wave with a measurable voltage amplitude peak to peak.)

      For starters check your contacts and shielded connections are good/clean, etc. Run everything on batteries (inc. laptop) to rule out any 60 hz noise issues.
      Last edited by Highlander; 09-23-2015 at 07:45 PM.
      "Reject culture..." "Put the Art pedal to the metal!"
      - Terence McKenna

    5. #5
      Member Achievements:
      Tagger Second Class Referrer Bronze Vivid Dream Journal Made Friends on DV Veteran First Class 5000 Hall Points
      Nazrax's Avatar
      Join Date
      Oct 2009
      LD Count
      36
      Gender
      Location
      Georgia, USA
      Posts
      199
      Likes
      153
      DJ Entries
      229
      I looked into some of this a while, back, but I felt totally out of my depth and went back to my DIY IR-based mask

      I remember reading over the DIY EEG tutorial you mentioned, and I found another one on DIY EOG. Part of my confusion was that, though EOG is supposed to require less amplification than EEG, that EOG circuit is considerably more expensive than the EEG circuit? I'm also confused (and showing my ignorance) that you say this is an EOG device, even though it's based on the EEG tutorial?

      My own experience with my mask, and somewhat alluded to by Highlander, is that it's very important - and very difficult - to create something that's A) comfortable to wear and B) won't shift too much during the night. Electronics aside, I can't tell you how many iterations I went through (maybe if I cut the board this way, maybe if I shift this strap here) until I found a design that worked!

      Your picture is a bit hard to make out - is the AD620 the only component you're using, or did you also include an opamp and/or a hardware low-pass filter?
      Highlander and IAmCoder like this.
      [36] DILD [0] WILD [0] DEILD
      Goals:[*] Fly [ ] Swim and feel wet [ ] Throw a fireball
      My dream journal

    6. #6
      Member Achievements:
      1000 Hall Points Veteran Second Class

      Join Date
      May 2011
      Posts
      25
      Likes
      5
      Well the electronics aren't that simple, but not hard to setup either: a breadboard, an AD620, a resistor, two wires to the computer, 3 electrodes, and 2x( 3x1.5 volt batteries) (+4,5v and -4,5v) . I'm currently rebuilding , because I couldn't get any sensible output with the old setup (I must have dislocated something, or in the worst case shorted the amplifier in some way). EOG, ECG and EEG are very similar. It's just that the biopotentials that we're measuring are with similar values. ECG can use 3 or more electrodes. EOG usually uses 3 . EEG I think uses around 6 normally , but there are scientific setups that use hundreds. I'm a med student and in neurology we saw that the EEG machine detects eye movements as artefacts (more proof that all three are relatively the same machine).
      About the mask - the idea is that there will always be noise and movement and so on , but in your sleep (especially REM) your body is pretty still. My mask isn't really a mask - its a tennis headband. Here's a picture:

      And it's ok to wear while sleeping. With the electrodes there's the problem that when wearing the mask for the whole night I'm left with 3 slightly visible marks on the forehead. But I guess that's mostly fixable if using different electrodes.
      So, my idea is that if the electrodes have skin contact (it doesn't even have to be optimal), when you aren't moving there should be little noise and the eye movements should be detectable.
      The picture wasn't really rich on information, just a pic from the archive as I mentioned. But the setup then was identical with the EEG tutorial (so just the AD620). With this setup for a long time I managed to get clear ECG and EOG data (with the software filter applied). Now I have to figure out what broke in the last year.
      Last edited by petko10; 09-26-2015 at 01:39 PM.

    7. #7
      Member Achievements:
      1000 Hall Points Veteran Second Class

      Join Date
      May 2011
      Posts
      25
      Likes
      5
      Tonight I got the first successful record (during sleep) in a looong time. It was done with the sawn (conductive wire) electrodes , which as it turns out work well, I guess the problem was with the noise coming from the power line (+5v USB and an invertor chip to get -5v). Here's the graphic (I'm missing some of the REM cycles, but one registered is good enough for now):

    8. #8
      Member Achievements:
      Tagger Second Class Referrer Bronze Vivid Dream Journal Made Friends on DV Veteran First Class 5000 Hall Points
      Nazrax's Avatar
      Join Date
      Oct 2009
      LD Count
      36
      Gender
      Location
      Georgia, USA
      Posts
      199
      Likes
      153
      DJ Entries
      229
      In my own creations, I've had a lot of trouble picking out REM from my data. How did you identify that section as being REM? What do other "noisy" sections of the data look like that differentiates them?
      [36] DILD [0] WILD [0] DEILD
      Goals:[*] Fly [ ] Swim and feel wet [ ] Throw a fireball
      My dream journal

    9. #9
      Member Achievements:
      1000 Hall Points Veteran Second Class

      Join Date
      May 2011
      Posts
      25
      Likes
      5
      I reviewed the section on small scale as showed above. The fluctuations in the second graphic have exactly the same shape, interval, amplitude as when I'm testing the device in real time (e.g. move my eyes and see what happens immediately on the graphic with no noise present). The whole interval that I marked as REM has such elements in it, while the other noises before the REM for example have very chaotic form - huge or variable amplitude, they are higher frequency and so on. It's easier to give an example:

    10. #10
      Member Achievements:
      1000 Hall Points Made Friends on DV Created Dream Journal Veteran Second Class

      Join Date
      Jun 2012
      LD Count
      86
      Gender
      Posts
      567
      Likes
      244
      DJ Entries
      1
      Hey petko10, how are you embedding those traces into your message? Do you need to have the image hosted and embed the picture as a URL?
      Please excuse my ignorance!

    11. #11
      Member Achievements:
      1000 Hall Points Veteran Second Class

      Join Date
      May 2011
      Posts
      25
      Likes
      5
      I upload the picture on imgur (I do it via an extension for GNOME which is super handy, but the chances you're on linux too are kind of slim) , then yes - I embed it as an URL.

    12. #12
      Member
      Join Date
      Nov 2007
      LD Count
      about 18
      Gender
      Location
      Philadelphia suburbs.
      Posts
      208
      Likes
      128
      DJ Entries
      7
      I love that your design has an amp, and two electrodes on the side's rather than Aura. That should mean in theory you should get a much cleaner signal. But even then it took you a long time to get a proper rem signal. I like that you actually took the time to make your device more accurate, but even then I don't see these devices being very accurate as a whole. I love that you never made false claims of super magic signals. If your proper device with lateral placement and an amp is not accurate, then it's hopeless for Auras straight line placement.

    13. #13
      Member Achievements:
      1000 Hall Points Veteran Second Class

      Join Date
      May 2011
      Posts
      25
      Likes
      5
      Well there's the fundamental problem with electrode displacement. As Nazrax pointed out it's very hard to invent a design that is comfortable and stable. Frankly I think the Aura is nicely thought out if they get a good signal. As far as I know if you have good electronics (with filters, good amplifier, insulation everywhere, etc.) the signal can get much better, but as you said - their placement is disadvantageous (I've tried such a placement - the signal is weaker). So in the end it all depends on the testing - their electronics might compensate for the placement. I, myself, aim for simplicity, but as it turns out I'll have to add a preamp and filters to the electrodes, because sometimes the noise scrambles the in-amp and if I push the electrodes around a little bit it gets better again, but I can't do that while I'm sleeping

      Edit: A friend of mine helped me figure out (hopefully) what the "state" that the in-amp got in was. As it turns out an op-amp can get into comparator state where it generates exactly those square waves, and that probably happened because the sound card fed some current back in the amplifier (because computer microphones get powered by the sound card, and I was using a mic jack where the tip and ring were shorted).
      Last edited by petko10; 10-06-2015 at 08:41 PM.

    14. #14
      Member
      Join Date
      Nov 2007
      LD Count
      about 18
      Gender
      Location
      Philadelphia suburbs.
      Posts
      208
      Likes
      128
      DJ Entries
      7
      They will need some very good filters to compensate for a straight line placement. That placement worked for zeo, because they were just giving you an overall look at your sleep quality. However a zeo like placement would be weak for real time rem detection, with lossy signals they better have some fine software to go with their headband. I don't even know where on the Aura an amp would be? On a note of quality electronics they just messed up the ports in their production units that they didn't realize till after production, so they don't actually connect with the unit, they have to resign the thing a 4th time, XD The following quote is from a person who ordered from them, doesn't really make me feel confident that Aura will be compensating for the signal placement.

      "Unfortunately the layout of the snaps was just slightly off from those in our headband, preventing a flush fit with the headband." - Seriously guys? "slightly" off? Just look at the *beep* picture. That's where every industrial designer would take a moment and hide in some dark corner, ashamed."
      Highlander likes this.

    15. #15
      Artist in residence Achievements:
      Made lots of Friends on DV Tagger First Class Vivid Dream Journal 10000 Hall Points Veteran First Class
      Highlander's Avatar
      Join Date
      Apr 2011
      Gender
      Posts
      779
      Likes
      1797
      DJ Entries
      322
      I think in terms of the radio analogy where you have to boost the microvolt signal of the incoming radio station where the front end selectivity (filtering) is critical to receive the signal amongst the others and above the noise.

      As with radio, in EEG you need an excellent (and consistent) signal-to-noise ratio. It is best to acheive this at the start (hence optimum electrodes, contact and positioning, etc.) The op-amp has to provide the best gain with minimum noise, etc.

      However the EOG signal is stronger when compared to that of EEG so it should (in theory) make the designer's job a little easier where you might get away with skimping on high quality components, optimum placement, etc, etc.
      (Comparing with radio where EEG would be 'DX' and EOG or muscle signals would be 'Local.')

      That is all good with analogue radio which is what I was brought up with. With the digital age comes the algorithms, etc. where the signal can be processed, filtered and refined further (and later in the stage) which is what a lot of these newer (EEG) designs including the Aurora are using, or claiming to.

      In regard to the latter I think there will be major contact/placement issues during the night. For example skin contact and temperature changes, sweat and impedence changes. The Aurora will have to self-calibrate and react to these changes to stay on track. If not then loss of signal or noise will be the result.

      I too cannot believe how on earth there is a major discrepancy with the board studs and the headband snaps. I would say that it probably happened from when the early pcb's were developed because if you notice the studs are in the same flat plane as the board (originally.) You can see this on the update photos, etc.
      They simply forgot to add Pi into the equation where iwinks thought everybody's head was like Kryten off Red Dwarf. I.e. A flat forehead!
      So when the headband strap design got sent off to be made this error got magnified as this too has to be curved, although the main site promo page graphics still show a 'flat' design concept relative to the forehead today.

      Also previously on one of the later updates (*** Link Removed ***) iwinks said that the case didn't fit properly (as in a gap) where they blamed it on heat during transit. Really? More like another miscalculation, lol.
      Last edited by anderj101; 10-12-2015 at 02:24 PM. Reason: Removed kicksterter link
      "Reject culture..." "Put the Art pedal to the metal!"
      - Terence McKenna

    16. #16
      Moderator Achievements:
      Veteran First Class Made lots of Friends on DV Populated Wall Vivid Dream Journal Tagger First Class Referrer Bronze 10000 Hall Points
      anderj101's Avatar
      Join Date
      Sep 2010
      LD Count
      ∞ 0
      Gender
      Location
      USA
      Posts
      2,797
      Likes
      5826
      DJ Entries
      230
      Just a reminder: Please do NOT post links to items for sale. KickStarter links or any other type of fundraiser links are also not allowed.

    Similar Threads

    1. DreamJournal (free app for recording dreams) gone open-source
      By Banhurt in forum Dream Signs and Recall
      Replies: 21
      Last Post: 09-13-2015, 08:56 AM
    2. Non-Eye Movement REM detection
      By ethan_hines in forum Lucid Aids
      Replies: 1
      Last Post: 06-29-2009, 02:26 AM
    3. Looking for good open source video editor
      By thedogsmeow in forum Tech Talk
      Replies: 6
      Last Post: 01-01-2009, 12:32 AM
    4. [SOFTWARE] Dream Journal software {look what i found on my hard drive...}.
      By Identity X in forum General Lucid Discussion
      Replies: 4
      Last Post: 12-02-2007, 05:13 PM

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •