Analyze sleep using "NeuroSky Thinkgear" EEG sensor.
I was using the "MindCap XL" (MindTec, Amazon) which measures a single EEG signal with NeuroSky's TGAM EEG sensor, and sends data over Bluetooth.
On OSX Download and install: http://developer.neurosky.com/docs/doku.php?id=thinkgear_connector_tgc
Start ThinkGearConnector.app
. It might be easier to run the binary from a terminal, to see the debug output regarding the Bluetooth connection:
/Applications/ThinkGearConnector.app/Contents/MacOS/ThinkGearConnector
Files in lib/
.
Client for the Thinkgear Connector server. Emits data as specified by the TGSP protocol.
ThinkgearClient.createClient({appName: 'record'}, function(thinkgear) {
thinkgear.on('data', function(data) {
console.log(data);
});
});
Most files implement a NodeJS Stream.
All streams operate on objects of type Sample
.
Readable streams:
- thinkgear/reader: Read EEG values from ThinkGear Connector
- mongodb/reader: Reads samples from the given collection
- fft/sine: Generates a sine wave (for testing)
Writable streams:
- mongodb/writer: Writes samples to the given collection
- stream/printer: Prints to STDOUT
Transform streams:
- fft/sampler: Reads samples'
rawEeg
value and transforms to samples withspectrum
(typeSpectrum
) - stream/average: Moving average of numerical samples over a specified time duration
- sleep/bands: Calculate relative magnitude of certain frequency bands from spectrum
- sleep/sef: Calculate SEF50 and SEF95 from spectrum (see A Low Computational Cost Algorithm for REM Sleep Detection Using Single Channel EEG)
Files in bin/
.
Read samples and store them inin a MongoDB collection
Load raw samples from MongoDB and plot them in a web page:
Load raw samples from MongoDB, run an FFT frequency analysis, and plot the frequency bands:
Load raw samples from MongoDB, run the algorithm from A Low Computational Cost Algorithm for REM Sleep Detection Using Single Channel EEG and plot the "SEFd":