User Tools

Site Tools


analysis:nsb2014:week8

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
analysis:nsb2014:week8 [2014/08/01 09:16]
mvdm [FieldTrip setup]
analysis:nsb2014:week8 [2022/06/29 19:01] (current)
mvdm
Line 1: Line 1:
-~~DISCUSSION~~ 
- 
-Under construction! 
- 
 ===== Time-frequency analysis: spectrograms ===== ===== Time-frequency analysis: spectrograms =====
  
Line 299: Line 295:
 === Creating trial data in FieldTrip === === Creating trial data in FieldTrip ===
  
-To convert this single "​trial"​ containing the entire recording into proper trials surrounding events of interest, FieldTrip ​uses "​trialfun":​ a function ​that returns the times of the events of interest. These times, along with some parameters like how much time around ​the events to include, ​are then passed to the ''​ft_redefinetrial()''​ function, which cuts up the data into trials:+To convert this single "​trial"​ containing the entire recording into proper trials surrounding events of interest, ​%%FieldTrip%% requires ​''​trl''​ variable ​that specifies ​the start and end indices (into the data) which are then passed to the ''​ft_redefinetrial()''​ function, which cuts up the data into trials:
  
 <code matlab> <code matlab>
 cfg = []; cfg = [];
-cfg.trialfun ​= 'ft_trialfun_lineartracktone2'; +cfg.cat(2,​getd(evt,'​n0'​),​getd(evt,​'n1'))
-cfg.trialdef.hdr ​data.hdr+cfg.mode '​nlx'​
-cfg.trialdef.pre ​2.5+cfg.hdr data.hdr
-cfg.trialdef.post ​5;+cfg.twin [-1 4];
  
-cfg.trialdef.eventtype ​'​nosepoke';​ % could be '​nosepoke',​ '​reward',​ '​cue'​ +trl ft_maketrl(cfg);
-cfg.trialdef.location = '​both';​ % could be '​left',​ '​right',​ '​both'​ +
-cfg.trialdef.block = '​both';​ % could be '​value',​ '​risk'​ +
-cfg.trialdef.cue = {'​c1','​c3','​c5'​}% cell array with choice of elements {'​c1','​c3','​c5','​lo','​hi'​}+
  
-[trl, event= ft_trialfun_lineartracktone2(cfg);+cfg = [];
 cfg.trl = trl; cfg.trl = trl;
- +data_trl = ft_redefinetrial(cfg,​data); ​
-data_trl = ft_redefinetrial(cfg,​data);​+
 </​code>​ </​code>​
  
-The above reorganizes the data into 7-second windows (from -to seconds) around nosepoke times following the 1- 3- and 5-pellet cuesThe function ​''​ft_trialfun_lineartracktone2()'' ​is a more powerful version of ''​getEvents_value()'' ​we encountered above: it can accept a variety of requests for particular event times. For instance, if we only wanted nosepokes on the left side of the maze that followed the 3-pellet cue, we can specify this by changing ​'both' ​to '​left'​ and only including ​'c3'.+The above reorganizes the data into 4-second windows (from -to seconds) around nosepoke times (''​evt.n0'' ​and ''​evt.n1''​). ''​ft_maketrl()'' ​converts the event times from ''​LoadEvents()'' ​into the data indices ​that ''​ft_redefinetrial()'' ​needs.
  
-☛ Inspect the ''​data_trl''​ structure. Notice that there are now 88 trials instead of 1, and that each trial has its own time and data vectors. Plot the 47th trial as an example to verify this.+☛ Inspect the ''​data_trl''​ structure. Notice that there are now 115 trials instead of 1, and that each trial has its own time and data vectors. Plot the 47th trial as an example to verify this.
  
 === Constructing the event-triggered spectrogram === === Constructing the event-triggered spectrogram ===
Line 335: Line 327:
 cfg.foi ​         = 10:2:100; % frequencies of interest cfg.foi ​         = 10:2:100; % frequencies of interest
 cfg.t_ftimwin ​   = ones(size(cfg.foi)).*0.5; ​ % window size: fixed at 0.5s cfg.t_ftimwin ​   = ones(size(cfg.foi)).*0.5; ​ % window size: fixed at 0.5s
-cfg.toi ​         = -1:0.05:4; % times of interest+cfg.toi ​         = -0.5:0.05:3.5; % times of interest
  
 TFR = ft_freqanalysis(cfg,​ data_trl); TFR = ft_freqanalysis(cfg,​ data_trl);
Line 348: Line 340:
 You should get: You should get:
  
-{{ :analysis:course:​week6_fig4.png?​600 |}}+{{ :analysis:nsb2014:​week6_fig4.png?​600 |}}
  
-This plot is an //average// spectrogram over 88 trials, with time 0 corresponding to the time of nosepoking into the reward receptacle. As with the examples using ''​spectrogram()'',​ we can control the smoothness of the spectrogram by specifying the time and frequency steps. For the frequency steps this is accomplished the same way in FieldTrip, but for the time axis we can now simply specify a vector with the window centers instead of a window size and overlap.+This plot is an //average// spectrogram over 115 trials, with time 0 corresponding to the time of nosepoking into the reward receptacle. As with the examples using ''​spectrogram()'',​ we can control the smoothness of the spectrogram by specifying the time and frequency steps. For the frequency steps this is accomplished the same way in FieldTrip, but for the time axis we can now simply specify a vector with the window centers instead of a window size and overlap.
  
 Looking at the results, it appears there are some beta (~20Hz) and gamma events visible in the average spectrogram. Looking at the results, it appears there are some beta (~20Hz) and gamma events visible in the average spectrogram.
  
-☛ Change the ''​cfg.toi''​ and ''​cfg.foi''​ parameters to verify you can change the resolution of the time and frequency axes. What happens if you try to extend the time axis from -2 to 5?+☛ Change the ''​cfg.toi''​ and ''​cfg.foi''​ parameters to verify you can change the resolution of the time and frequency axes. What happens if you try to extend the time axis from -2 to 5? What would you do if you wanted data for that extended range?
  
 === Options and parameters for FieldTrip spectrograms === === Options and parameters for FieldTrip spectrograms ===
Line 383: Line 375:
 You should now have a beautiful image that balances time and frequency resolution: You should now have a beautiful image that balances time and frequency resolution:
  
-{{ :analysis:course:week6_fig5.png?600 |}}+{{ :analysis:nsb2014:ft_specgram2.png?600 |}}
  
 ☛ What causes the whitespace at the bottom of the image? ☛ What causes the whitespace at the bottom of the image?
Line 405: Line 397:
 cfg.t_ftimwin ​   = 20./​cfg.foi; ​ % 20 cycles per time window cfg.t_ftimwin ​   = 20./​cfg.foi; ​ % 20 cycles per time window
  
-cfg.toi ​         = -2:0.05:0; % pre-nosepoke baseline+cfg.toi ​         = -1:0.05:0; % pre-nosepoke baseline
 TFR_pre = ft_freqanalysis(cfg,​ data_trl); TFR_pre = ft_freqanalysis(cfg,​ data_trl);
  
-cfg.toi ​         = 0:0.05:2; % post-nosepoke+cfg.toi ​         = 0:0.05:1; % post-nosepoke
 TFR_post = ft_freqanalysis(cfg,​ data_trl); TFR_post = ft_freqanalysis(cfg,​ data_trl);
  
Line 451: Line 443:
  
 <code matlab> <code matlab>
 +%% load the data
 fc = FindFiles('​*.ncs'​);​ % get filenames of all LFPs recorded fc = FindFiles('​*.ncs'​);​ % get filenames of all LFPs recorded
 data = ft_read_neuralynx_interp(fc);​ % load them all -- this will take a while data = ft_read_neuralynx_interp(fc);​ % load them all -- this will take a while
 +data_all.hdr.Fs = data_all.fsample;​ % for some reason this is missing from the header
  
-% define layout+%% define layout ​for later plotting
 cfg = []; cfg = [];
 cfg.layout = '​ordered';​ cfg.channel = data.label; cfg.layout = '​ordered';​ cfg.channel = data.label;
Line 465: Line 459:
  
 <code matlab> <code matlab>
 +%%
 cfg = []; cfg = [];
-cfg.trialfun ​= 'ft_trialfun_lineartracktone2'; +cfg.cat(2,​getd(evt,'​n0'​),​getd(evt,​'n1'))
-cfg.trialdef.hdr ​data.hdr+cfg.mode '​nlx'​
-cfg.trialdef.pre ​2.5+cfg.hdr data_all.hdr
-cfg.trialdef.post ​5;+cfg.twin [-1 4];
  
-cfg.trialdef.eventtype ​'​nosepoke';​ % could be '​nosepoke',​ '​reward',​ '​cue'​ +trl ft_maketrl(cfg);
-cfg.trialdef.location = '​both';​ % could be '​left',​ '​right',​ '​both'​ +
-cfg.trialdef.block = '​both';​ % could be '​value',​ '​risk'​ +
-cfg.trialdef.cue = {'​c1','​c3','​c5'​}% cell array with choice of elements {'​c1','​c3','​c5','​lo','​hi'​}+
  
-[trl, event= ft_trialfun_lineartracktone2(cfg);+cfg = [];
 cfg.trl = trl; cfg.trl = trl;
- +data_trl = ft_redefinetrial(cfg,​data_all); 
-data_trl = ft_redefinetrial(cfg,​data);+
  
 %% %%
-cfg              = [];+cfg              = []; % start with empty cfg
 cfg.output ​      = '​pow';​ cfg.output ​      = '​pow';​
-%cfg.channel ​     = '​R016-2012-10-03-CSC04a';​ 
 cfg.method ​      = '​mtmconvol';​ cfg.method ​      = '​mtmconvol';​
 cfg.taper ​       = '​hanning';​ cfg.taper ​       = '​hanning';​
-cfg.foi ​         = 1:1:100; +cfg.foi ​         = 1:​100; ​% frequencies of interest 
-cfg.keeptrials ​'​yes';​ % should be needed for subsequent statistics... +cfg.toi          ​-0.5:0.05:3.5; % times of interest 
-cfg.t_ftimwin ​   = 20./cfg.foi;  % 20 cycles per time window +cfg.t_ftimwin = 20./​cfg.foi;​ 
-cfg.toi ​         = -1:0.05:4+ 
 TFR = ft_freqanalysis(cfg,​ data_trl); TFR = ft_freqanalysis(cfg,​ data_trl);
 </​code>​ </​code>​
Line 509: Line 498:
 You should get: You should get:
  
-{{ :analysis:course:week6_fig6.png?600 |}}+{{ :analysis:nsb2014:ft_specgram3.png?600 |}}
  
 This shows the baseline-corrected,​ event-aligned spectrograms for all 16 channels in this session. There is also an average shown (the subplot on the lower right). Note that a subset of the channels, presumably located in the ventral striatum, show a very similar time-frequency pattern, whereas another subset do not show this at all. The channels that do not show this same pattern are likely located in the hippocampus. This shows the baseline-corrected,​ event-aligned spectrograms for all 16 channels in this session. There is also an average shown (the subplot on the lower right). Note that a subset of the channels, presumably located in the ventral striatum, show a very similar time-frequency pattern, whereas another subset do not show this at all. The channels that do not show this same pattern are likely located in the hippocampus.
- +==== Exercise ​====
-==== Assignment ​====+
  
 Because the event-triggered spectrograms above show an average over trials, it is possible to lose touch with the properties of the raw data that generated it. For instance, the average may arise from a distribution of very similar looking individual trials, or it may be dominated by one atypical but extreme trial. For this reason it is important to compare the spectrogram to the raw data. Because the event-triggered spectrograms above show an average over trials, it is possible to lose touch with the properties of the raw data that generated it. For instance, the average may arise from a distribution of very similar looking individual trials, or it may be dominated by one atypical but extreme trial. For this reason it is important to compare the spectrogram to the raw data.
Line 519: Line 507:
 An example of a study where this was done well is [[http://​www.ncbi.nlm.nih.gov/​pmc/​articles/​PMC3463873/​ | Leventhal et al]]. Neuron 2012. [[http://​www.ncbi.nlm.nih.gov/​pmc/​articles/​PMC3463873/​figure/​F3/​ | Figure 3]] in this paper shows a number of event-triggered LFP traces, one for each trial. An example of a study where this was done well is [[http://​www.ncbi.nlm.nih.gov/​pmc/​articles/​PMC3463873/​ | Leventhal et al]]. Neuron 2012. [[http://​www.ncbi.nlm.nih.gov/​pmc/​articles/​PMC3463873/​figure/​F3/​ | Figure 3]] in this paper shows a number of event-triggered LFP traces, one for each trial.
  
-☛ Implement a function eventLFPplot(csc,​event_times,​varargin) to make such a plot, as follows: +☛ Implement a function eventLFPplot(cfg,csc) to make such a plot. The ''​cfg''​ variable should contain an ''​eventTimes''​ field which is requiredand optionally accept a ''​window''​ field to override the default ​window ​of [-1 3] seconds relative ​to the event times.
- +
-<code matlab>​ +
-% function eventLFPplot(csc,​event_times,​varargin) +
-+
-% INPUTS +
-+
-% csc: [1 x 1] mytsd, LFP signal ​to be plotted +
-% event_times:​ [nEvents x 1] double with event times to align LFP on +
-+
-% varargins (with defaults):​ +
-+
-% t_window: [2 x 1] double indicating time window ​to use, e.g. [-1 3] for 1 second before ​to 3 seconds after event times +
- +
-</​code>​+
  
 You can use a skeleton like the following: You can use a skeleton like the following:
analysis/nsb2014/week8.1406899001.txt.gz · Last modified: 2018/07/07 10:19 (external edit)