Preparation for Building an EEG based Emotion Detection Model

Originally posted on

Links and hints for my personal use/preparation for building an emotion detection model:

MNE is a collection of code/tool to process EEG and MEG data.

Code on how to simulate/generate fake raw data based on some sample is here.

Some basic concerns and questions on MNE are answered here.

One consistent limitation in EEG based model is — the accuracy of recognition is not very high (most are close to 51%~67%; with very few having 80%~91% accuracy). Need to explore what is needed — use of EEG device with more sensors or improving the feature extraction as well as machine learning algorithms or combining EEG with other body signals as read by various sensors. [5] has some hints.

[3] Faster wave (high freq, small amplitude) implies a more awake brain. Figure 6.1 from this book is very useful.

[5] EEG based emotion detection is useful because even though we are able to fake outward expression of emotion or we are inept at expressing true emotion still we cannot suppress voluntary and internal cortical signals (those are related to real emotion) and those are captured in EEG. Physiological marker is a low quality indicator. On top of that facial and bodily changes due to emotion appear after some delay from the onset of emotional arousal.

[10] says that the while comparing people under same level of anesthesia each; the one that responded to anesthesia and became unconscious had lower alpha brain wave activity compared to the one that did not respond to anesthesia or was still alert/awake. The researchers reported a correlation between a “delta-alpha coupling” and amount of anesthesia in the blood.

To be continued.

Further Reading:

  1. The Book “Assistive Technologies for Physical and Cognitive Disabilities”.
  2. Chapter 10 — Neuro Measure (EEG) — from the book “ Decoding the Irrational Consumer” on why is EEG more useful than self report or other body signals.
  3. Calculus of Thoughts (book) — Chapter 6, Oscillating Neural Synchrony
  4. Research Paper — Real-time EEG-based emotion recognition for music therapy. — Olga, Yisi, …
  5. Handbook of Research on Synthesizing Human Emotion in Intelligent Systems and Robotics (book); Chapter 13: EEG-Analysis for the Detection of True Emotion or Pretension
  6. Debugging Neural Net.
  7. Neural Networks in Healthcare (book) Chapter 8 Artificial Neural Networks in EEG Analysis.





Music and Pain Management — Survey #1

Originally posted on

We are all masterpieces and here in the world to make the most of our time and energy to reach our full potential. But all of our days and experiences are not positive and bright ones. We have to manage stress, anxiety, pain and depression to effectively handle our days. During my darkest and bad days music helps me to stay positive and energetic. Seeing the way music works on me I decided to explore the art and science of various media as medicine — specifically music. For some people instead of music it can be watching sports; for other it may be reading books and listening to specific types of lectures.

Below is the summary of what I learnt during my research in this area several years ago.

[1] This paper evaluated patients’ preference for Music Therapy (MT) versus Music as Medicine (MM) as well as patients’ perception of anxiety and pain after the treatment (Chemo, Radiation) sessions augmented with music.

By “Music Therapy” the authors meant that a “Music Therapist” would be present during treatment session using music (in addition to traditional painkiller). The music performance would be interactive and the user has to participate (play/sing) instead of passively hearing the music. There may be improvisation to distract the patient. We may stress on playfulness and creativity as a way to distract patients based on their personality type. However we have to keep the following points in mind. Some patients like familiarity and predictability instead of spontaneity. On top of that they may feel insecure due to their lack of musical skills and try to avoid active participation. In the presence of other people some of the patients may not be at ease to enjoy the music. Some are not good at multitasking and may prefer to focus on the music itself instead of interleaving communication and music performance. So a music augmented treatment session should consider all of these possibilities.

By the term “Music as Medicine” the authors indicated use of pre-selected (which can be based on the patient’s personality type as well as characteristics of the music) and pre-recorded music without any music therapist being present during the treatment session.

We have the usual problem of small sample size here. 31 grown up patients participated. As the sample size is small the debate would be — the observation is not statistically significant.

Though symptom (anxiety, pain) control performance was similar/close in both cases; 77% of the candidates preferred MT over MM. Which in a sense implies that these candidates prefer doing things together. Candidates with inclination towards MM does not like interactive activities much. My personal observation is that this percentage closely matches general percentage of extrovert versus introvert in society.

Some people are not open to experience emotion and for some music is an element that evokes strong emotion and helplessness. It is better to filter out such people or have a therapist nearby to provide support. Also Music does not help in symptom management for people who have very negative view of life and who think there is little hope in life. We should filter out such people too — neither music therapy nor music as medicine would be useful for them.

For some people it takes more time to be ready (mindset and trust factors) to get the most benefit from MM or MT- here by digital long distance (when face to face meeting is not feasible) demo/video/questionnaire /personal story sharing before the treatment day or more preparation sessions can make the patients well prepared for the actual day of treatment.

[2] This paper talks about disease and illness. “Disease” is biological or objective. “Illness” is psychosocial so subjective. Significant component of pain is subjective as well. Midbrain is involved in emotion and it is more immediate response to nociception. Cognition attaches meaning and can amplify pain. Present day treatment mostly focuses on biological side of pain. We need to consider Bio-psychosocial model of pain to handle pain effectively.

However the authors did their evaluation on rat which may not really be that useful. Why not? Because human and rat are significantly different in the “Psycho” and “Social” dimensions.

The article says that 80% of all doctor visits are related to chronic pain. It also indicates that huge amount of loss in productivity and annual expenditure of nearly 70 billion dollars are related to chronic pain (back pain, headache, arthritis etc.).

Another article says that due to the limited number of physicians; it is preferred or emphasized that patients would self manage the pain when possible.

