This shows you the differences between two versions of the page.

tutorial:timefrequencyanalysis [2012/07/24 15:44] 192.87.10.82 [Morlet wavelets] bandwidth and duration |
tutorial:timefrequencyanalysis [2016/02/11 17:51] (current) johzum [Visualization] |
||
---|---|---|---|

Line 1: | Line 1: | ||

- | {{tag>tutorial freq meg eeg plot}} | + | {{tag>tutorial freq meg eeg plot MEG-language}} |

====== Time-frequency analysis using Hanning window, multitapers and wavelets ====== | ====== Time-frequency analysis using Hanning window, multitapers and wavelets ====== | ||

Line 6: | Line 6: | ||

In this tutorial you can find information about the time-frequency analysis of a single subject's MEG data using a Hanning window, multitapers and wavelets. This tutorial also shows how to visualize the results. | In this tutorial you can find information about the time-frequency analysis of a single subject's MEG data using a Hanning window, multitapers and wavelets. This tutorial also shows how to visualize the results. | ||

- | We will continue working on the [[tutorial:shared:dataset|dataset]] described in the preprocessing tutorials. Below we will repeat code to select the trials and preprocess the data as described in the first tutorials ([[tutorial:Preprocessing|trigger based trial selection]], [[tutorial:visual_artifact_rejection|visual artifact rejection]]). We assume that the reader already knows how to do the preprocessing in FieldTrip. | + | Here, we will work on the MEG-language-semantics dataset, you can click [[tutorial:shared:dataset|here]] for details on the dataset. This tutorial is a continuation from the preprocessing tutorials. We will begin by repeating the code used to select the trials and preprocess the data as described in the first tutorials ([[tutorial:Preprocessing| trigger based trial selection]], [[tutorial:artifacts|artifact rejection]]). We assume that the reader already knows how to do the preprocessing in FieldTrip. |

