Close

The Software: EOG REM Detection Implementation (Code)

A project log for OpenLD: Lucid Dreaming Research Platform

An open source platform to help induce and explore the realm of Lucid Dreaming for Research and Personal Well-being

jae-choiJae Choi 09/28/2016 at 20:000 Comments

Now that we have derived the expression (the Inverse Dot Product) for calculating the magnitude of eye movements, we can begin its implementation. The C++ code for it is pretty simple:

int remDetect::evaluate_EOG_REM_Epoch(double *EOG1, double *EOG2, double min_EOG)
{
    // Resat accumulator
    avg_EOG_IP = 0;
    // Optimized algorithm - it is equivalent with += (EOG1 - EOG2)^2 - (EOG1 + EOG2)^2
    for (int i = 0; i < m_size_window; i++) {
        avg_EOG_IP += -1.0 * EOG1[i] * EOG2[i];
    }
    // Average
    avg_EOG_IP /= m_size_window;
    // if the value is within the limit window then return 1, else 0
    if (avg_EOG_IP > min_EOG) {
        rem_eog_Counter++;
        return 1;
    } else return 0;
}

In the code, you can see that I average (divide by number of EOG data points) the IDP after it has been calculated. This is to make sure that the constant min_EOG does not depend on the length of the signals and hence is portable across different EEG sampling frequencies. This function will return a 1 if it detects enough eye movements (above the min_EOG threshold) and a 0 otherwise.

There it is. We are done with the Lucid Dream Trigger portion of this project. In the next Project Log, I will give a general overview of how to use the OpenLD Software.

Discussions