<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kelly Yang on Medium]]></title>
        <description><![CDATA[Stories by Kelly Yang on Medium]]></description>
        <link>https://medium.com/@kellyang2006?source=rss-64cd03831151------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Kelly Yang on Medium</title>
            <link>https://medium.com/@kellyang2006?source=rss-64cd03831151------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:12:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kellyang2006/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Learning to Decode EEG Motor Imagery Tasks Using Scout ESI and CNN Algorithms]]></title>
            <link>https://medium.com/@kellyang2006/learning-to-decode-eeg-motor-imagery-tasks-using-scout-esi-and-cnn-algorithms-2ccaec8209ca?source=rss-64cd03831151------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ccaec8209ca</guid>
            <category><![CDATA[replicate]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[aritifical-intelligence]]></category>
            <category><![CDATA[brain-computer-interface]]></category>
            <dc:creator><![CDATA[Kelly Yang]]></dc:creator>
            <pubDate>Sun, 24 Mar 2024 05:32:21 GMT</pubDate>
            <atom:updated>2024-05-27T22:35:47.086Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tl;dr</h3><ul><li>Reading brain signals to interpret movement intentions could transform lives for people with paralysis. By decoding patterns within electroencephalography (EEG) data that reflect different motor imagery tasks like imagining left hand movement or tongue movement, we may be able to translate these thought commands into prosthetic limb control or computer interaction.</li><li>However, accurately classifying the complex and often noisy EEG datasets recorded during motor imagery remains extremely challenging.</li><li>I aimed to utilize an automated framework that combines EEG source imaging (ESI) and convolutional neural networks (CNNs) to accurately distinguish EEG signals corresponding to multiple motor imagery tasks. I focused the analysis on key regions of the brain’s motor cortex tied to different body part activations, extracted informative spatial and time-frequency features, and used these inputs to train a customized CNN model.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WF_xqSoSKSNGT-Lc" /><figcaption>Photo by <a href="https://unsplash.com/@averey?utm_source=medium&amp;utm_medium=referral">Robina Weermeijer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>The ability to interpret human brain signals and translate them into commands for external devices is a powerful concept that has further developed in recent years. Brain-computer interfaces (BCIs) aim to provide a direct communication pathway between the brain and computers or machines, without the need for physical movements. This technology has the potential to change lives for individuals with severe motor impairments, allowing them to regain independence and control over their environment using just their thoughts.</p><p>However, developing accurate and usable BCIs remains a significant challenge, particularly when it comes to decoding multiple distinct brain patterns associated with different intended movements or motor imagery tasks. Achieving high classification performance across many simultaneous options is crucial for creating intuitive BCI systems. Additionally, systems that can generalize well across different users is extremely important in real-world scenarios.</p><p>In a recent study published in the Journal of Neural Engineering, researchers from Northeast Electric Power University and Changchun University of Science and Technology in China have proposed a novel approach that combines advanced signal processing techniques with deep learning methods to tackle these challenges in multi-class motor imagery decoding for BCIs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tszRSI0qluQedi1etjad3g.png" /></figure><h3>The Approach</h3><p>At the core of this work is the integration of two powerful techniques: EEG source imaging (ESI) and convolutional neural networks (CNNs). ESI is a computational method that models the source of brain activity within the three-dimensional volume or cortical surface, based on the electrical potentials measured on the scalp by EEG sensors. By working in the “source space” rather than the raw sensor space, ESI can provide a more informative representation of the underlying neural processes, accounting for the complex propagation of electrical signals through the head volume.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*uIcgE-J40Pz1QWse.jpg" /></figure><p>The second key component is the use of CNNs, a type of deep learning neural network architecture that has shown remarkable success in various machine learning tasks, particularly in areas like computer vision and image recognition. CNNs are able to automatically learn hierarchical feature representations directly from data, making them well-suited for decoding the intricate patterns present in neuroimaging data such as EEG.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1K5NoNH--RwpIgnG.png" /></figure><h3>The Process</h3><p><strong>A. Data Preprocessing:</strong></p><p>Before any analysis, the raw EEG signals were filtered to retain only the frequency bands most relevant for detecting sensorimotor rhythms associated with motor imagery (8–30 Hz). The data was separated into four distinct tasks: imagining opening/closing the left fist, right fist, both fists, and both feet.</p><p><strong>B. Source Computation:</strong></p><p>To convert the EEG data from the sensor space to the source space, there were two key problems. The forward problem involves modeling how electrical currents within the brain propagate through the head volume to produce the observed scalp potentials. This was accomplished using a boundary element method (BEM). The inverse problem, which calculates the source currents that best explain the measured EEG data, was solved using a weighted minimum norm estimation (WMNE) approach. These steps effectively mapped the sensor readings onto a three-dimensional representation of brain activity.</p><pre>%Compute forward solution<br>headmodel = bst_headmodelnew(&#39;kernel::meg::OpenMEEG&#39;);<br><br>%Compute inverse solution  <br>InverseKernel = bst_inverse_kernel(...);<br>sources = bst_inverse_2018(..., InverseKernel);</pre><p><strong>C. Scout Creation:</strong></p><p>Within the motor cortex region of the reconstructed brain activity, ten distinct “scout” regions of interest (ROIs) were identified. These scout ROIs were strategically positioned to cover the areas of the motor cortex that are known to be closely linked to the different motor imagery tasks based on functional maps like the motor homunculus. By focusing the analysis on these task-relevant regions, more informative features related to the imagined movements could be extracted.</p><p><strong>D. Feature Extraction:</strong></p><p>From the time-series data corresponding to each of the ten scout ROIs, a joint time-frequency analysis (JTFA) approach based on Morlet wavelets was used to extract features. This technique captures information not just about the temporal patterns but also the spectral content of the neural activity within each scout region. The resulting two-dimensional time-frequency maps provide insight into the underlying neural dynamics associated with each motor imagery task.</p><pre>from scipy.signal import morlet<br><br># Wavelet parameters<br>f_c = 1 <br>sigma_t = 3 / (2 * np.pi * f_c)<br><br># Compute wavelet coefficients<br>wav = morlet(np.linspace(-3,3,128), f_c, sigma_t) <br><br># Get time-freq maps<br>tf_maps = [np.convolve(scout_ts, wav, mode=&#39;same&#39;) for scout_ts in scout_time_series]</pre><p><strong>E. CNN Architecture and Training:</strong></p><p>The time-frequency maps from the scout ROIs were then fed as input to a deep convolutional neural network architecture specifically designed for this application. The CNN consisted of six convolutional layers, two max-pooling layers for downsampling, and three fully-connected layers for final classification. Through an iterative training process, the CNN learned to automatically extract the most discriminative features from the time-frequency maps, finally being able to map these patterns to the corresponding motor imagery classes. The trained model could then classify new, unseen data into one of the four motor imagery tasks.</p><p>The proposed approach combining scout ESI and CNNs achieved significant results on a publicly available EEG dataset for motor imagery classification (PhysioNet database). Across ten subjects, an overall mean accuracy of around 90% in discriminating the four motor imagery tasks.</p><h3>Impact</h3><p>By achieving high classification accuracies across multiple simultaneous movement imaginations, we are able to further develop BCIs to be more intuitive and impactful. Individuals with severe motor disabilities, neural prosthetics for restoring lost functionality, and even able-bodied users will soon be able to utilize this technology to enhance their lives.</p><p>Cross-subject generalization in this project addresses one of the challenges in developing practical BCI systems that can be used without extensive training. Being able to transfer a pre-trained model to new individuals could improve the accessibility and scalability of BCI technologies.</p><h3>Reflection</h3><p>In the process of understanding and replicating this research, I gained valuable insights into neural signal processing and the techniques that needed to be used in order to decode information.</p><p><strong>A couple of takeaways from me:</strong></p><ol><li>Identifying the problem</li></ol><p>By understanding the motor imagery decoding task as a pattern recognition problem in the source space, powerful machine learning techniques like CNNs were leveraged. Additionally, utilizing two techniques combined was able to allow for a much higher accuracy and better results.</p><p>2. Real-world implementation</p><p>While BCIs have a lot of potential, there is still a lot of work to be done in this realm before BCIs are able to be used in the real-world. There needs to be consideration for the ethics and privacy of all kinds of technology.</p><p><strong>Next steps:</strong></p><p>In the future, I hope to explore more advanced neural network architectures, such as attention mechanisms or generative models, which could further enhance the feature learning capabilities. Additionally, I hope to incorporate information from other neuroimaging modalities like functional near-infrared spectroscopy (fNIRS) or functional magnetic resonance imaging (fMRI), which could provide a more comprehensive understanding of the neural processes involved.</p><p>Tutorial followed: <a href="https://github.com/SuperBruceJia/EEG-Motor-Imagery-Classification-CNNs-TensorFlow?tab=readme-ov-file">https://github.com/SuperBruceJia/EEG-Motor-Imagery-Classification-CNNs-TensorFlow?tab=readme-ov-file</a></p><blockquote><em>Thanks for reading! Feel free to follow, connect with me on </em><a href="https://www.linkedin.com/in/kelly-yang-498740215/"><em>LinkedIn</em></a><em>, or email me at kellyang2006@gmail.com for upcoming articles. Also be sure to stay up to date with my newsletter on </em><a href="https://kellyang2006.substack.com/"><em>Substack</em></a><em>. Please let me know if you have any questions or comments.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ccaec8209ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Classifying Sleep Stages with a Convolutional Neural Network on Raw Electroencephalogram (EEG) Data]]></title>
            <link>https://medium.com/@kellyang2006/classifying-sleep-stages-with-a-convolutional-neural-network-on-raw-electroencephalogram-eeg-data-7a3a012e7db0?source=rss-64cd03831151------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a3a012e7db0</guid>
            <category><![CDATA[brain-computer-interface]]></category>
            <category><![CDATA[cnn]]></category>
            <category><![CDATA[sleep]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[sleep-disorders]]></category>
            <dc:creator><![CDATA[Kelly Yang]]></dc:creator>
            <pubDate>Tue, 28 Nov 2023 22:17:16 GMT</pubDate>
            <atom:updated>2023-11-29T01:47:02.176Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Why?</strong></h3><p>Sleep is an important aspect of our everyday lives, with an estimated 50 to 70 million Americans struggling with chronic sleep disorders, according to the National Institute of Health. However, a significant number of cases remain undiagnosed or untreated because of the inconveniences and long wait times associated with traditional sleep studies.</p><p>By understanding someone’s sleep patterns, we can gain valuable insights into their overall health. Sleep plays a critical role in both physical and mental health, such as influencing processes like memory consolidation, emotional regulation, metabolism, chronic disease risk, and immune response. Analyzing sleep patterns can not only help identify sleep disorders such as insomnia and sleep apnea, but can also be used as a guide for improving quality of life.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h8qTxc32T-wFLGnn" /><figcaption>Photo by <a href="https://unsplash.com/@qstevenson?utm_source=medium&amp;utm_medium=referral">Quin Stevenson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine being able to monitor your sleep and gain all the benefits of understanding your sleep patterns by simply wearing a headband. This headband would track your brain signals and classify your sleep stages, eliminating all the hassle of conventional methods.</p><h4>What is sleep staging?</h4><p>Sleep staging is a method to determine which sleep stage a person is in by analyzing their EEG (electroencephalogram) — a measure of the brain’s electrical activity. This process provides insights into normal and abnormal sleep patterns during different stages of sleep, and is crucial for diagnosing sleep disorders and assessing sleep quality.</p><p>Sleep stages are identified by observing changes in the brain’s electrical patterns and specific events characteristic of different sleep stages, such as sleep spindles (short bursts of brain activity that occur during early stages of sleep) or rapid eye movements (brain activity is high and eyes move swiftly around).</p><p>Sleep recordings are typically divided into 30-second intervals, and each interval is categorized into one of the five following stages:</p><p>i. <strong>wakefulness (W):</strong></p><ul><li>Characteristics: Active mental and physical engagement with the environment</li><li>Brain Activity: Fast and varied brain waves</li></ul><p>ii. <strong>light sleep (N1)</strong></p><ul><li>Duration: Less than 10 minutes</li><li>Characteristics: Slowing of heartbeat, breathing, and eye movements; muscle relaxation</li><li>Brain Waves: High-amplitude alpha waves (8–13 hertz, relaxed and calm state), progressing to theta waves (4–7 hertz, light sleep or deep relaxation)</li></ul><p>iii. <strong>deeper sleep (N2)</strong></p><ul><li>Characteristics: Continued slowing of heartbeat, breathing, and deeper muscle relaxation</li><li>Body Changes: Decreased body temperature, cessation of eye movements</li><li>Brain Waves: Theta waves, sleep spindles (12–14 hertz), and k-complexes (single sharp wave)</li></ul><p>iv. <strong>deep sleep (N3):</strong></p><ul><li>Duration: 20 to 40 minutes</li><li>Characteristics: Lowest levels of heartbeat and breathing; difficulty in awakening</li><li>Brain Waves: Delta waves (0.5–4 hertz, restorative state)</li><li>Functions: Bodily recovery, human growth hormone release</li></ul><p>v. <strong>rapid eye movement (R)</strong></p><ul><li>Characteristics: marked by rapid eye movements, vivid and emotional dreaming</li><li>Brain Activity: Fast and low amplitude, similar to wakefulness</li></ul><p><em>*hertz (Hz) typically refers to the number of cycles per second in a wave</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G92EEe9M8tlkoAbQ.jpeg" /></figure><p>To classify the different sleep stages, I trained a convolutional neural network (CNN) on a <a href="https://physionet.org/content/sleep-edfx/1.0.0/">Sleep Physionet</a> dataset, which contains 153 overnight sleep recordings from 78 individuals. A convolutional neural network is a type of deep learning system that can be trained to identify and understand patterns in large amounts of data.</p><h3><strong>The Process</strong></h3><h4>1. Setting up the environment</h4><p>The first step involves setting up the Python environment and importing the packages and modules required to run and analyze the data.</p><pre>!pip install torch<br>import torch<br>device = &#39;cuda&#39; if torch.cuda.is_available() else &#39;cpu&#39;</pre><p>The code snippet above demonstrates the installation of PyTorch, which is a popular library for building neural networks. Then, it checks if a GPU is available for faster computation.</p><h4>2. Loading data</h4><p>The EEG data used for training is fetched from the <a href="https://physionet.org/content/sleep-edfx/1.0.0/">Sleep Physionet</a> dataset. This dataset contains numerous EEG recordings, each corresponding to different sleep stages. The following code snippet demonstrates how to import the necessary module from mne library and fetch the data:</p><pre>import mne<br>from mne.datasets.sleep_physionet.age import fetch_data<br>subjects = range(30)<br>recordings = [1]<br>fnames = fetch_data(subjects=subjects, recording=recordings, on_missing=&#39;warn&#39;)</pre><p>Typically, high amplitude, low-frequency waves indicate deep sleep (N3), while low amplitude, high-frequency waves are typical for the wakefulness and REM stages.</p><p>The plot below shows brainwave patterns, specifically the various amplitudes and frequencies of the raw EEG signals. It’s difficult to interpret due to the overwhelming amount of information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*bEGUWQaKmdwGdX4pWBOVeA.png" /></figure><h4>3. Preprocessing data (filter, window)</h4><p>The raw EEG data needs to undergo preprocessing, which includes filtering to focus only on relevant frequencies. This is crucial as EEG signals contain a lot of noise and irrelevant information. The code snippet below applies a high-pass filter to keep frequencies below 30 hertz. Typically, the 30 hertz threshold is implemented because any signals above are considered high-frequency and are not commonly associated with traditional brain wave patterns, such as alpha, theta, and delta waves.</p><pre>l_freq, h_freq = None, 30<br>for raw in raws:<br>    raw.load_data().filter(l_freq, h_freq)</pre><p>Plotting the same data, except with the filter:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k1d8NltV5xwFYi2udybiew.png" /></figure><p>Notice that in contrast to the first plot, most of the data above 30 hertz has been cut off and only relevant information remains.</p><h4>4. Making splits</h4><p>To ensure the model’s ability to learn effectively and increase its accuracy, the data can be split it into three different sets:</p><pre>test_ds, train_ds = pick_recordings(dataset, test_recs)<br>train_ds, valid_ds = train_test_split(train_ds, n_subjects_valid, split_by=&#39;subj_nb&#39;)</pre><ol><li>the <strong>training set</strong> is used to train our model and learn its parameters <br>(⚽ analogy: regular practice sessions)</li><li>the <strong>validation set</strong> is used to adjust the model’s parameters to improve its accuracy and ability <br>(⚽: scrimmages to prepare for an official game)</li><li>the <strong>test set</strong> is used to assess the model’s performance on new and unseen data <br>(⚽: official game that the practice and scrimmages were helping prepare for)</li></ol><h4>5. Creating the model</h4><p>To start, a CNN architecture is similar to a design blueprint, which specifies how different layers can analyze the unique features of EEG data. In this case, a CNN architecture proposed by Chambon et al. (2018) is used.</p><p>Then, the CNN model is the actual system crafted from that blueprint, trained to accurately identify and interpret the subtle patterns that signify different sleep stages in the EEG data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sG57BH47JljYlhTACJ21mQ.png" /><figcaption>CNN architecture proposed by Chambon et al. (2018)</figcaption></figure><p>The <strong>input</strong>, on the left, is a 30-second window of EEG data. This means that the CNN looks at 30-second segments of EEG readings to make its classification. C refers to the number of different EEG data channels being used.</p><p>The <strong>output</strong>, on the right, is a 5-dimensional vector where each dimension is matched to one of the 5 sleep stages(W, N1, N2, N3, R).</p><p>In between, there is a long process involving:</p><ul><li>The CNN uses several <strong>convolutional layers</strong>, each extracting increasingly complex features from the EEG data .<br>(⚽: player scanning a small area of the field with their eyes, recognizing specific patterns like player formations or ball movements. This focused analysis across different sections of the field helps build a comprehensive understanding of the game)</li><li><strong>Max pooling </strong>is a process in neural networks used to reduce the size of the input data, making it easier to process without losing important information.<br>(⚽: selecting the most significant play or event within a specific time frame during a soccer match, helping emphasize key information)</li><li><strong>Nonlinearities</strong> introduce complex patterns that the network can learn and react differently to.</li><li>After passing through these layers, the data (now transformed into a set of features) is flattened and fed into a fully-connected layer, which combines all the learned features from previous layers and makes the final decision on which sleep stage the 30-second segment corresponds to.</li></ul><h4>6. Training and monitoring</h4><p>The training and monitoring phase is similar to an intensive learning period where the model is exposed to a large amount of information from the training set and must learn to understand and interpret it correctly.</p><p>In the <strong>training loop</strong>, the model is repeatedly exposed to the data, learning from its mistakes. Each pass through the training data is called an epoch, where the model tries to predict the sleep stage for each data point and adjusts its internal parameters based on its accuracy.</p><p>In the <strong>monitoring loop</strong>, the model’s performance is evaluated on a separate set of data (validation set). This step ensures that it’s learning to make accurate predictions on new, unseen data based on previous learnings, and not just memorizing the training data.</p><p>In this learning process, two key components guide the model’s learning:</p><pre>from torch.nn import CrossEntropyLoss<br>from torch.optim import Adam<br><br>optimizer = Adam(model.parameters(), lr=1e-3, weight_decay=0)<br>criterion = CrossEntropyLoss(weight=torch.Tensor(class_weights).to(device))</pre><ol><li><strong>Optimizer (Adam): </strong>Think of the optimizer as a guide that tells the model how to adjust its learning based on its performance, such as providing advice for adjustments and how to make learning more efficient.</li><li><strong>Criterion (Cross-Entropy Loss): </strong>This is the measure used to determine how well the robot is performing. If the robot makes a wrong prediction, the loss function calculates how bad this mistake is. The goal is to minimize this loss during training.</li></ol><p>Once training is done, a <strong>learning curve</strong> can provide a visual representation of the robot’s learning progress. It shows how the robot’s performance (accuracy) improves and how its mistakes (loss) decrease over time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cSfEcTUclKVeHr7xNiJW0g.png" /><figcaption>Learning curve of the model</figcaption></figure><h4>7. Visualizing results</h4><p>To understand how well the model is performing, a tool called a c<strong>onfusion matrix</strong> can be used, where:</p><ul><li>Each row represents the <em>actual</em> sleep stage</li><li>Each column represents the <em>predicted</em> stage</li><li>Each cell in the grid shows the number of times the model made a particular prediction</li><li>The diagonal showcases correct predictions, while off-diagonal elements reveal where the CNN stumbled</li><li>At points where the number is big, the model is confusing the different sleep stages</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*i8m5Ahw2aG1Jb0DknnH97w.png" /></figure><p>The confusion matrix gives a detailed breakdown of correct and incorrect predictions, and other tools (e.g. hynogram) can be used to further analyze and pinpoint areas of improvement for the model.</p><h3>Outcome of the Model</h3><h4>Model’s Accuracy</h4><p>The performance of the model on the test set was determined using balanced accuracy and Cohen’s kappa score.</p><p>The <strong>balanced accuracy</strong> of the model on the test set was <strong><em>0.665, </em></strong>meaning that the model correctly classified 66.5% of the sleep stages on average. This measure is extremely helpful because it balances out the differences in representation across different sleep stages in the dataset, so it makes sure that the model is good at identifying all types of sleep stages, not just the most common ones.</p><p>Additionally, the model achieved a <strong>Cohen’s kappa score</strong> of <strong><em>0.641</em></strong> on the test set. Cohen’s kappa is a statistic that measures whether the model’s predictions and the actual categories match (determine if it’s accurate or not), beyond just chance. A score of 1 would mean perfect agreement and 0 would mean no agreement (beyond chance). A kappa score of 0.641 means that the model’s predictions align decently well with the true categories, and goes beyond what would be expected just by chance.</p><p>Thus, the model has a reasonably good ability to classify sleep stages from EEG data, but there’s still room for improvement, especially in making it more sensitive to less common sleep stages.</p><h4>Potential Uses of the Model</h4><p>Sleep reflects health and unhealthy levels of sleep are linked to chronic conditions. The model can help diagnose various sleep disorders. For example, by classifying sleep stages, it can help identify abnormalities in sleep patterns (like excessive REM sleep or lack of deep sleep) which are potential symptoms of conditions like insomnia, sleep apnea, or narcolepsy. In general, it can be beneficial to understand sleep patterns, as better sleep can allow for better focus, clearer thinking, etc.</p><h4>Improving the Model</h4><p>To further improve the model:</p><ul><li>Increasing datasets and diversity can allow for better performance as the model can spot patterns that it wouldn’t have recognized with a smaller sample.</li><li>Experimenting with different neural network designs/architectures can lead to improved accuracy and efficiency.</li><li>Optimizing training hyperparameters, such as learning rate, batch size, etc. can reduce the training time and allow the model to generalize better on new data.</li><li>Addressing limitations such as imbalances in the dataset (certain sleep stages are represented more than others) using techniques like applying different weights to the different stages, generating synthetic data for stages that are underrepresented, etc.</li></ul><h3>Takeaways</h3><ul><li>Since sleep is a crucial aspect of our lives, understanding different sleep stages can allow for diagnosis of sleep disorders or provide insight into sleep patterns.</li><li>A convolutional neural network is a method to recognize patterns in large amounts of data and can be applied to various fields, including BCIs.</li><li>In this case, I used a CNN to classify different sleep stages based on raw EEG data. Personally, I’m interested in the intersection of AI and BCIs, so this was extremely informative.</li><li>I learned about various different components of machine learning techniques, including preprocessing EEG data, constructing and training a CNN, and evaluating its performance in classifying different sleep stages.</li><li>To learn more, check out the tutorial I followed <a href="https://colab.research.google.com/github/hubertjb/dl-eeg-tutorial/blob/main/sleep_staging_physionet.ipynb">here</a>!</li></ul><h3>Next Steps</h3><p>In the future, I hope to better understand EEG data for neurological diseases, such as Parkinson’s and Alzheimer’s. These diseases affect a large number of people worldwide and they significantly reduce quality of life because of their progressive nature and their impact to cognitive and motor functions. Through the use of BCIs and AI, there is potential for earlier diagnosis, better monitoring of disease progression, and possibly more effective treatments.</p><blockquote>Thanks for reading! Feel free to follow, connect with me on <a href="https://www.linkedin.com/in/kelly-yang-498740215/">LinkedIn</a>, or email me at kellyang2006@gmail.com for upcoming articles. Also be sure to stay up to date with my newsletter on <a href="https://kellyang2006.substack.com/">Substack</a>. Please let me know if you have any questions or comments.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a3a012e7db0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Brain-Computer Interfaces for Rehabilitation]]></title>
            <link>https://medium.com/@kellyang2006/brain-computer-interfaces-for-rehabilitation-80f3a78d9655?source=rss-64cd03831151------2</link>
            <guid isPermaLink="false">https://medium.com/p/80f3a78d9655</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[prosthetics]]></category>
            <category><![CDATA[brain-computer-interface]]></category>
            <dc:creator><![CDATA[Kelly Yang]]></dc:creator>
            <pubDate>Sat, 28 Oct 2023 22:27:30 GMT</pubDate>
            <atom:updated>2023-11-25T01:36:57.790Z</atom:updated>
            <content:encoded><![CDATA[<p>Think about the last device you interacted with — maybe the mouse you clicked to open this article or the smartphone screen your fingers just scrolled.</p><p>Pretty simple, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YMCc0hFLqpas5RU_" /><figcaption>Photo by <a href="https://unsplash.com/@alesnesetril?utm_source=medium&amp;utm_medium=referral">Ales Nesetril</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Now, picture doing the same interactions, but just by thinking about it.</p><p>No, there’s no need for a physical trackpad nor a keyboard.</p><p>And no, this is not a science fiction scenario — it’s the reality of Brain-Computer Interfaces (BCIs). While controlling gadgets with our minds may seem extremely entertaining, it’s a game changer for those on the long road of rehabilitation after a stroke or serious trauma. BCIs are transforming the exhaustive process of recovery into a more improved and effective journey.</p><h3>Understanding Brain-Computer Interfaces</h3><p>Although the term may ring a bell, you may be wondering, “What exactly are BCIs? And how do they even work?”.</p><p>In a nutshell, BCIs create a direct communication pathway between the brain and an external device. They decode brain/nervous system signals and turn it into information that a machine can interpret.</p><p>There are several types of BCIs, each utilizing different methods to interface with the brain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9fkuMUjFR0OuDmSca4icEg.png" /><figcaption>Different types of BCIs from <a href="https://linkmix.co/19202300">Source</a></figcaption></figure><p><strong>Invasive BCIs</strong></p><p>Invasive BCIs require surgical implantation of electrodes (specialized sensors designed to pick up electrical signals from the brain) directly into the brain tissue. Although the quality of the signal is the highest, the process is more expensive and comes with a larger number of risks.</p><p><strong>Semi-Invasive BCIs</strong></p><p>Semi-invasive BCIs involve the placement of electrodes on the brain’s surface or in the dura mater, the protective layer covering the brain, without penetrating the brain tissue. An example is electrocorticography (ECoG), which allows for a better spatial resolution/understanding where the signal comes from and a lower clinical risk than invasive BCIs.</p><p><strong>Non-invasive BCIs</strong></p><p>Non-invasive BCIs are typically more popular due to their lowered risk and costs. However, they generally offer lower signal quality in comparison. A few examples of non-invasive BCIs include:</p><ul><li><strong>Electroencephalography (EEG): </strong>Measures electrical activity on the scalp using electrodes.</li><li><strong>Functional Magnetic Resonance Imaging (fMRI): </strong>Records changes in blood flow in the brain, providing a highly detailed spatial resolution.</li><li><strong>Functional Near-Infrared Spectroscopy (fNIRS): </strong>Utilizes near-infrared light to measure blood oxygenation in the brain.</li><li><strong>Magnetoencephalography (MEG):</strong> Measures the magnetic fields produced by neural activity.</li></ul><p>Among these, EEG is known for its lower costs, temporal resolution, portability, and convenience, making it especially useful in various applications, including medical diagnoses, neurofeedback, and as a key component in BCIs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*nJ8z8B1wCSo4JM3N.jpg" /><figcaption>Different types of BCIs (non-invasive: EEG, semi-invasive: ECoG, invasive: intracortical microelectrode) from <a href="https://thejns.org/focus/view/journals/neurosurg-focus/49/1/article-pE2.xml">Source</a></figcaption></figure><p><strong>Now, what does the actual process look like for an EEG-based BCI?</strong></p><ol><li>The brain constantly generates electric signals due to the communication between neurons. Large clusters of neurons fire together, producing enough signal for measurement through EEG.</li><li>The brain’s electrical activity is captured and relayed to a computer.</li><li>Then, algorithms process the information, converting these complex signals into simple commands that can control an external device, such as a computer keyboard.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/0*Apijt1i9Xdk1J8Nr.png" /><figcaption>Main Components of the BCI System from <a href="https://braininformatics.springeropen.com/articles/10.1186/s40708-023-00199-3">Source</a></figcaption></figure><h3>Rehabilitation, Currently</h3><p>We’ve learned about BCIs, but what can we do with it?</p><p>Rehabilitation is a vital part of healthcare focused on helping individuals recover after an illness, injury, or medical emergency (such as a stroke, Parkinson’s disease, Multiple Sclerosis, etc.). It helps patients of all ages be as independent as possible and enables participation in everyday activities.</p><p>According to the <a href="https://www.who.int/health-topics/rehabilitation#tab=tab_2">World Health Organization</a>, 1 in 3 people today are estimated to be living with a health condition that would benefit from rehabilitation. Furthermore, in 2022, the medical rehabilitation service market size was valued at USD 240.7 billion, and is expected to grow to USD 385.9 billion by 2030, as documented by the <a href="https://www.grandviewresearch.com/industry-analysis/medical-rehabilitation-services-market-report">Market Analysis Report</a>.</p><p>Currently, rehabilitation for conditions such as strokes or traumatic brain injuries mainly consists of physical therapy, occupational therapy, speech therapy, medication management, and more. It aims to address the physical, cognitive, and emotional challenges that may arise.</p><p>However, these approaches have limitations. Progress can be slow and stagnant, and some functions, such as motor skills or language abilities, may never fully recover. Specifically, traditional therapy struggles to effectively address complex conditions like strokes or brain injuries due to:</p><ul><li><strong>Lack of individualized treatment plans:</strong> One-size-fits-all approaches in traditional rehab may not be able to address the unique needs of each patient. Conditions and recovery varies from person to person, and personalized treatment plans are essential for optimizing recovery outcomes.</li><li><strong>Complex constraints: </strong>Some conditions might affect areas of the brain that are difficult to stimulate through traditional therapy methods.</li><li><strong>Low intensity: </strong>Limited sessions with repetitive or tedious movements may be insufficient and lead to a lack of motivation or engagement.</li></ul><p>A newer approach, involving BCIs, could offer a whole new pathway for helping patients regain lost functions. By directly communicating with the brain, they have the potential to offer a more personalized and effective treatment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vBuEkfF8rz3oXwyz" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Transitioning from Traditional Therapy to BCIs</h3><p>The use of BCIs allows for improved rehabilitation approaches that were not previously possible with traditional therapy. They can achieve this by:</p><ol><li><strong>Enabling targeted neural stimulation for neuroplasticity:</strong> BCIs can stimulate specific regions of the brain, which can help rewire neural pathways and restore lost functions.</li><li><strong>Assisting motor skill recovery through device control:</strong> BCIs can bypass damaged neural pathways, allowing users to<strong> </strong>control external devices and retrain motor skills.</li><li><strong>Facilitating communication for severe disorders: </strong>BCIs can translate patient’s thoughts to text or speech output.</li><li><strong>Customizing cognitive training:</strong> BCIs can be used for memory training tasks or to stimulate cognitive functions.</li><li><strong>Providing continuous monitoring and feedback:</strong> BCIs can monitor brain activity to determine progress and tailor to specific needs.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*jZQkHKlgILGFLDUD.jpg" /><figcaption>User testing a BCI from <a href="https://www.globaltimes.cn/page/202108/1230191.shtml">Source</a></figcaption></figure><p>These are just a few examples of how BCIs can be used… and the potential doesn’t stop there.</p><h3>Take, BCIs for Stroke Rehabilitation</h3><p>To gain a deeper understanding of how BCIs impact rehabilitation, it’s crucial to understand one of their applications. For example, a stroke, which is a disruption of blood supply to the brain, often results in damaged neuronal pathways — the communication routes between the brain and the body.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XhKaC17jGXuDBAvx.jpg" /><figcaption>Stroke (rupture in blood vessels in brain) from <a href="https://firstcardiology.org/stroke-the-silent-killer/">Source</a></figcaption></figure><p>Now, imagine intending to raise your arm. This intention creates a unique pattern of neural activity or ‘brainwave’ that travels via neuronal pathways to your arm muscles, causing movement. A stroke might damage parts of these pathways, preventing the transmission of this ‘brainwave,’ resulting in paralysis.</p><p>BCIs provide a sort of detour around these damaged paths. For a paralyzed patient, when they think about moving their arm, their brain still produces the corresponding brainwave. However, it just can’t reach its destination.</p><p>BCIs, often in the form of a noninvasive EEG cap worn on the patient’s head, detects this brainwave. The cap is covered in electrodes that capture the electrical impulses generated by clusters of brain cells and provides valuable insights into the brain’s operation.</p><p>While the data that the BCI collects is extremely informative, it also contains a considerable amount of noise — unwanted signals that aren’t directly related to the desired information. Hence, it’s passed through various filters and algorithms to isolate the useful signals that are connected specifically to the patient’s intended action.</p><p>This filtered data is then converted into actionable commands by an algorithm that has been ‘trained’ to recognize patterns associated with specific thoughts. It’s similar to translating one language to another, where the algorithm can identify which pattern corresponds to which thought.</p><p>Once interpreted in a way for the machine to understand, these commands can communicate with an external device, such as a prosthetic arm or computer. In the case of rehabilitation, this could mean translating the patient’s intention to move their arm into a corresponding action in a prosthetic limb or a virtual arm displayed on a screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0y3fX7nRsyOa_Lrb.jpg" /><figcaption>Poststroke rehabilitation using BCIs from <a href="https://svn.bmj.com/content/7/6/541">Source</a></figcaption></figure><p>What makes this powerful in rehabilitation is the immediate and interactive feedback it provides to the patient. Being able to see their thoughts turn into action, whether it be through a virtual simulation or an external device, triggers a reinforcement mechanism in the brain. This method, also known as biofeedback, is found to increase awareness in a patient during the recovery process, making improvement both more efficient and effective.</p><p>Moreover, an increasing number of applications are integrating BCIs and machine learning, which means that the system itself will be able to improve over time and cater specifically towards the need of each patient. This may lead to a more successful recovery approach based on the patient’s progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VCR-hJpoNUwQ-8tw.jpeg" /><figcaption>How neurons control muscle movement from <a href="https://med.stanford.edu/news/all-news/2015/06/research-sheds-light-on-how-neurons-control-muscle-movement.html">Source</a></figcaption></figure><h3>Companies, Studies, and More</h3><p>EEG-based BCIs have significantly advanced in recent years, making them increasingly user-friendly and accessible.</p><p>So, you might be wondering, “who is leading these developments? And what progress has been made?”.</p><p><strong>Clinical Studies</strong></p><p>Various clinical studies investigating the potential of EEG-based BCIs in stroke rehabilitation have shown encouraging results. For instance, a study published in the <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC8235968/">National Library of Medicine</a> discovered that combining EEG-based BCI technology with other artificial intelligence technologies led to significant improvement in motor function and learning.</p><p>Similarly, another <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7825186/">research paper</a> reported clinically significant improvements in hand function in stroke patients following therapy involving an EEG-based BCI system.</p><p><strong>Companies and Products</strong></p><p>Several companies have been developing EEG-based BCI products specifically aimed at benefiting stroke patients during rehabilitation.</p><ul><li><a href="https://www.neuroelectrics.com/"><strong>Neuroelectrics</strong></a><strong>: </strong>Known for their wireless EEG and transcranial electrical stimulator, which are used for monitoring and non-invasive neurostimulation.</li><li><a href="https://mindmaze.com/"><strong>MindMaze</strong></a><strong>:</strong> Developed a virtual reality/augmented reality system, “MindMotion GO,” specifically designed for neurorehabilitation. It aims to motivate patients and supplement traditional care by providing exercises to improve cognitive and motor function.</li><li><a href="https://blackrockneurotech.com/"><strong>Blackrock Neurotech</strong></a><strong>: </strong>Designed neural recording and stimulation systems to help patients with paralysis and neurological disorders.</li><li><a href="https://www.gtec.at/"><strong>g.tec</strong></a><strong>:</strong> This medical technology company offers a BCI series directed at stroke rehabilitation and produces research devices for BCIs.</li></ul><p><strong>Consumer Products</strong></p><p>Although most applications are still being researched, there are a couple BCIs on the market currently. A notable example is the <a href="https://www.emotiv.com/epoc/">Emotiv EPOC+ EEG headset</a>, which provides a user-friendly interface for both researchers and individuals interested in exploring BCI technology. The <a href="https://choosemuse.com/">Muse headband</a> is another popular EEG-based device, offering a range of applications from meditation guidance to basic BCI functionalities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E72SeSwzyWoeaZ9_" /><figcaption>Muse headband from <a href="https://grepgiggles.files.wordpress.com/2019/11/muse.jpg?w=1120">Source</a></figcaption></figure><h3>The Road Ahead: Challenges and Future Possibilities</h3><p>Although BCIs are infinitely promising, there is still a considerable amount of progress to be made regarding consumer applications and widespread adoption. Currently, BCIs are still in an early phase of development, meaning that there are improvements needed as developers are still conducting research and innovating.</p><p>Another aspect of consideration is the accessibility of BCIs, many BCI applications require users to consistently wear or interact with the device, which may not be feasible for many patients.</p><p>Furthermore, the EEG signals that are commonly used in BCIs to interpret brain activity, can be unpredictable and have a high signal-to-noise ratio. This makes it challenging to reliably control devices, especially for applications that require precision.</p><p>Nonetheless, researchers around the globe are working on making these systems more accurate, accessible, and user-friendly.</p><p>Personally, I’m interested in the intersection of artificial intelligence and EEG data. As someone passionate about technology, but relatively new to both fields, I’m curious about how we can use advanced algorithms or computational techniques to gain a better understanding of EEG data for patients with complex neurological conditions.</p><p>And although BCIs won’t mean a complete end to traditional rehabilitation methods yet, their addition could signify a significant leap in our ability to help those on their road to recovery.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*x_mZzEG1GD6mUTKHH_7twQ.png" /><figcaption>Widespread use of BCIs and technology from <a href="https://static.vecteezy.com/system/resources/previews/022/700/692/large_2x/generative-ai-illustration-of-a-brain-in-a-jar-sitting-in-an-old-lab-wires-everywhere-connect-it-to-a-row-of-monitors-and-glowing-computer-screens-photo.jpg">Source</a></figcaption></figure><h3>The Key Takeaways (tl;dr)</h3><ul><li>BCIs enable direct communication between the brain and external devices. They decode brain signals into information that machines can interpret, allowing for control without the need for physical input devices like keyboards or trackpads.</li><li>BCIs have the potential to revolutionize rehabilitation, offering a more targeted approach.</li><li>Specifically, in stroke rehabilitation, BCIs can sense brainwaves associated with specific thoughts, enabling motor rehabilitation, and providing immediate feedback.</li><li>BCIs are still a work in progress, mostly in the development and research phase. They have a lot of promising applications, and current research is aiming to make it more accessible.</li></ul><blockquote>Thanks for reading! Feel free to follow, connect with me on <a href="https://www.linkedin.com/in/kelly-yang-498740215/">LinkedIn</a>, or email me at kellyang2006@gmail.com for upcoming articles. Also be sure to stay up to date with my newsletter on <a href="https://kellyang2006.substack.com/">Substack</a>. Please let me know if you have any questions or comments.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80f3a78d9655" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>