[FieldTrip] wavelet fourier output produces sign inverted imaginary part
Björn Herrmann
bherrmann at cbs.mpg.de
Fri Nov 2 10:10:16 CET 2012
Dear fieldtrip users,
I observed something strange using ft_freqanalysis with the "wavelet" method that might be important for many/some of you.
It seems that the imaginary part of the fourier output (from "wavelet") is sign inverted for the TFR calculated for more than one frequency at once (i.e. cfg.foi = [4 5]) as compared to the TFR calculated independently for the frequencies (i.e., first cfg.foi = 4, and then cfg.foi = 5). This impacts the phase angle which is backwards in case of calculating the TFR for more frequencies in one go. amplitude/power is unaffected and it seems also ITPC calculations. momentary phase and therefore some phase-amplitude coupling measures are, however, affected by this. I attached a bit of code showing the difference:
Cf = 5;
Sf = 500;
dur = 20;
freqs = 1:10;
cfg = [];
cfg.method = 'wavelet';
cfg.output = 'fourier';
cfg.width = 3;
cfg.toi = 0:0.01:dur;
t = 0:1/Sf:(dur-1/Sf);
data = [];
data.avg = sin(2*pi*Cf*t+1.1);
data.fsample = Sf;
data.time = t;
data.label = {'channel'};
data.dimord = 'chan_time';
floop = [];
for ii = 1 : length(freqs)
cfg.foi = freqs(ii);
F = ft_freqanalysis(cfg, data);
floop(:,ii) = squeeze(F.fourierspctrm);
end
cfg.foi = freqs;
F = ft_freqanalysis(cfg, data);
fonego = squeeze(F.fourierspctrm)';
[real(floop(1000,1)), real(fonego(1000,1)); ...
imag(floop(1000,1)), imag(fonego(1000,1)); ...
angle(floop(1000,1)), angle(fonego(1000,1))]
ans =
-0.0128 -0.0128
0.0067 -0.0067
2.6605 -2.6605
I thought this might be important for some of you, independently of a bug report i'll try to send later (i have to figure out how this works first). My colleagues and I were unable to fix the problem in the fieldtrip script directly, but a simple solution is to do the following: real(fourier)+(imag(fourier)*-1)*1i
Based on some tests i did, I believe the fonego is the wrong one (i.e. using cfg.foi = [4 5]).
All the best,
Björn
More information about the fieldtrip
mailing list