Back to the main page.

Bug 1868 - Wrong determination of Sampling Frequency leads to error in Morlet Wave

Reported 2012-12-03 16:47:00 +0100
Modified 2013-01-17 10:34:21 +0100
Product: FieldTrip
Component: specest
Version: unspecified
Hardware: PC
Operating System: Linux
Importance: P3 major
Assigned to: Roemer van der Meij
Depends on:
See also:

Joaquín Morís - 2012-12-03 16:47:11 +0100

When trying to use ft_freqanalysis with a Morlet wavelet, I get an error indicating that the padding is incorrect in ft_specest_wavelet.m. Checking the the error, I found the following lines of code (58-65), including the one in which the error appeared (64). % Determine fsample and set total time-length of data fsample = 1./mean(diff(time)); dattime = ndatsample / fsample; % total time in seconds of input data % Zero padding if round(pad * fsample) < ndatsample error('the padding that you specified is shorter than the data'); end Unless I'm wrong, this seems to be incorrect, this code calculates the mean time difference between data points (mean(diff(time))) but then divides 1 instead of 1000 between that mean difference. To work correctly, the following code should be used: % Determine fsample and set total time-length of data fsample = 1000./mean(diff(time)); It would be even better to use the fsample information generated previously and available in the cfg to prevent possible errors. Fieldtrip - 20121129

Roemer van der Meij - 2012-12-04 10:50:22 +0100

Hi Joaquin, Thanks for joining our bugzilla system! In our code, sampling rate is defined as 1 over the difference between time-points in seconds. Using 1000 instead of 1 would be the case if you would specify your time-axis in milliseconds instead of seconds. In fieldtrip, we chose to specify it in seconds. Padding, when using either ft_freqanalysis or ft_specest_wavelet in itself, is also defined in seconds. More specifically, cfg.padding refers to the total length in seconds of the data+padding. Possibly, you incorrectly specified cfg.padding to the amount that you want to be added, instead of the total (a common mistake when using cfg.padding). Is this correct? If not, could you attach to this bug report an m-file containing the settings you used and a (preferable small) bit of data that replicates the error?

Joaquín Morís - 2012-12-04 12:33:34 +0100

(In reply to comment #1) Hi Roemer, You are absolutely right, I'm sorry for my mistake. Thanks for your quick response!

Roemer van der Meij - 2013-01-17 10:34:21 +0100

bug closing time