A mistake in my False discovery rate (FDR) correction script

August 8th, 2016

I have posted an FDR script at http://www.alivelearn.net/?p=1840. I noticed that there is a small bug. In rare cases, this bug will cause the most significant voxel to be classified as ‘non-significant’ while other voxels are ’significant’.

Consider the following example:

p = [0.8147 0.9058 0.0030 0.9134 0.6324 0.0029 0.2785 0.5469 0.9575 0.9649 0.1576 0.9706 0.9572 0.4854 0.8003 0.1419 0.4218 0.9157];

The previous script will classify p(3) as significant but p(6) as non-significant.

Here is the updated version of the script:

function y = fdr0(p, q)
% y = fdr0(p, q)
% to calculate whether a pvalue survive FDR corrected q
% p: an array of p values. (e.g. p values for each channel)
% q: desired FDR threshold (typically 0.05)
% y: an array of the same size with p with only two possible values. 0
% means this position (channel) does not survive the threshold, 1 mean it
% survives
% Ref:
% Genovese et al. (2002). Thresholding statistical maps in functional
% neuroimaging using the false discovery rate. Neuroimage, 15:722-786.
% Example:
%   y = fdr0(rand(10,1),0.5);
% Xu Cui
% 2016/3/14

pvalue = p;
y = 0 * p;

[sortedpvalue, sortedposition] = sort(pvalue);
v = length(sortedposition);
for ii=1:v
    if q*ii/v >= sortedpvalue(ii)
        y(sortedposition(1:ii)) = 1;

Author: Xu Cui Categories: brain, matlab, nirs, programming Tags:

Remote Desktops

July 25th, 2016

I have quite a few devices now: one computer (PC) at Stanford, one (PC) at home, one Macbook Pro laptop, one iPhone and iPad. I am sometimes at work, sometime home, sometimes travelling, sometimes meeting people. One thing I always want to achieve is to be able to access the computers from anywhere.

I did some research and Google’s Chrome Remote Desktop is a good choice. It is also free. It is a plugin of Chrome browser. For iphone/iPad, Google also offers an app. I installed Chrome Remote Desktop on all my devices, and now I can access any computer from any other devices.

remote desktop

remote desktop

This is what I hoped for - a full connection. But at this particular moment I can’t use the home computer to remote others. I got the famous “some required components are missing” error and don’t know how to solve it. If you know a solution, please let me know.

Author: Xu Cui Categories: life Tags:

3 monitors

July 18th, 2016

To be more “productive”, I recently upgraded my work space. I used to have 2 monitors side by side. Both of them are View Sonic but they are of different size and one is old. So I purchased two monitors (Dell U2415). Together with one original View Sonic monitor, now I get 3 monitors on my desk.

3 monitors

3 monitors

The left one is the original view sonic one with resolution 1920 x 1080. I make it vertical because I write a lot of codes and a vertical placement allows me see more lines of codes at the same time. So this monitor is almost dedicated to writing codes.

The right two are Dell U2415 with resolution 1920 x 1200. According to some people, “Dell UltraSharp series is a gold standard in excellence which programmers have used and loved for years”. I myself do love it a lot. These monitors have a very thin bezel, which is ideal for side-by-side placement. I use the middle screen for the current job (Excel, browsing etc), and the right screen for supportive function (e.g. wechat, FileZilla, QQ, windows explorer etc).

Of course, to make the 3 monitor setup possible, I need a trip-monitor stand. The one I use is SIIG 13″-27″ Articulated Freestanding Triple Monitor Desk Stand. It does an OK job. One of the reason I chose it because it does not need a grommet. I am using varidesk and there is not much space under the table.

Overall, I like the 3 monitors a lot. I do feel I am more “productive” :)

Author: Xu Cui Categories: life, technology Tags:

MatLab tip, save data in compressed mode

June 29th, 2016

I have a mat file which is 100+M in size. It would be fine normally but since I was trying to upload it to github, it was rejected due to its big size. Fortunately there is a way to reduce the size: save it again in the compressed mode.

After I load the file, I save the variable again using the following command:

save filename variablename -v7

