Home » Viewing Your Mind Exercise With the Muse Headband | Jan, 2023

Viewing Your Mind Exercise With the Muse Headband | Jan, 2023

by Icecream
0 comment

So that you’ve acquired a Muse headband and also you’ve tried to mediate with it. It acquired boring — now what?

Properly, you’re actually in the correct place as a result of, on this information, I’ll be outlining each step it takes to be enjoying video games or do different cool issues with the Muse headband.

Relating to brain-computer interfaces with the Muse headband, on-line assets are fairly scarce and most of them are onerous to know due to the curse of information. This text goals to unravel that so the whole lot needs to be fairly clear, no matter your information degree.

There are numerous methods to attach your Muse and ship code to it however on this article, I’ll be going over the right way to do it fully in Python. All of the directions are Mac primarily based however will nonetheless work for Home windows and Linux with slight changes.

Earlier than we contact the Muse headband, we should get the code a part of issues sorted out. Observe the 5 steps under to put in all of the coding dependencies for Python and this undertaking.

Step 1

Since all of the code is in Python, step one is to obtain Python when you haven’t but. Go to their web site right here and obtain the newest model.

Step 2

After putting in Python, you need to open the Terminal in your laptop computer. You are able to do this by discovering the Terminal app or urgent (⌘ + house), then typing within the phrase “Terminal” for the app to pop up. If in case you have bother opening Terminal, verify this out.

Terminal is a text-based interface that enables a person to work together with a pc by getting into instructions as textual content. It’s generally used to execute instructions, run applications, and carry out varied duties on a pc.

That is what Terminal ought to appear like as soon as its open

Step 3

Now that Terminal is up and going, you need to confirm your python set up. To take action, merely copy and paste the code under into your terminal and press “enter”

python --version

If that gave you an error alongside the traces of “command not discovered: python”, you will have the newer model of python so as a substitute, enter the next.

python3 --version

Both one of many instructions above ought to have printed the model variety of your Python software program, if not, chances are you’ll need to return again to step 1 and take a look at it once more.

Step 4

At this level, your Python needs to be up and operating. Earlier than we discover a code editor, we should verify if the Python dependency pip is put in. Pip is a Python package deal that enables the person to put in extra instructions from the Python Package deal Index. With pip in place, you may set up instruments to make use of afterward with only one line.

To verify if pip is put in, enter one of many two instructions under. Should you had so as to add “3” after python in step 3, you’ll want to add “3” after pip on this step.

pip --version

or:

pip3 --version

Step 5

When you’ve confirmed that pip is put in, now’s the time to discover a code editor the place you may edit your code. I like to recommend Visible Studio Code or VS code developed by Microsoft. The wonderful thing about VS code is the very fact it’s simple to make use of out there on Home windows, Linux, and macOS.

Set up can be tremendous simple. Click on right here and obtain it from their official web site following their directions.

As soon as put in, open it up and depart it on the opening web page.

At this level, you’ve efficiently put in all of the code aspect of issues! 🥳 Nonetheless, issues aren’t executed but. The following set of directions will present you the right way to join your headband to the code however I promise, it’ll be extra fingers and enjoyable!

In an effort to join the Muse headband and stream the brainwave alerts to your laptop computer, just a few issues have to be downloaded. Earlier than 2016, streaming from the Muse could possibly be simply achieved by way of Muse Lab, a software program particularly for Muse Growth nevertheless it has since been disabled. 😢

Nonetheless, concern not! After spending a few lengthy days browsing the web, I managed to search out just a few methods to stream the scarf by way of Bluetooth with out Muse Lab.

Initially, among the code was outdated however I ended up discovering issues that barely work and modifying it. Observe the steps under to put in the whole lot.

Step 1

First, to ensure that the Muse headband to talk with the laptop computer, an outlet have to be created. The outlet principally permits the Muse bluetooth alerts to be “plugged in” or related to the laptop computer.

