Skip to content

Commit

Permalink
rephrased some parts of the help - see #2028
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoostenveld committed May 17, 2022
1 parent da934af commit c607aec
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions ft_resampledata.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
%
% The data should be organised in a structure as obtained from the FT_PREPROCESSING
% function. The configuration should contain
% cfg.resamplefs = frequency at which the data will be resampled (default = 256 Hz)
% cfg.resamplefs = frequency at which the data will be resampled
% cfg.detrend = 'no' or 'yes', detrend the data prior to resampling (no default specified, see below)
% cfg.demean = 'no' or 'yes', whether to apply baseline correction (default = 'no')
% cfg.baselinewindow = [begin end] in seconds, the default is the complete trial (default = 'all')
Expand All @@ -23,25 +23,22 @@
% cfg.method = interpolation method, see INTERP1 (default = 'pchip')
% cfg.extrapval = extrapolation behaviour, scalar value or 'extrap' (default = as in INTERP1)
%
% Note, that depending on the selected method, an implicit anti-aliasing low pass filter is applied, prior
% to the resampling. This is only the case for the method 'resample'. Optionally, an explicit anti-aliasing
% low pass filter can be specified. This may be useful if the requested output sampling rate is lower than
% the sampling rate of the input data, and if a method is used that does not apply a low pass filter
% under the hood, i.e. for any method other than 'resample', or if strong signal components are present in the
% bandwidth that is close to the new Nyquist frequency.
% When you specify cfg.method='resample' an implicit anti-aliasing low pass filter is applied prior
% to the resampling. You can also explicitly specify an anti-aliasing low pass filter. This is adviced
% when downsampling using any other method than 'resample', but also when strong noise components are
% present just above the new Nyquist frequency.
% cfg.lpfilter = 'yes' or 'no' (default = 'no')
% cfg.lpfreq = scalar value for low pass frequency (there is no default, so needs to be always specified)
% cfg.lpfilttype = string, filter type (default is set in ft_preproc_lowpassfilter)
% cfg.lpfiltord = scalar, filter order (default is set in ft_preproc_lowpassfilter)
%
% More documentation about anti alias filtering can be found in this <a href="matlab:
% More documentation about anti-alias filtering can be found in this <a href="matlab:
% web('https://www.fieldtriptoolbox.org/faq/resampling_lowpassfilter')">FAQ</a> on the FieldTrip website.
%
% Previously this function used to detrend the data by default. The motivation for this is that the data
% is filtered prior to resampling to avoid aliassing and detrending prevents occasional edge artifacts of
% the filters. Detrending is fine for removing slow drifts in data prior to frequency analysis, but not good
% if you subsequently want to look at the evoked fields. Therefore the old default value 'yes' has been
% removed and you now explicitly have to specify whether you want to detrend.
% Previously this function used to detrend the data by default to avoid edge artifacts fue to the
% anti-aliassing filter. Detrending is fine for removing slow drifts in data prior to frequency analysis,
% but not recommended if you want to look at ERPs or ERFs. Therefore the old default value 'yes' has been
% removed; you now explicitly have to specify whether you want to detrend or not.
%
% To facilitate data-handling and distributed computing you can use
% cfg.inputfile = ...
Expand All @@ -51,10 +48,10 @@
% files should contain only a single variable, corresponding with the
% input/output structure.
%
% See also FT_PREPROCESSING, FT_APPENDDATA, RESAMPLE, DOWNSAMPLE, INTERP1, FT_PREPROC_LOWPASSFILTER
% See also FT_PREPROCESSING, FT_APPENDDATA, FT_PREPROC_LOWPASSFILTER, ESAMPLE, DOWNSAMPLE, INTERP1

% Copyright (C) 2003-2006, FC Donders Centre, Markus Siegel
% Copyright (C) 2004-2019, FC Donders Centre, Robert Oostenveld
% Copyright (C) 2004-2022, FC Donders Centre, Robert Oostenveld
% Copyright (C) 2022, DCCN, Jan-Mathijs Schoffelen
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
Expand Down Expand Up @@ -96,7 +93,7 @@
% ft_checkdata is done further down

% check if the input cfg is valid for this function
cfg = ft_checkconfig(cfg, 'forbidden', {'trial'}); % prevent accidental typos, see issue 1729
cfg = ft_checkconfig(cfg, 'forbidden', {'trial'}); % prevent accidental typos, see issue 1729
cfg = ft_checkconfig(cfg, 'renamed', {'blc', 'demean'});
cfg = ft_checkconfig(cfg, 'renamed', {'resamplemethod', 'method'});
cfg = ft_checkconfig(cfg, 'renamed', {'fsample', 'resamplefs'});
Expand Down Expand Up @@ -306,7 +303,7 @@
newtim = newtim( sel);
newdat = newdat(:, sel);
end

data.time{itr} = newtim;
data.trial{itr} = newdat;

Expand All @@ -327,7 +324,7 @@
cfg.extrapval = nan;
end
end

ntr = length(data.trial);

ft_progress('init', cfg.feedback, 'resampling data');
Expand Down Expand Up @@ -356,7 +353,7 @@
if istrue(cfg.lpfilter)
olddat = ft_preproc_lowpassfilter(olddat, cfg.origfs, cfg.lpfreq, cfg.lpfiltord, cfg.lpfilttype);
end

% perform the resampling
newtim = cfg.time{itr};
if length(oldtim)>1
Expand Down

0 comments on commit c607aec

Please sign in to comment.