The parameter -v7 is the key. How does the compression perform? Originally the file (render_ch2bet) size is 103M, with -v7 parameter the file is 40.9M (render_ch2bet_compressed). By comparison, if we compress the original file using a third party program, we got ~40M (render_ch2bet.zip). If we use the -v7 option, not only we get a much smaller file and save a lot of space, we can also load it directly in MatLab.

Compressed MAT file

Author: Xu Cui Categories: matlab Tags:


June 27th, 2016

Manish Saggar in our lab brought something very cool - a helmet like EEG system. He called it “dry” EEG because it does not requite gel. The design is not polished, but it’s cheap, like $800. And it does not need long wires to transmit the signal to a computer, which is pretty nice. This product is manufactured by OpenBCI, an open source community.


Manish Saggar

I decided to give it a try and borrowed the device from Manish.

Wearing OpenBCI Biosensing Headset

Wearing OpenBCI Biosensing Headset

The headset does not fit my head perfectly, leaving most channels in the front untouched with my head. It’s also not comfortable to wear for a long time; the material is hard and exert a lot of pressure on my head. But it’s wireless and we can collect the data and display the signal on screen in real time. This part is cool.

To collect data, we need two pieces of software and a USB dongle.

USB dongle

USB dongle

First, let’s download the dongle driver. The driver of the dongle can be found at http://www.ftdichip.com/Drivers/VCP.htm. Since I am using Windows 7, I download the Windows executable setup version. You can download the file (CDM21218_Setup.zip) directly from http://www.ftdichip.com/Drivers/CDM/CDM21218_Setup.zip. Then unzip and install it.

Then, let’s plugin the dongle into a USB. Make sure you plug it the right way. If you do, the dongle will emit blue lights. I did it wrong in the first place and have to reverse the side and try again.

We also need to download the OpenBCI software which can collect and visualize the data in real time. You can download it at http://openbci.com/index.php/downloads. I downloaded the Windows 64bit version.

Now it is time to play with it. First let’s open OpenBCI software.



The dongle acts as COM3 port on my computer, so I select COM3. I also switch my headset power on. Then I click “START SYSTEM”.



At this time I click the round “head” bring up the signal panel. Then I click “Start data stream” to collect the data. The figure below shows my brain wave in real time!

OpenBCI data collection

OpenBCI data collection

So far it’s all impressive. The setup is easy. But the question is if the signal is reliable. What we found is that it’s highly motion sensitive. If I move my head, or blink my eye, the signal will change. At this point, I hesitate to draw any conclusion on the quality of the signal.

In the past few years a number of companies have produced consumer-use brain signal recording devices. Check out this list in wikipedia. A few NIRS companies (e.g. Hitachi) are also working on a consumer NIRS device. There is no doubt that we will have a reliable personal brain sensor in the near future.

Author: Xu Cui Categories: brain Tags:

Some tips to use wavelet toolbox

June 13th, 2016

Wavelet toolbox is a useful tool to study hyperscanning data. Many recent publications on NIRS hyperscanning use wavelet coherence to quantify the relationship between two interacting brains (e.g. Baker et al 2016, Nozawa et al 2016). You can see more information about wavelet coherence at http://www.alivelearn.net/?p=1169



Here are some tips to use the toolbox:

1. It often takes a long time to run Monte Carlo simulation. You may use ‘mcc’=0 to disable it.


2. If you need to get the values of the result (instead of the graphic), you may specify the return value

[Rsq,period,scale,coi,sig95] = wtc(signal1,signal2,'mcc',0); %Rsq is a complex matrix

3. If you are only interested in a certain band, you can specify the MaxScale (i.e. ms) parameter. More information at http://www.alivelearn.net/?p=1518

[Rsq,period,scale,coi,sig95] = wtc(signal1,signal2,'mcc',0, 'ms', 128);

4. If you are interested in finding the “phase” information (visualized by the arrows), you may use xwt function. The returned value is a complex matrix and you can calculate the phase.

[Rsq,period,scale,coi,sig95] = xwt(signal(:,jj),signal(:,jj+22));

5. To visualize the power of a single signal, you may use wt, which I personally feel much better than FFT.


6. To change the density of the arrows, you may specify the ArrowDensity parameter