There are a number of apps that assist create this outlet. My private favorite is Petal Metrics which could be put in right here following the web site directions. It’s tremendous person pleasant with an awesome person interface. Petal Metrics works on Home windows, Linux, and macOS.

If Petal Metrics doesn’t work for no matter motive, BlueMuse can be an choice for Home windows customers and Home windows customers solely. Nonetheless, the setup is barely extra difficult requiring Github as a substitute of a easy obtain.

Step 2

Now that an outlet is created, you need to join your Muse headband to it. Beneath kind, choose LSL (lab streaming layer). That is executed within the picture under. LSL alerts are the perfect for the kind of growth we’re doing as a result of it offers the perfect time-synchronization.

To attach your Muse, merely energy it on, flip in your laptop computer’s bluetooth, and click on the massive inexperienced stream button.

It can say “connecting” or “streaming Muse ####” however you received’t see something. Don’t fear, you’ve executed the whole lot proper.

Step 3

Now you’re formally streaming your headband! Go you! At this step, you’re about midway executed the whole undertaking. To really view the information, there must be code which turns the alerts into a visible. Fortunately, Alexandre Barachant created a beautiful program known as Muselsl which achieves this. All now we have to do is set up Muselsl to each view and code with the Muse knowledge.

Muselsl is a Github file, which means it’s extra difficult to obtain however I’ll present you the way in only a second.

First, you need to open up the Muselsl Github repository. You are able to do so right here. A GitHub repository is a flowery approach of a folder for a coding undertaking. Then, you need to clone the repository. On the web page, click on the massive inexperienced “code” button after which copy the hyperlink you see.

With the hyperlink copied, let’s transfer on to the subsequent step.

Step 4

At this level, now we have to go again to VS code we put in at the start. Open VS code when you haven’t already and click on the primary button on the left menu bar. (Check with picture under)

Now, click on the “Clone Repository” blue button. A search bar factor ought to pop up on the prime. Paste the hyperlink you copied from step 3 into the search bar. Open the repository in line with the directions and belief the creator if prompted.

Step 5

You will note a bunch of recordsdata on the left however for now, depart them and open the VS code terminal as seen within the screenshot under.

As soon as open, the terminal ought to look one thing like this on the backside:

Step 6

With the terminal open, you need to use pip to put in muselsl. As a refresher, pip was the command put in on the very starting to put in different python dependancies.

Putting in muselsl is tremendous simple. Paste the next code into the terminal and press “enter”. As soon as once more, the code you paste will depend on which model (3 or with out the three) of python your laptop computer acknowledges.

pip set up muselsl

or:

pip3 set up muselsl

As soon as the command is in, let it load and work it’s magic ✨

One error I bumped into was the truth that my laptop didn’t acknowledge pygatt. Should you run into the identical error, merely enter the next code after which attempt to reinstall muselsl once more following the code above.

pip set up pygatt

or:

pip3 set up pygatt

Step 7

Lastly! It’s time to view and stream the information. First, open up Petal Metrics from earlier and begin streaming.

Then, go to the terminal in VS code and kind within the command under

muselsl view

Your code will discover the Petal Metrics outlet and stream the information when you’re accurately carrying your headband. It ought to look one thing like this:

Utilizing the instructions under, you may alter the way in which the graph seems for a clearer illustration.

Yay! You lastly established a connection and get to view your brainwaves! The following step is to switch the code and get it to acknowledge your blinks 👁️

Now you can view your mind exercise however after a short while, it undoubtedly will get boring. Nonetheless, in case you haven’t observed, every time you blink, the graph exhibits somewhat spike or dip.

One factor we are able to do with this “dip” is to get the pc to acknowledge it. When the pc acknowledges it, blinking can flip right into a sign to do one thing or present one thing. The steps under will present you the right way to get your laptop to acknowledge your blinks.

Step 1

Within the Muselsl GitHub repository you cloned earlier, click on
examples > neurofeedback.py

neurofeedback.py is the file the place the alerts are gathered and printed.

After discovering the file, chances are you’ll be prompted to put in Python for VS Code. If not, go to the left menu bar, click on extensions, search Python, and set up Python. The next picture explains the right way to set up Python in VS Code.

