# length of freq vector in freqanalysis

Jan Mathijs Schoffelen jan.schoffelen at FCDONDERS.RU.NL
Tue Apr 10 20:58:41 CEST 2007

```Dear Sameer,

Your questions are related to some fundamental aspects of fourier-analysis. In general: the length of your data determines the frequency-resolution of the powerspectrum calculated from it.
For a good introduction on fourier-analysis you could have a look at www.dspguide.com.

Regarding your question about multiplotER: apparently the function expects two data-structures with the same frequency-axis. This can be achieved with zero-padding. You can specify cfg.pad before calling freqanalysis (for a good introduction on zero-padding: see www.dspguide.com I think). If you take this cfg.pad equal for the freqanalysis on data_pre and data_post (it should be >= the longest trials you have, so in your specific case >= 0.5 (it is defined in seconds)), the frequency axes come out identical and I expect multiplotER to behave itself.

By the way: cfg.tapsmofrq should be an integer multiple of the frequency-resolution of your data, i.e. an integer multiple of 1./(data-length [this includes the padding if you are comparing data with different length])

Yours,

Jan-Mathijs

----- Original Message -----
From: Sameer Walawalkar <sameer at ANDREW.CMU.EDU>
Date: Tuesday, April 10, 2007 6:40 pm
Subject: [FIELDTRIP] length of freq vector in freqanalysis

> Hello,
>
> I find that freqanalysis  (cfg.method = mtmfft) generates two
> different
> .freq vectors (different lengths, but spanning the correct [min
> max] as
> indicated by cfg.foilim) for two different datasets passed with
> same cfg
> (but one dataset has more time points than the other).
>
> Plotting the power spectra of the two datasets simultaneously using
> singleplotER works just fine, but multiplotER  shows one spectrum
> spanning
> smaller range than the other. Funnily, it is the frequency
> distribution
> with the larger .freq vector which is graphed smaller.
>
> Is there some way I can specify not only the frequency range but
> also the
> number of frequency points to be generated?
>
> The details are given below.
>
> 1> re: freqanalysis
> I use the same cfg structure (given below) to pass two datasets to
> freqanalysis. Yet the frequency vectors for each dataset has very
> different lengths.  I wonder if the different time lengths of each
> set
> make a difference.
>
> cfg = [];
> cfg.ouput='powandcsd';
> cfg.method='mtmfft';
> cfg.keeptrials='no';
> cfg.tapsmofrq=4;
> cfg.foilim =[30 90];
> cfg.channel = 'MEG'  ;
> cfg.channelcmb = {'MEG' 'MEG'};
>
>
> pre1 = -.300  ;
> pre2 = -.100 ;
> post1 = .000 ;
> post2 = .500 ;
> (this line tells my defined function Breakdata to pass on only data
> between times 300msec  to 100 msec before event and from event to
> 500 msec
> after.
>
>         [data_pre, data_post]  = Breakdata(data, pre1, pre2,
> post1, post2)
>         freq_pre = freqanalysis(cfg,data_pre);
>         freq_post = freqanalysis(cfg,data_post);
>
>         fd_pre = freqdescriptives([], freq_pre)
>         fd_post = freqdescriptives([], freq_post)
>
> In the above line Breakdata is a function I have written (I know I
> could
> use TFRs to do the same, but I had already written the function and
> have
> not yet had time to consider the other option).
>
> Now, my question is,
> >> size(freq_pre.freq)
>
> ans =
>
>      1    13
>
> >> size(freq_post.freq)
>
> ans =
>
> 1	31
>
> Why the difference? (they do however span the interval [30 90].).
> Needless to mention, fd_pre and fd_post are also effected.
>
> 2>re: multiplot.
> I use
> cfg = [];
> cfg.xparam = 'freq';
> cfg.zparam = 'cohspctrm';
> cfg.zlim = [0 1e-27];
> cfg.channel = 'all';
> cfg.cohrefchannel = 'MEG1833';
> cfg.layout = 'NM306mag.lay';
> multiplotER(cfg, fd_pre,fd_post)
>
> I would expect the plotting would not be affected as both datasets
> have
> their frequency vector noted for the x-axis. Yet, the graph of the
> first
> dataset is 1/3rd as long on the plot.
>
> How can I fix this? (Incidently, singleplotER works fine for the
> power
> spectrum ).
>
> Thanks for your help.
>
> Best,
> sameer
>
>

```