figure;wtc(signal(:,jj),signal(:,jj+22),'mcc',0,'ArrowDensity',[30 30]);

Do you have any tips? Please let me know.

Author: Xu Cui Categories: brain, matlab, nirs, programming Tags:

Just published a paper: Men vs Women, are they different in cooperation?

June 13th, 2016

We just published a big and long study. It is a NIRS hyperscanning study aiming to investigate the brain difference between men and women during cooperation. We have scanned 222 people! And it is one of the largest NIRS study I have seen. And it is a long study. The project started in 2012 (today is 2016/6/13). You can imagine how long it took to collect and analyze the data, and to get the paper published!

After a series of rejections (Nature -> Journal of Neuroscience -> PNAS -> NeuroImage), this paper was finally published in Scientific Reports this month (2016/06). The full-text of this paper is accessible via PubMed Central.

A cooperation game

Two lab members are playing the cooperation game

After the paper was published, it has attracted a lot of media attention. For example, Stanford news center has reported “Study finds differences in male, female brain activity when it comes to cooperation” (below).

Stanford News Center

Stanford News Center

Two major contributors of this study are Ning Liu and Joe Baker.

Ning Liu

Ning Liu

Joe Baker

Joe Baker

Author: Xu Cui Categories: brain, nirs Tags:

Hitachi ETG4000 on ebay, for less than $10,000

June 6th, 2016

In our lab meeting today we accidentally discovered that you can actually purchase a used ETG4000 on ebay! The seller asked for $9,995. When we purchased ETG4000 back in 2007, it costed us about half million!

Check it out:


Author: Xu Cui Categories: brain, nirs Tags:

fNIRS 2016

June 6th, 2016

fNIRS 2016 conference will be held in Paris, October 13 – 16, Université Paris Descartes, 12 rue de l’Ecole de Médecine, Paris 75006, FRANCE

Check out the society’s home page: http://www.fnirs2016.org/

The 2016 conference will take place in central Paris, October 13 – 16, 2016.

As with past meetings, there will be a day-long course prior to the start of the conference, on Thursday, October 13.

The conference is co-chaired by Judit Gervain and Joseph Culver.

Maria Angela Franceschini (MGH, Harvard Medical School, Boston, USA) – Keynote
Sol Diamond (Dartmouth College, USA)
Frédéric Dehais (ISAE, Toulouse, France)
Ursula Wolf (Bern University, Switzerland)
Frédéric Lesage (McGill University, Canada)
Gorm Greisen (University of Copenhagen, Danemark)
Yasuyo Minagawa (Keio University, Japan)
Ippeita Dan (Jichi Med. University, Japan)
Chuck Nelson (BCH, Harvard Medical School, Boston, USA)

Abstract submission opens: May 1st, 2016
Abstract submission ends: June 10th, 2016 (midnight GMT)
Notification to authors: Late July 2016
Early registration ends: Sept 10th, 2016

Author: Xu Cui Categories: nirs Tags:

DDoS Attack Threat

May 26th, 2016

I recently received an email who threatens to attack a server I am running - unless I pay them 0.2 Bitcoin (about $93 US dollars). Anybody know how to handle this?

Below is the email:


From: PhantomSquad@openmailbox.org
subject line: DDoS Attack Imminent - Important information


We are Phantom Squad

Your network will be DDoS-ed starting June 1st 2016 if you don’t pay protection fee - 0.2 Bitcoin @ 14hxG5TBZz6jCZz4H7mzfzXfgXjgaF3MqA.

If you don’t pay by June 1st 2016, attack will start, yours service going down permanently price to stop will increase to 20 BTC and will go up 10 BTC for every day of attack.

This is not a joke.

Our attacks are extremely powerful - sometimes over 1 Tbps per second. And we pass CloudFlare and others remote protections! So, no cheap protection will help.

Prevent it all with just 0.2 BTC @ 14hxG5TBZz6jCZz4H7mzfzXfgXjgaF3MqA

Do not reply, we will not read. Pay and we will know its you. AND YOU WILL NEVER AGAIN HEAR FROM US!

Bitcoin is anonymous, nobody will ever know you cooperated.

Author: Xu Cui Categories: web Tags: