Backyard Brains Logo

Neuroscience for Everyone!

+1 (855) GET-SPIKES (855-438-7745)


items ()

Pick a Card Project Update: Deploying Hardware for TinyML Model

Pick a Card Project Update

— Written by Nour Chahine —

Before I start discussing my updates, I have an announcement to make: I solemnly swear that I will solely be working with SSVEPs for the remainder of my project!

Over the past few weeks, I worked on feeding different forms of data into the neural network. I mainly applied two approaches: the power spectral density vector method and the notch filter knockout vector method. Both methods rely on quantifying the EEG response relative to the flashing frequencies of the cards.

Power Spectral Density Vector

The power spectral density vector method involves computing the power spectral density of the EEG signal, and then making a vector of the total power of the signal at each of the target frequencies.

Pick a Card Project Update

In the plot above, we can see the average power spectral density plot of my subject and Fellow Ariyana looking at a card flashing at 7.5 Hz (in red), overlayed with the individual epochs. Notice the peak at 7.5 Hz?

To quantify this information, I first compute the total power at each target frequency + 0.1 Hz: pf1, pf2, pf3, and pf4. Then I divide by the total power to normalize. 

In this example, the target frequencies are f1 = 4.3 Hz, f2 = 6.66 Hz, f3 = 7.5 Hz, and f4 = 8.75 Hz. The resulting power spectral density vector obtained {0.15, 0.05, 0.61, 0.17} shows that pf3 has the greatest value. This means that the subject was most likely looking at the card flashing at f3= 7.5 Hz

power spectral density

Notch Filter Knockout Vector

The notch filter knockout vector conveys information similar to that of the PSD vector, but it is obtained differently. A notch filter is a type of band-stop filter, which is a filter that attenuates frequencies within a specific range while passing all other frequencies unaltered. If I apply a notch filter of 5 Hz to a signal, then only the 5 Hz components of my signal are attenuated, while the others remain unchanged. How can this be useful?

The working principle here is that I obtain the total power of the signal, Ptotal. Then, I apply a notch filter to the signal at each of the target frequencies. Afterwards, I compute the power of the notched signals at each notch frequency, Pf1 Pf2 Pf3 and Pf4. By subtracting the notched signal power from the total power, you can determine how much the notched frequency contributed to the power. In other words, you can tell how much f1, f2, f3, and f4 each contribute to the total power of the signal. This information can be represented in a vector similar to the PSD vector:

The same data from the PSD example generates the following notch filter knockout vector:

We can deduce that the frequency f3 = 7.5 Hz contributed the most to the total power of the signal. Therefore, the subject was most likely looking at the card flashing at frequency f3. 

Both vectors convey similar information, but do they train the machine learning model in a similar manner?

That is what I tested next. Using Edge Impulse, I fed PSD vectors and notch knockout vectors that I computed from all of my collected data so far into a neural network. The table below highlights the training and testing accuracies obtained using the PSD vector and the Notch Knockout Vector as a model input.

Training AccuracyTesting Accuracy
PSD Vector73.5 %45.1 %
Notch Knockout Vector50 %4.35 %

Evidently, the PSD vector performed better. The Notch knockout vector is still useful for fast computations, though. 

I am now at the stage of hardware deployment. The goal is to deploy the best working model onto the Wio Terminal so that it is able to perform live classification when hooked up to an EEG channel. Before deploying the ML model, I started by hardcoding the classification process to verify that live classification can happen to begin with. I used the notch knockout method in combination with simple thresholding, and the code has been working for test signals from the function generator. 

Hopefully, it should also work with EEG signals. After I test this, I will deploy the ML model in combination with a web app I am developing on the side. Excited to get to the finish line!


No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.