[FieldTrip] Wavelet and time-frequency plot

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Sun Sep 4 09:25:27 CEST 2016

Dear Bahar,

Perhaps you should first acquaint yourself a bit more with some of the basics of spectral analysis, and with some of the details of what the consequences are of specific choices about cfg-options that you specify before calling the function. Although you provide too few details to be sure, I suspect that you have a single stretch of data (sampled at 30K), i.e. a single trial, and I assume this to be of a certain length. If you want to create a single time-frequency spectrum, without epoching (again, I assume that this is what you want to do), this can become quite memory consuming, even when only considering the amount of memory it takes to store the results. In your case, you ask in cfg.toi to return an estimate of power for each time point in your original data. This is certainly an overkill, due to the temporal smoothness of the estimates. As a consequence, with 30.000 samples per second, and (e.g.) 15 minutes of recording each frequency’s time cours will have 27.000.000 samples. Since MATLAB needs 16 bytes for each complex-valued double precision number, this will eat up 432MB of memory. Per channel and per frequency…
Next, not specifying the frequency range, will cause FieldTrip to compute and return all frequencies, from 0 until the Nyquist frequency, which is 15.000 Hz in your case. Now, if you indeed have 15 minutes of recording, this gives you a spectral resolution of 1/900 Hz, i.e. 900 frequency estimates per Hz. This all amounts to 1350000 frequency bins to be estimated. I can imagine that computers may choke on this.

I suggest to do the following:

1) resample your data to a lower sampling rate, using ft_resampledata. If you go down to 2 or 4 kHz, no information is lost for the time being (at least not if you want to look up until 500 Hz).
2) ask for more reasonable parameters, e.g. cfg.toi = data.time{1}(1):0.1:data.time{1}(end); cfg.foi = 0:5:500;
3) think about the cfg.width parameter, and think twice whether you would want to use the ‘wavelet’ method, rather than ‘mtmconvol’, which gives you more control about the temporal integration window. Note that a width parameter of e.g. 5 (a typical, i think even the default, value) leads to the wavelet to be ~10 ms wide at 500 Hz, which may be a bit short.

Best and good luck,


On 02 Sep 2016, at 21:45, Bahareh Elahian (belahian) <belahian at memphis.edu<mailto:belahian at memphis.edu>> wrote:

Hi All,
I am asking this question again since I tried on our HPC server, and still I need more memory for computation.
Do you have any idea how can I plot my signal in time-frequency?
I wrote down the detail in my following post.


Hello All,
I am trying to apply wavelet on my signal to see HFOs in time-frequency plot.
The sampling rate of my signal is 30K.
I will get an error: "
Error using fft
Out of memory. Type HELP MEMORY for your options.

here is what I wrote according to http://www.fieldtriptoolbox.org/reference/ft_freqanalysis:

reference:ft_freqanalysis – FieldTrip<http://www.fieldtriptoolbox.org/reference/ft_freqanalysis>
Note that this reference documentation is identical to the help that is displayed in MATLAB when you type “help ft_freqanalysis”. FT_FREQANALYSIS performs ...


reference:ft_freqanalysis – FieldTrip<http://www.fieldtriptoolbox.org/reference/ft_freqanalysis>
Note that this reference documentation is identical to the help that is displayed in MATLAB when you type “help ft_freqanalysis”. FT_FREQANALYSIS performs ...

cfg= [];

cfg.pad = 'maxperlen';
cfg.method = 'wavelet';
cfg.output = 'pow';
%cfg.channel = 'chan 4';
 cfg.toi = (1:size(eeg.eeg_data,2))/Fs;
% cfg.foilim  = [80 500];
[freq] = ft_freqanalysis(cfg, data1);

Do you have any idea? is it realted to my sampling rate?
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20160904/07a60cba/attachment-0002.html>

More information about the fieldtrip mailing list