Friday, April 28, 2017

Detected EEG wave that can tell whether eyes are open or closed

This humble equipment which hides in the paper box can detect and record EEG wave now. By filtering and Fourier transformed to the frequency domain, we can tell whether the testee's eyes are open or closed. The middle part of the graph, which has lower signal, is the period of time that eyes were closed.

When eyes closed, the amplitude of the signal decreased significantly. It has a great difference with the signal that generated when eyes are open.

And when eyes are open, the beta wave which mainly distributes around 20Hz appears, together with some other higher components.

In the beginning, I was guessing the widely distributed signals are noise, they look like white noise or 1/f noise. After deep investigation, I confirmed that it's EEG signal, and mainly is the beta wave.

And happily, I got to know a guy that is currently pursuing his master's degree in a university in Canada, he is studying the method of detect epilepsy evidence in EEG wave. He is using wavelet to extract some specific wave from the signal. He would be a great help to my project.

Tuesday, April 25, 2017

My first ECG signal recording

For the first time, I made it, I recorded the ECG signal, by this messy, tiny circuit.

Figure: The ECG signal

The circuit was designed by my partner

Here is the system structure:

human body -> electrodes -> leads -> ADS1298 -> serial port -> PC -> C# app -> matlab

Friday, November 4, 2016

How to let SharpGL capturing KeyDown event?


  • SharpGL won't capture KeyDown event
  • Make OpenGLControl focusable, like this: Focusable="True"
  • Set focus on the OpenGL control in the hosting window: OpenGLControl.Focus();
If the OpenGL control is in a User Control, then set focus on the user control in the hosting window of the user control.

Thursday, September 29, 2016

Solution for: (Visual Studio 2015)Error while trying to run project: Unable to start debugging

I googled around. Many other solutions didn't work, except this one.

Issue: When you trying to debug the application, VS says "Error while trying to run project: Unable to start debugging".
Solution: Delete your .suo file of your solution.

Sunday, June 26, 2016

Convert MIT-BIH Polysomnographic data to mat (Matlab) format

.mat file could be loaded directly into Matlab. But MIT-BIH Polysomnographic data is not a .mat format. although, offers a converter that could convert to .mat format, but be careful, it only gives you first 1000000 points, but not all data. So how to convert the whole data file to .mat? Fortunately, the convertion tool "wfdb2mat" is also offered by Just go, click "Software Index" And find WFDB links, click it. Find "Ready-to-run, precompiled binaries" OK, in this page you will find the tool in binary format. I use windows, so I downloaded the windows version.

Here is a command line example:

bin\wfdb2mat -r slpdb/slp14 -f 0 -t 21600  -s 2 >

Make sure you have .hea file along with .dat file. The last command will produce slp14m.mat and other stuffs. slp14m.mat is just you want. Try to load it into matlab:

eegdata = load('slp14m.mat');

All are done!

Tuesday, May 17, 2016

Digital Elliptic Filter in Matlab

(Just learning how to use elliptic filter in Matlab)

The elliptic filter works pretty well, so efficient. The following filter will band 50Hz and near frequencies (see the third figure). And the last figure shows the filtered signal.

==== m code started ====

Rp = 5; % peak-to-peak passband ripple, the smaller the smoother
Rs = 60; % stopband attenuation
Fs = 250; % sample rate
Wp = [47, 53]/Fs*2; % passband edge frequency
Ws = [48, 52]/Fs*2; % stopband edge frequency
[N, Wn] = ellipord(Wp, Ws, Rp, Rs); % find the minimum order of the required filter

fprintf('Wn %f, %f\n', Wn(1)*Fs/2, Wn(2)*Fs/2);

[b,a] = ellip(N,Rp,Rs, Wn,'stop'); % design an elliptic filter
freqz(b,a); % draw frequency response of the filter

title(['ellipord Analog bandstop filter order N=',num2str(N)]);

tseq = 0: 1/Fs :6;
dataIn =  sin(tseq*10 *2*pi) + sin(tseq*50 *2*pi) + sin(tseq*52 *2*pi) + sin(tseq*48 *2*pi);
dataOut = filter(b,a,dataIn);


Monday, January 18, 2016

vector::operator [] is time consuming

I am handling large amount of data (4000*4000 double). I found vector::operator [] is really expensive in terms of CPU cost.

vector arr = AllocateArray(4000, 4000);
while( _all_elements_in_arr_)
  arr[i] = x; // it's extremely slow.

So avoid of using operator [], instead, use direct address of the buffer could improve the performance tremendously:

double * buffer_addr = &arr[0];