[FieldTrip] freqanalysis

"Jörn M. Horschig" jm.horschig at donders.ru.nl
Wed Feb 5 12:49:38 CET 2014


Hi Victoria,

see: 
http://fieldtrip.fcdonders.nl/faq/why_does_my_tfr_contain_nans?s[]=tfr&s[]=nan
and: http://fieldtrip.fcdonders.nl/walkthrough#frequency_analysis

These should answer your question ;)

Best,
Jörn

  On 2/5/2014 12:40 PM, Victoria Schröder wrote:
> Dear Jörn,
>
> I still am dealing with finding the right cfg.toi when doing a time 
> frequency analysis. Depending on the time resolution i get NaN values 
> in the first matrixes in the resulting powspctrm and crsspctrm.  It 
> seems that for the first times selected there is no data. If i choose 
> a cfg.toi 1:0.05:2 then i get no Nan values but as soon as I start 
> below 1 i get Nan values.
>
> This is my code for the analysis. I would appreciate some concrete 
> advice and suggestions why i run into this problem.
>
> % time-frequency analysis
> cfg              = [];
> cfg.output       = 'powandcsd';  % different for convol than for fft
> cfg.channel={'C15' 'C10' 'B23' 'B3'};
> cfg.method       = 'mtmconvol';
> cfg.taper        = 'hanning';
> cfg.keeptrials = 'yes';
> cfg.trials=data_clean.trialinfo(:,1) < 20;
> cfg.channel={'C29' 'C16' 'C31' 'C9' 'C26' 'C13' 'D23' 'B26' 'D29' 
> 'B13' 'D31' 'B11'};
> cfg.channelcmb={'C29' 'D23'
>                 'C29' 'D31'
>                 'C29' 'D29'
>                 'C31' 'D23'
>                 'C31' 'D31'
>                 'C31' 'D29'
>                 'C26' 'D23'
>                 'C26' 'D31'
>                 'C26' 'D29'
>                 'C16' 'B26'
>                 'C16' 'B11'
>                 'C16' 'B13'
>                 'C13' 'B26'
>                 'C13' 'B11'
>                 'C13' 'B13'
>                 'C9'  'B26'
>                 'C9'  'B11'
>                 'C9'  'B13'} ;
> cfg.foi          = 12:2:30;  % analysis 2 to 30 Hz in steps of 2 Hz
> cfg.t_ftimwin    = ones(length(cfg.foi),1).*0.5;   % length of time 
> window = 0.5 sec
> cfg.toi = 0:0.05:1;
> freq_convol = ft_freqanalysis(cfg, data_clean);
>
> Thank you a lot
> Victoria
>
>
> 2014-02-03 13:40 skrev Jörn M. Horschig:
>> Hi Victoria,
>>
>> On 2/3/2014 12:14 PM, Victoria Schröder wrote:
>>> Thank Jörn,
>>>
>>> Thank for the advice for the tutorials but i have already looked at 
>>> them a lot.
>>>
>>> Anyhow, suppose i say cfg.keeptrials = 'yes', then i get the 
>>> averaged power over trials? Well, it might sound obvious, but if you 
>>> say 'yes' to keep trials, you keep the trials, whereas if you say 
>>> 'no' you do not keep the trials and instead get an average.
>>
>>> what happens then when the trials do not have the same length?
>> The average will be made with all data that is available. If some
>> trials go to 30s but all trials go to 29s, then the average of the
>> last one second is made of less data then the first 29s. This is a
>> crucial point for doing statistics as the degrees of freedom,
>> signal-to noise ration etc. will be different for different time
>> points.
>>
>>>
>>> and a last question :)
>>>
>>> what does cfg.toi  depend on ? in the tutorial time frequency 
>>> analysis this is chosen : cfg.toi          = -0.5:0.05:1.5; .. why 
>>> is that the case?
>> it depends on what time you are interested in and how much memory
>> (and cpu time aka patience) you got.
>>
>> Good luck ;)
>> Best,
>> Jörn
>>
>>>
>>> I hope this should be it for now
>>> Best
>>> Victoria
>>>
>>>
>>> 2014-02-03 11:42 skrev Jörn M. Horschig:
>>>> Hi Victoria,
>>>>
>>>> you might want to read the relevant part of the walkthrough for your
>>>> questions on mtmconvol and mtmfft:
>>>> http://fieldtrip.fcdonders.nl/walkthrough#frequency_analysis
>>>>
>>>> Then, also doing this tutorial might help in understanding what the
>>>> different methods are doing:
>>>> http://fieldtrip.fcdonders.nl/tutorial/timefrequencyanalysis
>>>>
>>>> And lastly, to shortly answer your questions, see below ;)
>>>>
>>>> On 2/3/2014 11:15 AM, Victoria Schröder wrote:
>>>>> Dear Jörn,
>>>> Hi ;)
>>>>
>>>>>
>>>>> the code works but i dont know whether my data is logical and 
>>>>> whether i decided to use the right method etc.
>>>> maybe you should try to get into one of the FieldTrip courses :) This
>>>> might tremendously help you in understanding what's being done and
>>>> why. Otherwise, try to read as much as you can, read methods of papers
>>>> and discuss with your supervisor and colleagues. Of course, on the
>>>> mailing list we also like to help a lot.
>>>>>
>>>>> My trials are pretty long (approx 30 sec but all are not the same 
>>>>> length) and i am interested in beta frequency.
>>>>>
>>>>> First, it is not really clear to me whether i should use 
>>>>> cfg.method=mtmfft or cfg.method=mtmconvol. As i understand , the 
>>>>> latter calculates the FFT for shorter self-specified time windows 
>>>>> to look at changes in power over time. Is that right? yep, about 
>>>>> right.
>>>>
>>>>> however, if i have more stimuli for one condition, how is the time 
>>>>> component then taken into account? it depends on how you segmented 
>>>>> your data. FieldTrip is just transforming your preprocessed data, 
>>>>> so whatever you put in is what you get out.
>>>>
>>>>> does mtmconvol take all trials of one condition and average the 
>>>>> the power for each time window over all trials? Or is each trial 
>>>>> treated seperatly?
>>>> depends on whether you specify cfg.keeptrials = 'yes' or 'no'
>>>>>
>>>>> Say i would use cfg.method=mtmfft do i need to specify a 
>>>>> cfg.tapsmofrq when using cfg.taper='hanning'? no, a hanning taper 
>>>>> is always a single taper. Only when combining multiple tapers you 
>>>>> can effectively smooth in the frequency domain. this is 
>>>>> implemented as taper='dpss'
>>>>
>>>>> As i understand hanning if appropriate for lower freuquencies so i 
>>>>> should use this taper to assess beta frequencies.
>>>> this is a rule of thumb, but there is nothing wrong with using
>>>> multitapering for lower frequencies. It depends on what you expect
>>>> from your data and what you want to achieve.
>>>>>
>>>>> Say i use cfg.method=mtmconvol what cfg.t_ftimwin is appropriate?
>>>> this depends on the frequencies you are interested in. I wouldn't
>>>> trust anything below 3 cycles, i.e. for 10Hz alpha at least 300ms.
>>>>
>>>>>
>>>>> Thank you a lot for the help
>>>> you're welcome, hope this helps
>>>>> Best
>>>>> Victoria
>>>> Likewise,
>>>> Jörn
>>>>
>>>>>
>>>>>
>>>>> 2014-02-03 09:19 skrev Jörn M. Horschig:
>>>>>> Hi Victoria,
>>>>>>
>>>>>> is there anything wrong with the code you used below? By smoothing,
>>>>>> do you refer to smoothing in the frequency domain?
>>>>>>
>>>>>> Best,
>>>>>> Jörn
>>>>>>
>>>>>>
>>>>>> On 1/30/2014 11:33 AM, Victoria Schröder wrote:
>>>>>>> Hello
>>>>>>>
>>>>>>> I am currently working on a freqanalysis as a first step to do a 
>>>>>>> connectivityanalysis. I am a bit unsure about the method to use 
>>>>>>> for the freqanalysis. My stimuli are very long: between 29 and 
>>>>>>> 30 sec. In total i have 4 stimuli per condition and 2 seperate 
>>>>>>> conditions. I am looking at the beta range so fairly low 
>>>>>>> frequencies.
>>>>>>>
>>>>>>> this is my code:
>>>>>>> Am i using the right taper and method. Should i smooth the data? 
>>>>>>> and if so, what should such a smoothing parameter depend on?
>>>>>>>
>>>>>>> %fourier analysis
>>>>>>> cfg=[];
>>>>>>> cfg.output='fourier';
>>>>>>> cfg.method='mtmfft';
>>>>>>> cfg.foi=[12:30];
>>>>>>> cfg.taper='hanning';
>>>>>>> cfg.keeptrials='yes';
>>>>>>> cfg.channel={'C15' 'C10' 'B23' 'B3'};
>>>>>>> frefourier=ft_freqanalysis(cfg,data_clean);
>>>>>>>
>>>>>>>
>>>>>>> %coherence analysis
>>>>>>> cfg=[];
>>>>>>> cfg.method='coh';
>>>>>>> cfg.channelcmb={'B3'  'C15'
>>>>>>>                 'B3'  'C10'
>>>>>>>                 'B23' 'C15'
>>>>>>>                 'B23' 'C10'}
>>>>>>> coherence=ft_connectivityanalysis(cfg, frefourier);
>>>>>>>
>>>>>>>
>>>>>>> Thank you very much for the suggestions!
>>>>>>> Best
>>>>>>> Victoria
>>>>>>> _______________________________________________
>>>>>>> fieldtrip mailing list
>>>>>>> fieldtrip at donders.ru.nl
>>>>>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>>>
>>>>>>
>>>>>> -- Jörn M. Horschig
>>>>>> PhD Student
>>>>>> Donders Institute for Brain, Cognition and Behaviour
>>>>>> Centre for Cognitive Neuroimaging
>>>>>> Radboud University Nijmegen
>>>>>> Neuronal Oscillations Group
>>>>>> FieldTrip Development Team
>>>>>>
>>>>>> P.O. Box 9101
>>>>>> NL-6500 HB Nijmegen
>>>>>> The Netherlands
>>>>>>
>>>>>> Contact:
>>>>>> E-Mail: jm.horschig at donders.ru.nl
>>>>>> Tel:    +31-(0)24-36-68493
>>>>>> Web: http://www.ru.nl/donders
>>>>>>
>>>>>> Visiting address:
>>>>>> Trigon, room 2.30
>>>>>> Kapittelweg 29
>>>>>> NL-6525 EN Nijmegen
>>>>>> The Netherlands
>>>>>>
>>>>>> _______________________________________________
>>>>>> fieldtrip mailing list
>>>>>> fieldtrip at donders.ru.nl
>>>>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>>>
>>>>
>>>>
>>>> -- Jörn M. Horschig
>>>> PhD Student
>>>> Donders Institute for Brain, Cognition and Behaviour
>>>> Centre for Cognitive Neuroimaging
>>>> Radboud University Nijmegen
>>>> Neuronal Oscillations Group
>>>> FieldTrip Development Team
>>>>
>>>> P.O. Box 9101
>>>> NL-6500 HB Nijmegen
>>>> The Netherlands
>>>>
>>>> Contact:
>>>> E-Mail: jm.horschig at donders.ru.nl
>>>> Tel:    +31-(0)24-36-68493
>>>> Web: http://www.ru.nl/donders
>>>>
>>>> Visiting address:
>>>> Trigon, room 2.30
>>>> Kapittelweg 29
>>>> NL-6525 EN Nijmegen
>>>> The Netherlands
>>>>
>>>> _______________________________________________
>>>> fieldtrip mailing list
>>>> fieldtrip at donders.ru.nl
>>>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>>
>>
>>
>> -- 
>> Jörn M. Horschig
>> PhD Student
>> Donders Institute for Brain, Cognition and Behaviour
>> Centre for Cognitive Neuroimaging
>> Radboud University Nijmegen
>> Neuronal Oscillations Group
>> FieldTrip Development Team
>>
>> P.O. Box 9101
>> NL-6500 HB Nijmegen
>> The Netherlands
>>
>> Contact:
>> E-Mail: jm.horschig at donders.ru.nl
>> Tel:    +31-(0)24-36-68493
>> Web: http://www.ru.nl/donders
>>
>> Visiting address:
>> Trigon, room 2.30
>> Kapittelweg 29
>> NL-6525 EN Nijmegen
>> The Netherlands
>>
>> _______________________________________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>


-- 
Jörn M. Horschig
PhD Student
Donders Institute for Brain, Cognition and Behaviour
Centre for Cognitive Neuroimaging
Radboud University Nijmegen
Neuronal Oscillations Group
FieldTrip Development Team

P.O. Box 9101
NL-6500 HB Nijmegen
The Netherlands

Contact:
E-Mail: jm.horschig at donders.ru.nl
Tel:    +31-(0)24-36-68493
Web: http://www.ru.nl/donders

Visiting address:
Trigon, room 2.30
Kapittelweg 29
NL-6525 EN Nijmegen
The Netherlands




More information about the fieldtrip mailing list