diff --git a/tutorial/mouse_eeg.md b/tutorial/mouse_eeg.md index 82135f0fc..520148ab4 100644 --- a/tutorial/mouse_eeg.md +++ b/tutorial/mouse_eeg.md @@ -64,7 +64,15 @@ The procedure consists of the following steps: Using **[ft_definetrial](/reference/ft_definetrial)** and **[ft_preprocessing](/reference/ft_preprocessing)** we define, read and preprocess the data segmentsof interest. Trials are specified by their begin and end sample in the data file and each trial has an offset that defines where the relative t=0 point (usually the point of the optogenetic stimulus-trigger) is for that trial. -The dataset used here does not include conventional digital trigger information. To record the timing of stimulation, an analog input channel 'HL1' was used to record TTL triggers. We use a customized function and the `cfg.trialfun='mousetrialfun'` option to define the segments. The trial function results in a `cfg.trl` Nx3 array that ccontains the begin- and endsample, and the trigger offset of each trial relative to the beginning of the raw data on disk. +We start with a visual inspection of the data. + + cfg = []; + cfg.dataset = 'S1s_10Hz.cnt'; + cfg.viewmode = 'vertical'; + cfg.blocksize = 30; % show 30 seconds per page + cfg = ft_databrowser(cfg); + +The dataset used here does not include digital trigger information. To record the timing of stimulation, an analog input channel 'HL1' was used to record TTL triggers. We use a customized function and the `cfg.trialfun='mousetrialfun'` option to define the segments. The trial function results in a `cfg.trl` Nx3 array that ccontains the begin- and endsample, and the trigger offset of each trial relative to the beginning of the raw data on disk. function trl = mousetrialfun(cfg) @@ -74,10 +82,11 @@ The dataset used here does not include conventional digital trigger information. % cfg.trialdef.prestim % cfg.trialdef.poststim - hdr = ft_read_header(cfg.dataset); + hdr = ft_read_header(cfg.dataset); trigchan = find(strcmp(hdr.label, 'HL1')); - trigger_data = ft_read_data(cfg.dataset, 'chanindx', trigchan); - trigger_data = trigger_data - median(trigger_data); + trigger_data = ft_read_data(cfg.dataset, 'chanindx', trigchan); % read trigger data + trigger_data = -trigger_data; % flip sign + trigger_data = trigger_data - median(trigger_data); % shift if isfield(cfg, 'trialdef') && isfield(cfg.trialdef, 'threshold') trigger_threshold = cfg.trialdef.threshold; @@ -85,18 +94,17 @@ The dataset used here does not include conventional digital trigger information. trigger_threshold = 0.5*max(trigger_data); end + % give some feedback figure plot(trigger_data, 'b') hold on - plot(trigger_threshold*ones(size(trigger_data)), 'r') - - trl = []; + plot(trigger_threshold*ones(size(trigger_data)), 'g') stim_duration = cfg.trialdef.prestim * hdr.Fs; % number of samples rest_duration = cfg.trialdef.poststim * hdr.Fs; % number of samples % extracts, trigger timing ------------------------------------------------ - data1 = find(abs(trigger_data) > trigger_threshold); % exceed threshold + data1 = find(abs(trigger_data) > trigger_threshold); % exceed threshold data2 = find(data1-[0,data1(1,1:end-1)] > rest_duration); % exceed 'rest_duration' idx = data1(data2); clear data1 data2 @@ -104,16 +112,15 @@ The dataset used here does not include conventional digital trigger information. trigger_event(1,:) = idx; clear idx - % give some feedback - figure - plot(trigger_event(1,:),0,'go') + % give some additional feedback + plot(trigger_event(1,:), trigger_threshold, 'rx') % extracts, trigger contents ---------------------------------------------- for tr = 1:size(trigger_event,2) temp_data = abs(trigger_data(trigger_event(1,tr):trigger_event(1,tr)+stim_duration-1)); idx = find_cross(temp_data, trigger_threshold, 'down'); clear temp_data - trigger_event(2,tr) = size(find(idx == 1),2) / (stim_duration / hdr.Fs); clear idx - end clear tr + trigger_event(2,tr) = size(find(idx == 1),2) / (stim_duration / hdr.Fs); + end trl = [trigger_event(1, :) - stim_duration+1; trigger_event(1, :) + rest_duration]'; trl(:, 3) = zeros(size(trl, 1), 1); @@ -136,21 +143,21 @@ The dataset used here does not include conventional digital trigger information. tidx1 = zeros(1,size(data,2)-1); tidx2 = zeros(1,size(data,2)-1); idx1 = zeros(1,size(data,2)-1); - tidx1(find(data(1,1:end-1) <= thr)) = 1; - tidx2(find(data(1,2:end) > thr)) = 1; - idx1(find(tidx1 + tidx2 == 2)) = 1; clear tidx1 tidx2 + tidx1(data(1,1:end-1) <= thr) = 1; + tidx2(data(1,2:end) > thr) = 1; + idx1(tidx1 + tidx2 == 2) = 1; clear tidx1 tidx2 % down crossing tidx1 = zeros(1,size(data,2)-1); tidx2 = zeros(1,size(data,2)-1); idx2 = zeros(1,size(data,2)-1); - tidx1(find(data(1,1:end-1) >= thr)) = 1; - tidx2(find(data(1,2:end) < thr)) = 1; - idx2(find(tidx1 + tidx2 == 2)) = 1; clear tidx1 tidx2 + tidx1(data(1,1:end-1) >= thr) = 1; + tidx2(data(1,2:end) < thr) = 1; + idx2(tidx1 + tidx2 == 2) = 1; clear tidx1 tidx2 % both idx0 = zeros(1,size(data,2)-1); - idx0(find(idx1 + idx2 > 0)) = 1; + idx0(idx1 + idx2 > 0) = 1; if nargin == 2 idx = idx0; @@ -169,8 +176,7 @@ Using this trial function, we can call **[ft_definetrial](/reference/ft_definetr cfg = []; cfg.dataset = 'S1s_10Hz.cnt'; cfg.trialfun = 'mousetrialfun'; % see above - cfg.trialdef.eventtype = '?'; - cfg.trialdef.eventvalue = 40000; + cfg.trialdef.threshold = 2e6; cfg.trialdef.prestim = 1; % in seconds cfg.trialdef.poststim = 2; % in seconds cfg = ft_definetrial(cfg); @@ -179,21 +185,21 @@ You will see that the trial function produces a figure, which can be used to che FIXME insert figure (1 data loading) -The segments of interest are specified by their begin- and endsample and by the offset that specifies the timing relative to the data segment. The offset is zero here indicating that the first sample is interpreted as time t=0. +The segments of interest are specified by their begin- and endsample and by the offset that specifies the timing relative to the data segment. The offset is 2000, indicating that sample 2000 in every trial is considered as time t=0. >> cfg.trl ans = - 7447 13446 0 - 17447 23446 0 - 27447 33446 0 - 37447 43446 0 - 47446 53445 0 - 57445 63444 0 - 67445 73444 0 - ... + 7447 13446 -2000 + 17447 23446 -2000 + 27447 33446 -2000 + 37447 43446 -2000 + 47447 53446 -2000 + 57447 63446 -2000 + 67447 73446 -2000 + ... -### preprocessing +### Reading and filtering After the segments of interest have been specified as `cfg.trl`, we read them from disk into memory. At this step we also specify other preprocessing options such as the filter settings. @@ -206,7 +212,7 @@ After the segments of interest have been specified as `cfg.trl`, we read them fr cfg.lpfreq = 100; data = ft_preprocessing(cfg); -The output of ft_preprocessing is a structure which has the following field +The output of ft_preprocessing is a structure which has the following fields: data = hdr: [1x1 struct] @@ -217,7 +223,7 @@ The output of ft_preprocessing is a structure which has the following field sampleinfo: [88x2 double] cfg: [1x1 struct] -In `data.sampleinfo` you can find the begin and endsample of each trial. The offset has been used to make an individual time axis `data.time` for each trial. +In `data.sampleinfo` you can find the begin and endsample of each trial: these are copied over from the 1st and 2nd column of `cfg.trl`. The offset in the 3rd column has been used to make an individual time axis `data.time` for each trial. We can plot all channels for a single trial using standard MATLAB code: @@ -230,7 +236,7 @@ FIXME insert figure (2 single trial plot ) ### Checking for artifacts -Using **[ft_databrowser](/reference/ft_databrowser)** we can do a quick visual inspection of the data in all trials and check for artefacts. +Using **[ft_databrowser](/reference/ft_databrowser)** we can do a quick visual inspection of the data in each trials and check for artefacts. cfg = []; cfg.viewmode = 'butterfly'; @@ -238,7 +244,7 @@ Using **[ft_databrowser](/reference/ft_databrowser)** we can do a quick visual i FIXME insert figure (3 datatrial browser) -The 41th channel with th elabel 'HL1' contains the analog TTL trigger, which is of much larger amplitude than all other channels. We can exclude it in the GUI by clicking the "channel" button or by using the following code: +The 41th channel with label 'HL1' contains the analog TTL trigger, which is of much larger amplitude than all other channels. We can exclude it in the GUI by clicking the "channel" button and removing it or by using the following code: cfg = []; cfg.viewmode = 'vertical'; @@ -255,7 +261,7 @@ During acquisition the two most frontal electrodes in the grid were used as the cfg = []; cfg.reref = 'yes'; - cfg.channel = {'all', '-HL1'}; % we don't want to re-reference the trigger channel + cfg.channel = {'all', '-VPM', '-Sync', '-HL1'}; % we don't want to re-reference these cfg.refchannel = {'FP1';'FP2';... 'AF3';'AF4';'AF7';'AF8';... 'F1';'F2';'F5';'F6';... @@ -265,198 +271,212 @@ During acquisition the two most frontal electrodes in the grid were used as the 'P1';'P2';'P3';'P4';'P5';'P6';... 'PO3';'PO4';'PO7';'PO8';... 'O1';'O2'}; - data_car = ft_preprocessing(cfg, data); + data_reref = ft_preprocessing(cfg, data); + +We have now lost the LFP, since that should not be rereferenced to the common average reference. We can get it back from the original data and append it to the rereferenced EEG data. + + cfg = []; + cfg.channel = 'VPM'; + data_vmp = ft_selectdata(cfg, data); + + cfg = []; + data_reref = ft_appenddata(cfg, data_reref, data_vmp); You can compare the original and re-referenced data using ft_databrowser. cfg = []; cfg.viewmode = 'vertical'; - cfg.channel = {'all', '-HL1'}; - cfg = ft_databrowser(cfg, data_car); + cfg = ft_databrowser(cfg, data_reref); FIXME insert figure (5 datatrial browser) -## Channel level analysis - ERPs - -### making a channel layout and deal with animal size +### Making a channel layout for plotting -In order to make layout of high-density electrode array (HD-array) on mouse skull, FieldTrip support layout files ('mouse_layout.mat') that gives you exact control of the 2-D position of the sensors for topoplotting, and of the per-channel local coordinate axes for the multiplotting. The mat-file containing various variables to draw outlines of the headshape within the name “lay”. +For 2D plotting of the channel data, FieldTrip makes use of so-called [layouts](/tutorial/layout). These layouts specify the location and size of each channel, and can include an outline (for example of the mouse head) and a mask to restrict the topographic interpolation for topoplots. -Let us give you the information how to make customized layout for HD-array by using FieldTrip. -This figure indicates an electrode arrangement of HD-array (this example photo is taken from Lee et al. (2011) Journal of Visualized Experiments ([video](http://www.jove.com/video/2562/high-density-eeg-recordings-freely-moving-mice-using-polyimide-based), [pdf](http://www.jove.com/pdf/2562/jove-protocol-2562-high-density-eeg-recordings-freely-moving-mice-using-polyimide-based)). +To make a customized layout for the EEG array we start with a figure that indicates the electrode arrangement. This example photo is taken from Lee et al. (2011) Journal of Visualized Experiments ([video](http://www.jove.com/video/2562/high-density-eeg-recordings-freely-moving-mice-using-polyimide-based), [pdf](http://www.jove.com/pdf/2562/jove-protocol-2562-high-density-eeg-recordings-freely-moving-mice-using-polyimide-based). {% include image src="/assets/img/tutorial/mouse_eeg/figure2.png" width="400" %} -You can specify cfg.image in ft_prepare_layout and subsequently click on the location of each electrode. After specifying each electrode location, you'll be asked to specify the outlines of the head (i.e. the circle around the head, the eyes, the nose and ears (dash lines) and optionally some lines representing other important landmarks: bold lines, bregma, and lambda) and to specify the mask for the topographic interpolation (green dash line). +You can specify `cfg.image` in **[ft_prepare_layout](/reference/ft_prepare_layout)** and subsequently click on the location of each electrode. After specifying each electrode location, you'll be asked to specify the outlines of the head (i.e. the circle around the head, the eyes, the nose and ears (dash lines) and optionally some lines representing other important landmarks: bold lines, bregma, and lambda) and to specify the mask for the topographic interpolation (green dash line). Find the bregma and lambda points on the skull, and record them with the stereotaxic ruler. The bregma and lambda points are located in the same anterio-posterior axis. -The anterio-posterior axis of high-density electrode array (HD-array) matches the line between bregma and lambda points. The bregma point (0, 0) should be located at the middle of the 4th layer of the anterior of HD-array because we follow the Paxinos coordinate system. We implemented a mouse layout on fixed length (4.2 mm) of between bregma and lambda. +The anterio-posterior axis of high-density electrode array (HD-array) matches the line between bregma and lambda points. The bregma point (0, 0) should be located at the middle of the 4th layer of the anterior of HD-array because we follow the Paxinos coordinate system. We implemented a mouse layout on fixed length (4.2 mm) between bregma and lambda. cfg = []; cfg.image = 'mouse_skull_with_HDEEG.png'; - lay = ft_prepare_layout(cfg); - -After creating the layout, you should manually assign the correct name of the channel labels in the lay.label cell-array. Channel arrangement in lay.label is followed click sequence during ft_prepare_layout process. You can use ft_layoutplot for a visual inspection of the complete layout. + layout = ft_prepare_layout(cfg); - cfg = []; - cfg.layout = lay; - ft_layoutplot(cfg); +After creating the layout, you should manually assign the correct name of the channel labels in the `layout.label` cell-array. The channel order in `layout.label` should correspond to the sequence in which you clicked the electrodes. You can use **[ft_plot_layout](/reference/plotting/ft_plot_layout)** for a visual inspection of the layout. You will see that a placeholder have been added for the comment and the scale. FIXME insert figure (6 layout plot) If you think that some outlines (nose, eyes, head, whiskers and ears) are not necessary, you can pass without assigning any outline. Next step is zero point calibration for the bregma point. If you, however, use customized layout for single subject, you don't need to carry out next step. -In the aspect of mouse anatomy, the bregma point is located in the middle of the 4th layer of the anterior of HD-array that it should be set (0, 0) because we follow the Paxinos coordinate system. To calibrate layout position, we just subtract the value of bregma on acquired layout from previous step. +Coinsidering the mouse anatomy, the bregma point is located in the middle of the 4th layer of the anterior of the EEG array that it should be set (0, 0) because we follow the Paxinos coordinate system. To calibrate layout position, we just subtract the value of bregma on acquired layout from previous step. - xy_shift = [382, 280]; - lay.pos = lay.pos – repmat(xy_shift, size(lay.pos, 1), 1); - lay.mask{1, 1} = lay.mask{1, 1}- repmat(xy_shift, size(lay.mask{1, 1}, 1), 1); - - for i =1:1:size(lay.outline, 2) - lay.outline{1, i}= lay.outline{1, i}- repmat(xy_shift, size(lay.outline{1, i}, 1), 1); + bregma = [382, 280]; + layout.pos = layout.pos – repmat(bregma, size(layout.pos, 1), 1); + for i=1:numel(layout.outline) + layout.outline{i}= layout.outline{i} - repmat(bregma, size(layout.outline{1, i}, 1), 1); + end + for i=1:numel(layout.mask) + layout.mask{i}= layout.mask{i} - repmat(bregma, size(layout.mask{1, i}, 1), 1); end To confirm your calibration, - cfg = []; - cfg.layout = lay; - ft_layoutplot(cfg); + figure + ft_plot_layout(layout) + axis on + grid on FIXME insert figure (7 layout plot) -If you are satisfy with the result, you can save it to a MATLAB file: +If you are satisfy with the result, you should save it to a MATLAB file. However, in the case of this specific tutorial you probably don't want to overwrite the mat file that you downloaded, but rather read it from disk and inspect it with **[ft_plot_layout](/reference/plotting/ft_plot_layout)**. - save mouse_eeg.mat lay + if false + save mouse_layout.mat layout + else + load mouse_layout.mat + end -HD-array is not scalable material. Each mouse, however, has different head size depending on strain, age, weight and gender. To circumvent this problem, we set to distance of bregma and lambda as the reference scale (4.2 mm). This distance could determine the level of head size with respect to individual subject. To get scalable mouse layout easily, we made a simple function ( ft_mouse_headsize_calibration ). If you use “ft_mouse_headsize_calibration” function, you can get calibrated head layout depending on the distance of bregma and lambda. The value of this function, cfg.B2Ldistance, is only affect size of outlines. This keeps the electrodes and the mask the same. -Take an example script as belo +### Deal with differences in animal size - cfg = []; - cfg.layout = 'mouse_layout.mat'; % mouse electrode layout - cfg.B2Ldistance = 3.8; % unit (mm) - [lay_new] = ft_mouse_headsize_calibration(cfg); +The polyimide fiml from which the EEG array is made is not strechable. Each mouse, however, has a different head size depending on its strain, age, weight and sex. To deal with the different sizes, we use the distance between bregma and lambda and a reference scale of 4.2 mm. If you have a smaller mouse, and consequently a relatively wider spaced EEG array for that specific mouse, you can scale the layout to accommodate this. The approach here to deal with differences in the mouse brain size are very comparable to those adopted in the Talairach-Tournoux anatomical atlas of the human brain. -To confirm your calibration, +For example for a mouse with a bregma-lambda distance of 3.8, you can do the following. - cfg = []; - cfg.layout = lay_new; - ft_layoutplot(cfg); + layout42 = layout; % this is the reference + layout38 = layout; % make a copy, this will be updated -{% include image src="/assets/img/tutorial/mouse_eeg/figure3.png" width="400" %} + ratio = 4.2/3.8; % the electrodes span a relatively larger part of the head on the smaller-sized animal -:!: This is discussed on + layout38.pos = layout42.pos; * ratio; + for i=1:numel(layout38.outline) + layout38.outline{i} = layout42.outline{i} * ratio; + end + for i=1:numel(layout38.mask) + layout38.mask{i} = layout42.mask{i} * ratio; + end -The current standards to deal with differences in mouse brain size are very comparable to those adopted in the Talairach-Tournoux anatomical atlas of the human brain. For human EEG it is easy to make use of a template and to compare or average subjects, since EEG recording caps scale along with the size of the human head. e.g., at the Donders we have caps in different sizes, ranging from 52 to 60 cm head circumference in 2cm steps, thereby accommodating approximately a 15% variance in head circumference. +Again, to confirm your calibration: -For the mouse the electrode grids are however of fixed dimensions, but the head sizes still differ. + figure + ft_plot_layout(layout38) + axis on + grid on -For example, let's think about a case of targetting CA1 hippocampus which is (AP, ML, DV) = -2, 1.5, -2 with respect to the bregma according to the mouse atlas. Each individual mouse has different brain size. What we do is to measure the length between bregma to lambda, and if the length is 4.2 mm, we multiply the target distance by 4.2/3.9 ~= 1.077. Hence the stereotaxic target for CA1 would be (AP, ML, DV) = -2.15, 1.62, -2.15. -Since the tolerance range of the stereotaxic is 0.1 mm, the actual target would be -2.1, 1.6, -2.1. -I observed that some group rescale only anterior posterior (AP). Hence according to them the target coordinate would be -2.1, 1.5, -2. Unlike human, mouse has a secondary confirmation procedure, which is called histology. Hence, we can confirm whether we hit the target or not via histological procedure after recordings. -For your information, many neuroscientists agree that this rescaling method can work as a rule of thumb but individual difference between animals cannot be neglected, emphasizing the post-hoc histological confirmation. +{% include image src="/assets/img/tutorial/mouse_eeg/figure3.png" width="400" %} -The anatomical structure of mouse brain due not vary dramatically if the weight and/or the length between bregma and lambda are in the similar range, in a sense of a few hundreds micrometer. For example, any structure with a dimension ranging larger than a couple of hundreds um, we seldom fail to hit this structure. However, when we aim for a structure with a sharp shape with dimension smaller than a couple of hundreds um, we half fail to hit that structure. But if this structure is on the cortex or near, we seldom fail. +For human EEG it is convenient to make use of a single template for the electrode positions. Human EEG caps come in different sizes, for example ranging from 52 to 60 cm head circumference in 2cm steps, and those are also are slightly variable. This range of human EEG caps can therefore accommodate approximately a 15% difference in head circumference. For the mouse the electrode grids are however fixed dimensions, whereas the head sizes still differ. -### compute and visualize the ERPs +For example, let's think about a case of targetting CA1 hippocampus which is (AP, ML, DV) = (-2, 1.5, -2) with respect to the bregma according to the mouse atlas. Each individual mouse has different brain size. What we do is to measure the length between bregma to lambda, and if the length is 3.9 mm, we multiply the target distance by `4.2/3.9 = 1.077`. Hence the stereotaxic target for CA1 would be (AP, ML, DV) = (-2.15, 1.62, -2.15). Since the accuracy of the stereotaxic is 0.1 mm, the actual target becomes be (-2.1, 1.6, -2.1). -The ERP that is time locked to stimulus onset is computed by averaging the data segments over all trials. +Note that some mouse research groups rescale only anterior posterior (AP) and according to them the target coordinate would be -2.1, 1.5, -2. - cfg = []; - timelock = ft_timelockanalysis(cfg, data); +In the mouse we can use histology as a a secondary confirmation procedure after recordings. The anatomical structure of mouse brain due not vary dramatically if the weight and/or the length between bregma and lambda are in the similar range, in a sense of a few hundreds micrometer. For example, any structure with a dimension ranging larger than a couple of hundreds micrometer, we seldom fail to hit this structure. However, when we aim for a structure with a sharp shape with dimension smaller than a couple of hundreds micrometer, we half fail to hit that structure. But if this structure is on the cortex or near, we seldom fail. -We can plot it with standard MATLAB command +## Channel level analysis - ERPs + +The ERP time-locked to stimulus onset is computed by averaging the data over all trials. + + cfg = []; + timelock = ft_timelockanalysis(cfg, data_reref); + +We can again plot it with a standard MATLAB command. figure - plot(timelock.time, timelock.avg(1:40,:)); % excluding channel HL1 - legend(timelock.label(1:40)); + plot(timelock.time, timelock.avg); + legend(timelock.label); FIXME insert figure (8 timelock plot) -Using the figure legend, we see that channel VPM shows a large response to the stimulation. This makes sense, because channel VPM corresponds to the depth electrode that is inserted along with the optode, i.e. it records from the stimulated site. +Looking at the figure legend, you can see that channel VPM shows a particularly large response to the stimulation. This makes sense, as it corresponds to the depth electrode that is inserted along with the optode, i.e. it records from the stimulated site. -Rather than plotting all ERPs on top of each other, we can also plot them according to the channel layout. +Rather than plotting all ERPs on top of each other, we can also plot them according to the channel layout. For that we use the function **[ft_multiplotER](/reference/ft_multiplotER)**. cfg = []; - cfg.layout = 'mouse_eeg14.mat'; + cfg.layout = 'mouse_layout.mat'; % from file cfg.showoutline = 'yes'; - figure + cfg.interactive = 'no'; % or 'yes' ft_multiplotER(cfg, timelock); FIXME insert figure (9 timelock plot) -You can use the zoom in and zoom out buttons of MATLAB. Furthermore, you can make a selection of channels and click in the selection, which causes them to be averaged and displayed in a single plot. In the single plot, you can make a selection of time (i.e. latency), which is subsequently averaged as an interpolated topographic distribution of the potential. +When you specify `cfg.interactive = 'no'` you can use the MATLAB zoom buttons. With `cfg.interactive = 'yes'` the zoom buttonsd don't work properly, but you can make a selection of channels and click in the selection, which causes them to be averaged and displayed in a single plot. In the single plot, you can again make a selection of time, which is subsequently averaged (for all channels) and shown as the interpolated topographic distribution of the potential. + +FIXME insert figure (singleplot) + +FIXME insert figure (topoplot) ## Channel level analysis - TFRs -In this section, we will describe how to calculate time-frequency representations using Hanning window. +This section describes how to calculate time-frequency representations using Hanning window. - %% power spectrogram + % power spectrogram cfg = []; cfg.output = 'pow'; cfg.method = 'mtmconvol'; cfg.taper = 'hanning'; - cfg.foi = 4:2:100; % frequency of interest - cfg.t_ftimwin = ones(length(cfg.foi),1).*0.25; % 250 ms window - cfg.toi = -1:0.01:3.0; % -1:0.01:3.0; - freq = ft_freqanalysis(cfg, data); + cfg.foi = 4:4:100; % frequencies of interest + cfg.t_ftimwin = ones(length(cfg.foi),1)*0.250; % 250 ms window + cfg.toi = -1:0.01:3.0; % from -1 to 3 seconds in steps of 0.01 + freq = ft_freqanalysis(cfg, data_reref); -The output of **[ft_freqanalysis](/reference/ft_freqanalysis)** is a structure which has the following field +The output of **[ft_freqanalysis](/reference/ft_freqanalysis)** is a structure which has the following fields: freq = - - label: {41x1 cell} + powspctrm: [39x25x401 double] dimord: 'chan_freq_time' - freq: [1x49 double] - time: [1x401 double] - powspctrm: [41x49x401 double] + label: {39x1 cell} + freq: [4 8 12 16 20 24 ... 96 100] + time: [-1 -0.9900 -0.9800 -0.9700 ... 2.9900 3.0000] cfg: [1x1 struct] -The element freq.powspctrm contains the temporal response (-1 ~ 3 sec, 0.01 sec sliding) of the power for each specified frequency (4~ 100 Hz, 2 Hz step). - -### visualizing TFRs +The element `freq.powspctrm` contains the power for each of the 39 channels, for each of the 401 timepoints, and for each of the 25 frequencies (from 4 to 100 in 4Hz steps). -This part shows how to visualize the results of time-frequency analysis with respect to **[ft_multiplotTFR](/reference/ft_multiplotTFR)** and **[ft_singleplotTFR](/reference/ft_singleplotTFR)**. +The results of the time-frequency analysis can be plotted with **[ft_multiplotTFR](/reference/ft_multiplotTFR)** and **[ft_singleplotTFR](/reference/ft_singleplotTFR)**. To visualize the power changes due to stimulation and to compare the power over frequencies, we perform a normalization with respect to the baseline. By specifying `cfg.baselinetype = 'relchange'` we compute the relative change, which is the power minus the average power in the baseline, divided the average power in the baseline. -To visualize the power changes, a normalization with respect to a baseline interval will be performed. -This method, "relchange", means (active period-baseline)/baseline. Note that the "relchange" is expressed as a ratio of subtracting, for each frequency. -If you want to visualize TFR on the head outline of mouse, "cfg.layout=mouse_layout.mat" have to be declared. - - %% visualization of all EEG channels + % visualization of all EEG channels cfg = [] ; cfg.xlim = [-1 2]; cfg.ylim = [4 100]; cfg.zlim = [-1.0 1.0]; cfg.colorbar = 'yes'; - cfg.layout = 'mouse_layout.mat'; + cfg.layout = 'mouse_layout.mat'; % see above cfg.showoutline = 'yes'; cfg.baseline = [-0.5 0]; cfg.baselinetype = 'relchange' ; ft_multiplotTFR(cfg, freq); FIXME insert figure (10 ft_multiplotTFR) +FIXME insert figure (11 ft_topoplotTFR) + +Again with `cfg.interactive = 'yes'`, which is the default, you can select one or multiple channels, click on them and get an average TFR over those channels,. In that average you can make a time and frequency selection, click in it, and get a spatial topopgraphy of the relative power over all channels in that fime-frequency range. -Otherwise, you can visualize TFR sequentially without mouse layout. +If you did not construct a layout, you can visualize the TFRs sequentially over all channels. An advantage of this is that in contrast to the previous figure, channel VMP is now also plotted. There is no location for that channel in the layout contained in the `mouse_layout.mat` file. - %% visualization of all EEG channels, not topographically arranged + % visualization of all EEG channels, not topographically arranged cfg = [] ; cfg.xlim = [-1 2]; cfg.ylim = [4 100]; cfg.zlim = [-1.0 1.0]; cfg.colorbar = 'yes'; - cfg.layout = 'ordered' + cfg.layout = 'ordered'; % see FT_PREPARE_LAYOUT cfg.showlabels = 'yes'; cfg.baseline = [-0.5 0]; cfg.baselinetype = 'relchange' ; ft_multiplotTFR(cfg, freq); -FIXME insert figure (11 ft_multiplotTFR with order) +FIXME insert figure (12 ft_multiplotTFR with ordered) -And, you can also visualize single TFR per each channel. +You can also explicitly visualize a TFR for a specific channel. - %% single channel visualization + % single channel visualization cfg = [] ; - cfg.channel = 'C4'; % channel + cfg.channel = 'VMP'; % you can also specify multiple, it will then average cfg.xlim = [-1 2]; cfg.ylim = [4 100]; cfg.zlim = [-1.0 1.0]; @@ -464,9 +484,10 @@ And, you can also visualize single TFR per each channel. cfg.baseline = [-0.2 0]; cfg.baselinetype = 'relchange' ; ft_singleplotTFR(cfg, freq); - xlabel('Sec'); ylabel('Hz'); + xlabel('time (s)') + ylabel('frequency (Hz)') -FIXME insert figure (12 ft_singleplotTFR with order) +FIXME insert figure (13 ft_singleplotTFR with order) ## Coregistration of anatomy and construction of volume conduction model @@ -838,10 +859,10 @@ The beamforming technique is based on the spatial filter. [The DICS spatial filt Before applying cross-spectral density matrix, the redefine of time interval and the channel selection will be carry out like below. - %% data redefine and cross frequency analysis + % data redefine and cross frequency analysis cfg = []; cfg.toilim = [-0.6 -0.1]; - dataPre = ft_redefinetrial(cfg, data_car); + dataPre = ft_redefinetrial(cfg, data_reref); cfg = []; cfg.channel = {'all', '-VPM', '-Sync', '-HL1'}; dataPre = ft_preprocessing(cfg, dataPre);