- | There is no information in this tutorial about how to compare conditions, how to grandaverage the results across subject or how to do statistical analysis on the time-frequency data. Some of these issues are covered in other tutorials (see Summary and suggested further reading). | + | There is no information in this tutorial about how to compare conditions, how to grandaverage the results across subjects or how to do statistical analysis on the time-frequency data. Some of these issues are covered in other tutorials (see [[#Summary and suggested further reading]]). |

+ | | ||

+ | <note exercise> | ||

+ | This tutorial contains hands-on material that we use for the [[/workshop/toolkit2015|MEG/EEG toolkit course]] and is complemented by this lecture. | ||

+ | | ||

+ | {{youtube>vwPpSglPJTE}} | ||

+ | </note> | ||

===== Background ===== | ===== Background ===== | ||

Line 27: | Line 33: | ||

To calculate the time-frequency analysis for the example dataset we will perform the following steps: | To calculate the time-frequency analysis for the example dataset we will perform the following steps: | ||

- | * Read the data into Matlab using **[[reference:ft_definetrial|ft_definetrial]]** and **[[reference:ft_preprocessing|ft_preprocessing]]** | + | * Read the data into MATLAB using **[[reference:ft_definetrial|ft_definetrial]]** and **[[reference:ft_preprocessing|ft_preprocessing]]** |

* Compute the power values for each frequency bin and each time bin using the function **[[reference:ft_freqanalysis|ft_freqanalysis]]** | * Compute the power values for each frequency bin and each time bin using the function **[[reference:ft_freqanalysis|ft_freqanalysis]]** | ||

* Visualize the results. This can be done by creating time-frequency plots for one (**[[reference:ft_singleplotTFR|ft_singleplotTFR]]**) or several channels (**[[reference:ft_multiplotTFR|ft_multiplotTFR]]**), or by creating a topographic plot for a specified time- and frequency interval (**[[reference:ft_topoplotTFR|ft_topoplotTFR]]**). | * Visualize the results. This can be done by creating time-frequency plots for one (**[[reference:ft_singleplotTFR|ft_singleplotTFR]]**) or several channels (**[[reference:ft_multiplotTFR|ft_multiplotTFR]]**), or by creating a topographic plot for a specified time- and frequency interval (**[[reference:ft_topoplotTFR|ft_topoplotTFR]]**). | ||

Line 48: | Line 54: | ||

We will here describe how to calculate time frequency representations using Hanning tapers. When choosing for a fixed window length procedure the frequency resolution is defined according to the length of the time window (delta T). The frequency resolution (delta f in figure 1) = 1/length of time window in sec (delta T in figure 1). Thus a 500 ms time window results in a 2 Hz frequency resolution (1/0.5 sec= 2 Hz) meaning that power can be calculated for 2 Hz, 4 Hz, 6 Hz etc. An integer number of cycles must fit in the time window. | We will here describe how to calculate time frequency representations using Hanning tapers. When choosing for a fixed window length procedure the frequency resolution is defined according to the length of the time window (delta T). The frequency resolution (delta f in figure 1) = 1/length of time window in sec (delta T in figure 1). Thus a 500 ms time window results in a 2 Hz frequency resolution (1/0.5 sec= 2 Hz) meaning that power can be calculated for 2 Hz, 4 Hz, 6 Hz etc. An integer number of cycles must fit in the time window. | ||

- | **[[reference:ft_freqanalysis|ft_Freqanalysis]]** requires preprocessed data (see above), which is available from ftp://ftp.fcdonders.nl/pub/fieldtrip/tutorial/timefrequencyanalysis/dataFIC.mat. | + | **[[reference:ft_freqanalysis|Ft_freqanalysis]]** requires preprocessed data (see above), which is available from ftp://ftp.fieldtriptoolbox.org/pub/fieldtrip/tutorial/timefrequencyanalysis/dataFIC.mat. |

load dataFIC | load dataFIC | ||

Line 88: | Line 94: | ||

===== Visualization ===== | ===== Visualization ===== | ||

- | This part of the tutorial shows how visualize the results of any type of time-frequency analysis. | + | This part of the tutorial shows how to visualize the results of any type of time-frequency analysis. |

To visualize the event-related power changes, a normalization with respect to a baseline interval will be performed. There are two possibilities for normalizing: (a) subtracting, for each frequency, the average power in a baseline interval from all other power values. This gives, for each frequency, the absolute change in power with respect to the baseline interval. (b) expressing, for each frequency, the raw power values as the relative increase or decrease with respect to the power in the baseline interval. This means active period/baseline. Note that the relative baseline is expressed as a ratio; i.e. no change is represented by 1. | To visualize the event-related power changes, a normalization with respect to a baseline interval will be performed. There are two possibilities for normalizing: (a) subtracting, for each frequency, the average power in a baseline interval from all other power values. This gives, for each frequency, the absolute change in power with respect to the baseline interval. (b) expressing, for each frequency, the raw power values as the relative increase or decrease with respect to the power in the baseline interval. This means active period/baseline. Note that the relative baseline is expressed as a ratio; i.e. no change is represented by 1. | ||

- | There are three ways of graphically representing the data: 1) time-frequency plots of all channels, in a quasi-topographical layout, 2) time-frequency plot of an individual channel, 3) topographical 2-D map of the power changes in a specified time-frequency interval. | + | There are three ways of graphically representing the data: 1) time-frequency plots of all channels, in a quasi-topographical layout, 2) time-frequency plot of an individual channel (or average of several channels), 3) topographical 2-D map of the power changes in a specified time-frequency interval. |

To plot the TFRs from all the sensors use the function **[[reference:ft_multiplotTFR|ft_multiplotTFR]]**. Settings can be adjusted in the cfg structure. For example: | To plot the TFRs from all the sensors use the function **[[reference:ft_multiplotTFR|ft_multiplotTFR]]**. Settings can be adjusted in the cfg structure. For example: | ||

Line 109: | Line 115: | ||

//Figure 3; Time-frequency representations calculated using **[[reference:ft_freqanalysis|ft_freqanalysis]]**. Plotting was done with **[[reference:ft_multiplotTFR|ft_multiplotTFR]]**// | //Figure 3; Time-frequency representations calculated using **[[reference:ft_freqanalysis|ft_freqanalysis]]**. Plotting was done with **[[reference:ft_multiplotTFR|ft_multiplotTFR]]**// | ||