Step 2

With Python put in, return to the neurofeedback.py file and click on the run button (the little triangle) within the prime proper. Clicking run ought to convey up the terminal and there could also be plenty of errors exhibiting within the terminal. Don’t fear, these errors are presupposed to be there.

The errors are a reason for the imports on the prime:

Your laptop doesn’t acknowledge these instructions so kind the next into terminal, one after the other adopted by “enter” to put in every of these unrecognized recordsdata. As soon as once more, relying on the kind of python you may have, kind “pip3” or “pip” to put in.

pip3 set up numpy
or

pip set up numpy
pip3 set up matplotlib
or

pip set up madplotlib
pip3 set up utils
or

pip set up utils
pip3 set up sklearn
or

pip set up sklearn

At this level, you need to be capable to run your code with no drawback. Now let’s transfer on to the subsequent step.

Step 3

Your code is now operating nevertheless it’s lacking an EEG stream. To search out that stream, activate Petal Metrics from earlier than and join your Muse. Now, when you run the code, you need to see loads of numbers. These numbers signify the Alpha waves.

You may be taught extra about these waves in my earlier article.

In brief, alpha waves are your relaxed state waves. They’re largely unaffected by muscle motion like blinks. To make the numbers delicate to blinks, we should print the delta waves.

To detect delta waves, add the next code

print("Delta: ", band_powers[Band.Delta])

Place it the place it’s positioned within the screenshot.

Now, to ensure the opposite waves don’t present, discover the road under within the code and both put a # in entrance of it (commenting it out so the pc doesn’t acknowledge it) or fully delete it.

print('Alpha Leisure: ', alpha_metric)

Should you accomplished all of the directions above accurately, hit run once more and try to be seeing the delta waves.

Step 4

Delta waves can simply detect blinks and muscle actions. Should you take a detailed have a look at the numbers or the screenshot above, you’ll see that the second you “blink”, the numbers grow to be bigger than 1.

Now we all know larger than 1 = blink so what can we do with this data?

Properly, in code, if we would like one thing to occur given a situation, we use an if assertion. Within the case of blink detection, the pc ought to print “blink” if the delta wave is bigger than 1. This may be executed by way of the next line:

if band_powers[Band.Delta] >= 1: 
print("Blink!")

The road needs to be positioned under the road the place you print the delta waves.

Step 5

Operating the code from step 4 offers you one thing alongside the traces of:

Uh oh!
One blink exhibits up as many blinks…

It is because whenever you blink as soon as, your muscle modifications for just a few milliseconds, not only one millisecond. The delta waves are collected faster than the time it takes for one blink.

Happily, there’s a easy strategy to repair this. All you need to do is scroll all the way in which to the highest of the code and modify the experimental parameters.

Even with out understanding the code, you may see a bunch of numbers. Epoch means a time frame and overlap means, nicely overlap.

The shift size under is the epoch-overlap size which in our case is 0.2

Which means each 0.2 seconds, there shall be a brand new eeg measurement. Since 0.2 is approach too quick for a blink, we need to change the quantity to 1.

Because of this OVERLAP_LENGTH = 0 since 1–0 = 1

Your code ought to appear like this after the adjustment:

Step 6

Lastly, let’s run the code once more, blink, and see what occurs.

Voila! Every time you blink, the delta quantity turns into larger than 1 and “Blink!” is printed as soon as.

Conclusion

All set! Your program now acknowledges whenever you blinked!

Take a look at this video of me demonstrating the code:

To clear up your code, you may delete the road that prints the delta waves in order that solely “Blink” prints whenever you blink. I sincerely hope this text helped you in some sense. I do know I undoubtedly struggled lots simply attempting to arrange the code.

If in case you have any issues, be happy to achieve out to me on Linkedin, and as soon as once more, thanks for studying!

GitHub repo: https://github.com/carolrongg/Muse-Blink-Detection.git

You may also like

Leave a Comment