NIRS data analysis (time series)

1 min read

[last updated: 2009/06/15]

Also check out NIRS data analysis (GLM and visualization)

Environment requirement

  1. MatLab
  2. SPM
  3. xTopo under xjView
    xjview is located in /fs/fmrihome/fMRItools/Xjview
    Add xjview to path by addpath(genpath('/fs/fmrihome/fMRItools/Xjview'))
    xTopo is based on topo program provided by Hitachi. It is modified by me. You can download xTopo at


  1. convert NIRS data file to csv format using ETG4000 program.
  2. copy the 3D positioning data (00X.pos).
  3. If you don’t have 3D positioning data, you may use the template channel positions located in xjview/nirs_data_sample/?x??.pos


  1. In MatLab command window, run topo
  2. Click button “Data Load” and select the data csv file. You only need to select the 1st (or left) file if you use 4×4 or 3×5 bilateral configurations. After a pause you will find the data information (such as subject name and marker timing etc)
  3. To view the overall time series, click button “Continuous Hb”. You will see the HbO, HbR and total traces for each channel. Colorful vertical lines indicates marker timing. To see more detailedly the trace of a certain channel, enter the channel number in CH box and click button “Zoom”.

  4. To see activation in a topographic view, click on any channel. You can also see the animation by click button “Play”.
  5. To see activation in 3D topo, in xTopo main window click “3D Topography”. You need to select the ???.pos file. You can rotate the brain.
  6. To average time series across trials, you need to select the markers (event) you are interested in (by clicking button “Select Mark”) and input proper parameters for Pre time, relax time and post time, then click either button “Integral Hb” or “cuixu Integral Hb” (I will explain the difference later).
  7. You can also zoom, plot topo, 3D topo like what you do for continuous time series.


  1. The difference between “Integral Hb” (IH) and “cuixu Integral Hb” (cH):
    IH: cut and collect the time series for each occurence of the event. Then do detrending based on pre time and post time for each individual time series. Finally average across occurences. Both pre and post time parameters are important.
    cH: Do detrending/smoothing with filter pass for the entire time series first, then cut and collect the time series for each occurence, then average. Pre time, relax time and post time is used when cutting the time series. The data used is from (Pre time) seconds before event onset, to (Relax + Post time) seconds after onset.  Relax and Post time are not that important. As long as the sum is the same, the result won’t change.
  2. Obtaining the data used in plot: You will find a variable called hb_data in the workspace. It contains the data used to plot. It’s an array. The 1st one is for probe set 1, 2nd for set 2. raw means raw data and fil means filtered data. The first dimension is hb species (oxy, dxy and total), second is time, 3rd is channel.

>> hb_data(1)

ana_mode: 2
calc_flg: 2
raw: [3x251x24 double]
fil: [3x251x24 double]

第十九期 fNIRS Journal Club 通知 2021/05/29,9:30am

美国普渡大学童云杰助理教授,将为大家讲解他们组最近被接受的一篇使用近红外相位信息研究脑血流变化的文章。热烈欢迎大家参与讨论。 时间: 北京时间2021年5月29日上午9:30地点: https://zoom.com房间号: 846 8391 7517密码: 805190 童云杰教授简介:普渡大学 生物医学工程助理教授、博士生导师。主攻方向是多模态脑成像, 包括核磁,fNIRS, EEG。关注脑功能及生理信号的提取与研究。发表论文九十余篇,引用上千次(H-index = 20)。 童教授要讲解的文章如下: Liang Z, Tian H, Yang HC, Arimitsu T, Takahashi...
Xu Cui
12 sec read

第十八期 fNIRS Journal Club 视频

北京时间2021年4月25日10点,北京师范大学的朱朝喆教授为大家讲解了他们最近几年在经颅脑图谱(Transcranial brain Atlas) 方面做的工作。视频如下: Youtube: Youku: 该视频在优酷上传后被优酷屏蔽,不清楚什么原因。申诉无效。
Xu Cui
3 sec read