- | Note that by using the options cfg.baseline and cfg.baselinetype when calling plotting functions, baseline correction can be applied to the data. Baseline correction can also be applied directly by calling **[[reference:ft_freqbaseline|ft_freqbaseline]]**. | + | Note that by using the options cfg.baseline and cfg.baselinetype when calling plotting functions, baseline correction can be applied to the data. Baseline correction can also be applied directly by calling **[[reference:ft_freqbaseline|ft_freqbaseline]]**. You can combine the various visualisation options/functions interactively to explore your data. Currently, this is the default ploting behavior because the configuration option cfg.interactive='yes' is activated unless you explicitly select cfg.interactive='no' before calling **[[reference:ft_multiplotTFR|ft_multiplotTFR]]** to deactivate it. See also the [[tutorial:plotting|plotting tutorial]] for more details. |

An interesting effect seems to be present in the TFR of sensor MRC15. To make a plot of a single channel use the function **[[reference:ft_singleplotTFR|ft_singleplotTFR]]**: | An interesting effect seems to be present in the TFR of sensor MRC15. To make a plot of a single channel use the function **[[reference:ft_singleplotTFR|ft_singleplotTFR]]**: | ||

Line 115: | Line 121: | ||

cfg = []; | cfg = []; | ||

cfg.baseline = [-0.5 -0.1]; | cfg.baseline = [-0.5 -0.1]; | ||

- | cfg.baselinetype = 'absolute'; | + | cfg.baselinetype = 'absolute'; |

+ | cfg.maskstyle = 'saturation'; | ||

cfg.zlim = [-3e-27 3e-27]; | cfg.zlim = [-3e-27 3e-27]; | ||

cfg.channel = 'MRC15'; | cfg.channel = 'MRC15'; | ||

Line 140: | Line 147: | ||

cfg.zlim = [-1.5e-27 1.5e-27]; | cfg.zlim = [-1.5e-27 1.5e-27]; | ||

cfg.ylim = [15 20]; | cfg.ylim = [15 20]; | ||

- | cfg.showlabels = 'markers'; | + | cfg.marker = 'on'; |

figure | figure | ||

ft_topoplotTFR(cfg, TFRhann); | ft_topoplotTFR(cfg, TFRhann); | ||

Line 148: | Line 155: | ||

//Figure 5; A topographic representation of the time-frequency representations (15 - 20 Hz, 0.9 - 1.3 s post stimulus) obtained using **[[reference:ft_topoplotTFR|ft_topoplotTFR]]**// | //Figure 5; A topographic representation of the time-frequency representations (15 - 20 Hz, 0.9 - 1.3 s post stimulus) obtained using **[[reference:ft_topoplotTFR|ft_topoplotTFR]]**// | ||

- | |||

- | |||

- | You can combine the various visualisation options/functions to interactively explore the data. This is done by starting with **[[reference:ft_multiplotTFR|ft_multiplotTFR]]** and the option cfg.interactive='yes'. See also the [[tutorial:plotting|plotting tutorial]] for more details. | ||

- | |||

- | cfg = []; | ||

- | cfg.baseline = [-0.5 -0.1]; | ||

- | cfg.baselinetype = 'absolute'; | ||

- | cfg.zlim = [-3e-27 3e-27]; | ||

- | cfg.showlabels = 'yes'; | ||

- | cfg.layout = 'CTF151.lay'; | ||

- | cfg.interactive = 'yes'; % note this option | ||

- | figure | ||

- | ft_multiplotTFR(cfg, TFRhann); | ||

- | |||

- | (The figures resulting from the interactive plotting mode are not demonstrated in this tutorial.) | ||

== Exercise 1 == | == Exercise 1 == | ||

Line 203: | Line 195: | ||

cfg = []; | cfg = []; | ||

cfg.baseline = [-0.5 -0.1]; | cfg.baseline = [-0.5 -0.1]; | ||

- | cfg.baselinetype = 'absolute'; | + | cfg.baselinetype = 'absolute'; |

+ | cfg.maskstyle = 'saturation'; | ||

cfg.zlim = [-3e-27 3e-27]; | cfg.zlim = [-3e-27 3e-27]; | ||

cfg.channel = 'MRC15'; | cfg.channel = 'MRC15'; | ||

+ | cfg.interactive = 'no'; | ||

figure | figure | ||

ft_singleplotTFR(cfg, TFRhann7); | ft_singleplotTFR(cfg, TFRhann7); | ||

Line 215: | Line 209: | ||

