[FieldTrip] Wavelet and time-frequency plot

Bahareh Elahian (belahian) belahian at memphis.edu
Mon Sep 5 18:59:57 CEST 2016

Thanks for your complete answer.

Yes . I have one trial and 8 channels.

I have changed the code as following and I got the [freq] structure.

% Resample Data
cfg = [];
cfg.resamplefs = 4;
cfg.detrend = 'No';
cfg.trials = 'all';
[data_resam] = ft_resampledata(cfg, data1);
 %% wavelet
cfg= [];
cfg.pad = 'maxperlen';
cfg.method = 'wavelet';
cfg.output = 'pow';
cfg.toi = data_resam.time{1}(1):0.1:data_resam.time{1}(end);
cfg.foi = 0:5:500;
[freq] = ft_freqanalysis(cfg, data_resam);

The problem here is that the freq.powspctrm is a 3 dimentional matrix which I beleive it should be a 2 dimensional.

The dimension is (8*100*1380).

In online tutorials, I found the other examples that the freq.powspctrm had 2 dimensional.

Do you know where is the problem (if there is any)?



From: fieldtrip-bounces at science.ru.nl <fieldtrip-bounces at science.ru.nl> on behalf of Schoffelen, J.M. (Jan Mathijs) <jan.schoffelen at donders.ru.nl>
Sent: Sunday, September 4, 2016 2:25:27 AM
To: FieldTrip discussion list
Subject: Re: [FieldTrip] Wavelet and time-frequency plot

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/20160905/e5b6dfa0/attachment-0002.html>

More information about the fieldtrip mailing list