EmotiBit / EmotiBit_FeatherWing

Firmware to run Emotibit with Adafruit feather M0 WiFi and Feather ESP32
MIT License
19 stars 9 forks source link

Add EDR Amplitude and EDR frequency to EmotiBit stock #173

Closed nitin710 closed 2 years ago

nitin710 commented 2 years ago

Description

Lit Rev

TypeTag considerations

nitin710 commented 2 years ago

Draft 1

Issues

// Load latest EDA signal dataLen = dataDoubleBuffer[EDA]->getData();

// process EDA for(dataLen) { lowPassfilteredSignal = edaAmplitudeLowPassFilter (data[i]); highPassfilteredSignal = edrAmplitudeHighPassFilter(data[i]); if((highPassfilteredSignal) / lowPassfilteredSignal > threshold) { // add (highPassfilteredSignal - lowPassfilteredSignal ) to _outDataPacket

// calculate the time between response
interResponseTime = lowPassFilter( interResponseSampleCount/samplingFreq);

// Add (1/interResponseTime) to _outDataPackets

} else { interResponseSampleCount++; } }



## Questions
1. Should we consider a `+ve` and `-ve` swing in EDA to count as a EDR?
    - If yes, how do we represent that? 
      - Do we just send a `+ve` and `-ve` value?
nitin710 commented 2 years ago

@produceconsumerobot what do you think of the draft? Still trying to think of a way to bypass typeTag

nitin710 commented 2 years ago

Notes from Discussion

nitin710 commented 2 years ago

Draft 2

in processElectrodermalResponse()
{
float* bufferData;
uint32_t timestamp;
size_T bufferSize;
edrAmplitudeHighPassFilter // for bandpass @ 0.5Hz
edaAmplitudeLowPassFilter // for bandpass @1.5Hz
edaAmplitudeBaselineFilter // @0.1Hz  // used to provide a baseline that works as a reference for threshold
edrFrequencyFilter // lowPass digital filter @1Hz
static float threshold; // ~ 0.1 (10%)
static uint16 interResposeSampleCount; // to count number of samples passed between EDR events
float interResponseTime;
static const float timePeriod = 1/ samplingFreq;
static bool onsetDetected;
static float baseEdrAmplitude;
float riseTime;

// Load latest EDA signal
bufferSize = dataDoubleBuffers[EDA]->getData(&bufferData, &timestamp, false);

// process EDA
for(bufferSize)
interResponseSampleCount++;
{
  lowPassfilteredSignal = edaAmplitudeLowPassFilter (data[i]);
  highPassfilteredSignal = edrAmplitudeHighPassFilter(lowPassfilteredSignal); // creates a bandpass by cascading low and high
  if(!onsetDetected)
  {
    if( highPassfilteredSignal / lowPassfilteredSignal > threshold)
    {
      // set onset detected.
      // record onset time(by back-calculating based on frequency)
      // set base edr amplitude
      baseEdrAmplitude = data[i]

      // calculate the time between response
      interResponseTime = lowPassFilter( interResponseSampleCount * timePeriod);
      // Add interResponseTime  _outDataPackets
      // interResponseSampleCount  = 0;
    }
  }
  else  // after onset has been detected
  {
    if(data[i] < data[i-1]) // peak detected
    {
         amplitude = data[i-1] - baseEdrAmplitude;
    }
    // calculate the rise time
   riseTime = interResponseSampleCount  * timePeriod;
   // send TimePeriod
   // onsetDetected = false; 
  }
}
produceconsumerobot commented 2 years ago

image

produceconsumerobot commented 2 years ago

SCR duration is also a somewhat commonly used term, e.g. from Handler et al. 2012 An EDA Primer for Polygraph Examiners image

produceconsumerobot commented 2 years ago

from Setz et al 2010 Discriminating Stress From Cognitive Load Using a Wearable EDA Device

image

produceconsumerobot commented 2 years ago

From Boucsein's 2012 book image image image

nitin710 commented 2 years ago

A Guide for Analysing Electrodermal Activity (EDA) & Skin Conductance Responses (SCRs) for Psychological Experiments https://www.birmingham.ac.uk/Documents/college-les/psych/saal/guide-electrodermal-activity.pdf

nitin710 commented 2 years ago

@produceconsumerobot as discussed, we may want to move the EDR:FREQ to a periodic channel. Let's pool that discussion into this issue.

Early draft: image (16)

nitin710 commented 2 years ago

Moving processElectrodermalActivity() into EmotiBitEda

Proposed solution for addPacket

nitin710 commented 2 years ago

Typetag Nomenclature

possible typetags between E series and S series Signal name Typetag(S series) Typetag(E series)
EDA EA EA
EDL EL EL
EDR ER ER
Skin Conductance Response Amplitude SA EC(electrodermal change)
Skin Conductance Response Frequency SF EF
Skin Conductance Response Rise Time SR ET
Skin Conductance Response Recovery Time ST E?
Skin Conductance Response Duration SD ED
Skin Conductance Response Latency SL E?

S- series

Reasons to have S series

note: when we add Skin conductance duration, need to resolve conflict with type tag SD-Card percentage.

Reasons not to have S series

E-series

Reasons to Have E series

Reasons not to have it

nitin710 commented 2 years ago

Here U1 represents a bandpass filtered eda, which is being used to determine the SCR derivatives. bandpass [0.3-1] Hz image