Note the boundary effects for lower frequencies (the white time frequency points in the plot). There is no power value calculated for these time frequency points. The power value is assigned to the middle time point in the time window. For example for 2 Hz the time window has a length of 3.5 sec (1/2 * 7 cycles = 3.5 sec), this does not fit in the 3 sec window that is preprocessed and therefore there is no data point here. For 5 Hz the window has a length of 1.4 sec (1/5 * 7 cycles = 1.4 sec). We preprocessed data between t = -1 sec and t = 2 sec so the first power value is assigned to t= -0.3 (since -1 + (0.5 * 1.4) = -0.3). Because of these boundary effects it is important to apply **[[reference:ft_freqanalysis |ft_freqanalysis ]]** to a larger time window to get all the time frequency points for your time window of interest. | Note the boundary effects for lower frequencies (the white time frequency points in the plot). There is no power value calculated for these time frequency points. The power value is assigned to the middle time point in the time window. For example for 2 Hz the time window has a length of 3.5 sec (1/2 * 7 cycles = 3.5 sec), this does not fit in the 3 sec window that is preprocessed and therefore there is no data point here. For 5 Hz the window has a length of 1.4 sec (1/5 * 7 cycles = 1.4 sec). We preprocessed data between t = -1 sec and t = 2 sec so the first power value is assigned to t= -0.3 (since -1 + (0.5 * 1.4) = -0.3). Because of these boundary effects it is important to apply **[[reference:ft_freqanalysis |ft_freqanalysis ]]** to a larger time window to get all the time frequency points for your time window of interest. | ||

- | If you would like to learn more about plotting of time-frequency representations, read Visualization. | + | If you would like to learn more about plotting of time-frequency representations, please see the [[#Visualization]] section. |

=== Exercise 3 === | === Exercise 3 === | ||

Line 281: | Line 275: | ||

cfg.tapsmofrq = 0.4 *cfg.foi; | cfg.tapsmofrq = 0.4 *cfg.foi; | ||

cfg.toi = -0.5:0.05:1.5; | cfg.toi = -0.5:0.05:1.5; | ||

- | cfg.pad = 'maxperlen'; | ||

TFRmult = ft_freqanalysis(cfg, dataFIC); | TFRmult = ft_freqanalysis(cfg, dataFIC); | ||

Line 302: | Line 295: | ||

//Figure 8; Time-frequency representations of power calculated using multitapers.// | //Figure 8; Time-frequency representations of power calculated using multitapers.// | ||

- | If you would like to learn more about plotting of time-frequency representations, read Visualization. | + | If you would like to learn more about plotting of time-frequency representations, please see the [[#Visualization]] section. |

===== Time-frequency analysis IV. ===== | ===== Time-frequency analysis IV. ===== | ||

Line 337: | Line 330: | ||

//Figure 9; Time-frequency representations of power calculated using Morlet wavelets.// | //Figure 9; Time-frequency representations of power calculated using Morlet wavelets.// | ||

- | If you would like to learn more about plotting of time-frequency representations, read the Visualization part of this tutorial. | + | If you would like to learn more about plotting of time-frequency representations, please see [[#Visualization]]. |

===== Summary and suggested further reading ===== | ===== Summary and suggested further reading ===== | ||

Line 343: | Line 336: | ||

After having finished this tutorial on time-frequency analysis, you can continue with the [[tutorial:beamformer|beamformer source reconstruction]] tutorial if you are interested in the source-localization of the power changes or the [[tutorial:/cluster_permutation_freq|cluster-based permutation tests on time-frequency data]] tutorial if you are interested how to do statistics on the time-frequency representations. | After having finished this tutorial on time-frequency analysis, you can continue with the [[tutorial:beamformer|beamformer source reconstruction]] tutorial if you are interested in the source-localization of the power changes or the [[tutorial:/cluster_permutation_freq|cluster-based permutation tests on time-frequency data]] tutorial if you are interested how to do statistics on the time-frequency representations. | ||

+ | |||

+ | Frequently asked questions: | ||

+ | {{topic>freq +faq &list}} | ||

+ | |||

+ | Example scripts: | ||

+ | {{topic>freq +example &list}} | ||

----- | ----- | ||

- | This tutorial was last tested with version 20120612 of FieldTrip by Jan-Mathijs, using Matlab 2011b on a 64-bit MacOS platform. | + | This tutorial was last tested by Robert with version 20150609 of FieldTrip using MATLAB R2014b on a 64-bit OS X computer. |

Share this page: