This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
analysis:nsb2014:week8 [2014/08/01 10:17] mvdm [Constructing the event-triggered spectrogram] |
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 379: | 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 401: | 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 447: | 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 461: | Line 459: | ||
<code matlab> | <code matlab> | ||
+ | %% | ||
cfg = []; | cfg = []; | ||
- | cfg.trialfun = 'ft_trialfun_lineartracktone2'; | + | cfg.t = 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 505: | 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 515: | 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 required, and 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: |