会议日期:2021年5月22日-24日会议地点:天津师范大学 一、 会议简介       近红外光谱脑功能成像(fNIRS)具有设备购买与使用成本低、可在自然环境条件下使用、具有较高的时间分辨率和空间定位能力等特点,受到了脑科学研究的高度重视。“近红外光谱脑功能成像学术会议”是由北京师范大学认知神经科学与学习国家重点实验室朱朝喆教授发起并组织的全国性学术会议。已连续成功举办六届,共吸引全国近百家高校、科研院所及医院的六百余名学者参加。该会议已成为国内规模和影响力最大的fNIRS脑成像学术活动。       本届会议由北京师范大学与天津师范大学联合主办。会议将延用往届会议将学术报告与研究方法工作坊相结合的模式。学术报告模块(5月22日周六)将邀请心理学与认知神经科学领域、基础与临床医学领域以及工程技术领域知名学者汇报其fNIRS最新研究成果;工作坊模块(5月23-24日)由fNIRS领域一线研究者系统讲授fNIRS成像原理、fNIRS实验设计、fNIRS数据分析与统计、fNIRS论文写作以及fNIRS前沿技术等。除理论讲授外,还设置了fNIRS空间定位与数据分析操作(NIRS-KIT软件)环节,此外还安排充足的研讨答疑时间以便与会人员交流互动。       具体日程与详细内容等最新消息请关注后续通知,可通过天津师范大学心理部网站或北京师范大学国家重点实验室网站,或者扫描下方二维码关注微信公众号-“fNIRS脑成像实验室”查阅更新信息,期盼在天津师范大学与您相聚! 二、会议组织机构 主办单位:教育部人文社会科学重点研究基地天津师范大学心理与行为研究院、天津师范大学心理学部、北京师范大学认知神经科学与学习国家重点实验室会议主席:白学军、朱朝喆组织委员会:赵春健、杨邵峰、侯鑫、曹正操 三、说明1.        学术报告模块注册费:人民币500元/人;工作坊模块注册费:人民币2500元/人。发票为电子发票,内容均为:“会议费”。两个模块各自独立收费,参会者可根据自己需要进行选择。2.        注册费包括各自模块的资料费、午餐费;其他费用自理。3.        会议报告人免除会议模块注册费,其他费用请自理。4.       ...
Xu Cui
18 sec read

13 Replies to “NIRS data analysis (time series)”

  1. I’m struggling to get your code running an Matlab 2010a. SPM is installed and in the path, as is xjview.m. yet I see this error:
    ??? Undefined function or method ‘passfilter’ for input arguments of type ‘double’.

    Error in ==> cuixu_calc_int at 175
    dsignal = passfilter(continuous_data(p_cnt).raw(1,:,hb_ch), [0.3 0.01],

    ??? Error while evaluating uicontrol Callback

    where does passfilter come from? Do I need any other packages installed? Any hints?

  2. passfilter function is not included in the public version of xjview. Here is the function:

    function y = passfilter(x, threshold, samplingFrequency)
    % function y = passfilter(x, threshold, samplingFrequency)
    % low or/and high pass filter
    % x: orginal signal
    % threshold: the frequency thresholds. It should be an array of length 2.
    % The first component corresponds to the low pass filter threshold and the
    % 2nd one corresponds to the high pass threshold. If you don’t want to
    % set the threshold, put nan.
    % samplingFrequency: the sampling frequency of the original signal x.
    % Default 10 Hz
    % y: the result signal
    % Note: this script needs signal toolbox
    % Example:
    % y=humps([0:.01:1])+randn(1,101)*10;
    % figure;plot(y)
    % hold on; plot(passfilter(y, [0.5, nan], 10), ‘r’)
    % Xu Cui
    % 2007-10-02

    if nargin < 2 error('At least two arguments are required.'); end if nargin < 3 samplingFrequency = 10; end if ~isfinite(threshold(1)) && ~isfinite(threshold(2)) y = x; return end if isfinite(threshold(1)) && isfinite(threshold(2)) [b,a]=ellip(4,0.1,40,[threshold(2) threshold(1)]*2/samplingFrequency); elseif isfinite(threshold(1)) [b,a]=ellip(4,0.1,40,[threshold(1)]*2/samplingFrequency); elseif isfinite(threshold(2)) [b,a]=ellip(4,0.1,40,[threshold(2)]*2/samplingFrequency, 'high'); end y = filtfilt(b,a,x); return

  3. thanks for the passfilter function. it seems though there are some more functions missing (now choking on ellip and Maximize).
    Also there is a little glitch when running on a Unix system (case-sensitive filesystem) – in input_para.m you try to fopen a file ‘ALL_E_coef.txt’ but after unziping it is called All_E_coef.txt (lower case Ls).
    Do you plan on releasing an xjview version that has the needed functions?
    Thanks again for your help!

  4. I am trying to load my data sampled from fNIRS machine which has .csv

    However each time I try it, I get this error :

    Error in load_ad_etg7000 (line 25)
    load_flg = 0;

    Output argument “ad_data” (and maybe others) not assigned during call to

    Error in load_ad (line 81)
    [info, ad_data, mark,para,para_p] =

    Error in OnDataLoad (line 64)
    [info,ad_data,mark,para,para_p] =

    Error while evaluating uicontrol Callback

    I cannot understand why I have this error.

    I have cross checked it with the sample data that you have provided and could not see any differences. Could you please let me know why I am getting this kind of error ?


  5. I created the csv file from the Hitachi’s own program. I remembered that once I tried to change the csv file and then it failed. So I guess you have to create the csv in Hitachi’s way.

  6. I have problems with fileOut, it doesn’t save measurements data into the file. Only the information about subjects.
    any ideas?

  7. Hi Dr. Xu Cui,

    I wonder if you have a paper reference for your “cuixu Integral Hb”?


  8. Excuse me,
    May I ask how do you create the .pos file in your sampling data?
    Which instrument(Ex: ISOTRAK II) and software(Ex: Brainstorm) did you use to create the .pos file?
    Thanks for replying

Leave a Reply

Your email address will not be published. Required fields are marked *