[3] The author says that the mid brain and Amygdala are involved during handling pain as well as euphoria-inducing stimuli.

[4] This paper says that acceptance of pain increases pain tolerance basically by cognitive restructuring of pain related thoughts. It also says that distraction reduces the intensity of pain perception.

[5] This paper says that the performance of Music increases/elevates pain tolerance. On top of that music forms a sense of community (good for people who want company of others or gain energy/sense of support from that.). My thought is — face to face or long distance group music therapy sessions may be very useful and affordable for people who feel lonely, depressed and in general not understood because of lack of awareness regarding mental health issues.

[6] Pain is a composite sensation. Pain processing is not linear and can be very powerful. It may stop any other ongoing neural processes in brain as well. Pain is modulated at every level of neural axis and can be amplified.

It is interesting that same part of brain is involved in both pain and emotional disorders (depression, anxiety). Cognition can modulate pain: if we are distracted we do not feel pain to be that intense as distraction suppresses neural activation in the area involved in pain sensation. Emotional experience modulates perception of pain too. Lateral Orbitofrontal Cortex and Rostral Anterior Cingulate Cortex are activated during cognitive modulation of pain processing as well as depression. All the pieces of information can be very useful in proper treatment planning.

[7] says that parts of the brain namely ACC (Anterior Cingulate Cortex) and Insula are involved in subjective (emotional and motivational) evaluation of pain (stinging, burning, aching). Other parts of Nervous System (primary and secondary somatosensory cortices) deal with location and duration of pain. Observing family member in pain causes more pain in people than observing a stranger in pain.

Additionally it is mentioned that there is a feedback loop between emotion, cognition and pain perception. The unpleasantness of the experience makes pain a “pain” or “non pain” thing. As for example even though painful to some extent; body massaging is not as unpleasant as having a surgery — the label we attach to a situation affects our pain perception. Negative emotional state makes pain perception stronger. Now how to create pleasant and unpleasant situations for the sake of experiments? There are different ways to do so. We can create negative emotional states by giving way too difficult problem /instruction to handle, showing faces with negative emotion, introducing bad odor etc. On the other hand we can elevate or induce positive emotion with images or videos with positive vibe and good odor, humor or funny distractions and then conduct our research.

What if we use a music intervention that causes both distraction and good mood? Is it possible? What would be the combined score or conditional probability of effectiveness?

Also some changes are observed in the brains of patients with chronic pain. Cannot these changes be reversed so that we do not feel pain even though the pain causing stimuli are gone long ago (chronic pain and neuroplasticity)?

[8] This paper says that the pain modulation in the nervous system can be affected pharmacologically or through contextual or psychological manipulation like “attentional” state, emotional context, empathy, hypnotic suggestions, attitudes towards life and expectations, placebo effect, social modeling or social influence and there by can alter pain perception. A person with low empathy feels less pain (while seeing another person in pain and being himself/herself in pain too) as compared to a person with high empathy.

It may be a good idea to shortlist music/hypnosis techniques/videos that we can use to make a person less emotional/empathetic so that (s)he does not feel the pain. We need to be careful about the type of distraction (from pain) chosen such that it does not arouse or make the person too stressed. As for example showing patients the word “green” in blue color and instructing them to report the color of ink not the word itself may be bit too much. We need to find out ways to distract that is not stressful and does not create negative emotion.

[9] Discusses whether online/long distance cognitive behavioral treatment is effective or not? Dr. Anthony Komaroff from Harvard Medical School says that it is effective.

That’s all for now. Other parts of my survey will be posted in near future. Based on the survey I feel positive regarding using music as a “second aid” for pain management though we have a long way to go. Please note that I am using the term “Second aid” because I am not saying that the regular pharmaceutical intervention is not required. My thought is how about combining music with traditional/usual medication or means so that lower dose of medication would suffice? There are recent publications regarding the harsh side effect of relying on pain medication long term and corresponding overdose — it may cause addiction to pain-killer. On the other hand withdrawal may cause respiratory and other complications and in some cases death. So research on other ways of managing pain is important.


[1] The Impact of Music Therapy Versus Music Medicine on Psychological Outcomes and Pain in Cancer Patients: a Mixed Methods Study — by Joke Bradt, Noah Potvin, Amy Kesslick, Minjung Shim, Donna Radl, Emily Schriver, Edward J. Gracely and Lydia T. Komarnicky-Kocher.

[2] The Biopsychosocial Approach to Chronic Pain: Scientific Advances and Future Directions — by Robert J. Gatchel and Yuan Bo Peng, Madelon L. Peters, Perry N. Fuchs and Dennis C. Turk.

[3] Effects of Music on Anxiety and Pain in the Diagnosis and Treatment of Patients With Breast Cancer — by Alysia Greco.

[4] Acceptance, Cognitive Restructuring, and Distraction as Coping Strategies for Acute Pain — by Annika Kohl, Winfried Rief and Julia Anna.

[5] Performance of Music Elevates Pain Threshold and Positive Affect: Implications for the Evolutionary Function of Music — by R.I.M. Dunbar, Kostas Kaskatis, Ian MacDonald and Vinnie Barra.

[6] Cognitive Control of Emotion and Pain in the Human Brain From Basic Pain Mechanisms to Headache — by Jes Olesen, Troels Staehelin Jensen.

[7] Cognitive and emotional control of pain and its disruption in chronic pain — by M. Catherine Bushnell, Marta Čeko

[8] Effects of Psychological State on Pain Perception in the Dental Environment — by Catherine Bushnell