Back to the main page.

Bug 3416 - problem in ft_channelcombination

Status NEW
Reported 2018-03-02 15:42:00 +0100
Modified 2018-03-22 08:01:27 +0100
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Linux
Importance: P5 major
Assigned to: Heidi Solberg Økland
URL:
Tags:
Depends on:
Blocks:
See also:

Heidi Solberg Økland - 2018-03-02 15:42:04 +0100

Created attachment 859 An example dataset and a script to go with it that shows the problem. Hello there. I'm working on an analysis pipeline for brain-speech coherence, and I've run into a problem that I can't seem to solve.. Bacially, I want my coherence spectrum to only contain gradiometer data, but when I try and select MEGGRAD for the channel combination I get an empty coherence spectrum... And when I try to select MEGGRAD for the FFT and either MEG or MEGGRAD for the coherence, I get the following error: Index exceeds matrix dimensions. Error in ft_channelcombination (line 173) collect = [datachannel(indx(:,1)) datachannel(indx(:,2))]; Error in ft_connectivityanalysis (line 174) cfg.channelcmb = ft_channelcombination(cfg.channelcmb, tmpchan, 1); Error in coherence_channelcmb_problem (line 68) AudCoh = ft_connectivityanalysis(cfg, FreqFourier_Aud); Help? I've attached a script with an example dataset that replicates the problems.


Heidi Solberg Økland - 2018-03-02 15:56:00 +0100

Sorry, seems I didn't attach the dataset. I've tried to add it but when I try to upload it I get an error ... This site can’t be reached The web page at http://bugzilla.fieldtriptoolbox.org/attachment.cgi might be temporarily down or it may have moved permanently to a new web address. ERR_CONNECTION_ABORTED


Jan-Mathijs Schoffelen - 2018-03-03 13:18:26 +0100

please try and upload a small dataset, that at least consists of a data.label field. Otherwise, try a bit more yourself in terms of debuggin, e.g. type dbstop if error on the command line, or put a breakpoint in ft_channelcombination at line 173, and inspect the variables 'datachannel', and 'indx'. These apparently do not match matlab's expectations.


Heidi Solberg Økland - 2018-03-16 15:20:03 +0100

Created attachment 863 Script that reproduces the error


Heidi Solberg Økland - 2018-03-16 15:31:22 +0100

Comment on attachment 863 Script that reproduces the error Just found out it doesn't run properly, will upload a new one..


Heidi Solberg Økland - 2018-03-21 13:32:32 +0100

I've tried to troubleshoot this a bit more, but am completely stuck. I've tried going back a few steps in my pipeline so as to do the splitting up into trials, trial rejection etc with gradiometer data only, but I'm still having problems. Here's an example data structure: >> Data Data = hdr: [1x1 struct] fsample: 250 grad: [1x1 struct] elec: [1x1 struct] cfg: [1x1 struct] label: {206x1 cell} trial: {1x275 cell} trialinfo: [275x1 double] time: {1x275 cell} sampleinfo: [275x2 double] Here's how my code goes: freqMin = 0.1; % Minimum frequency in Hz freqMax = 20; % Maximum frequency in Hz freqStep = 0.1; % Frequency steps in Hz Padding = 10; % Total length of signal wanted in seconds Smoothing = 0.6; % Spectral smoothing in Hz cfg = []; cfg.output = 'fourier'; % use Fourier analysis cfg.method = 'mtmfft'; % spectral smoothing using multitapers cfg.foi = freqMin:freqStep:freqMax; % from x to y Hz in steps of cfg.pad = Padding; cfg.tapsmofrq = Smoothing; % Hz - determines degree of smoothing cfg.taper = 'hanning'; cfg.keeptrials = 'yes'; cfg.trials = AudTrl'; % use auditory trials % cfg.channel = {'MEG' 'AudEnv' 'LipEnv'}; FreqFourier_Aud = ft_freqanalysis(cfg, Data); >> FreqFourier_Aud FreqFourier_Aud = label: {206x1 cell} dimord: 'rpttap_chan_freq' freq: [1x200 double] fourierspctrm: [220x206x200 double] cumsumcnt: [220x1 double] cumtapcnt: [220x1 double] elec: [1x1 struct] grad: [1x1 struct] trialinfo: [220x1 double] cfg: [1x1 struct] If don't comment out channel selection for the FFT something goes awry: >> FreqFourier_Aud FreqFourier_Aud = label: {2x1 cell} dimord: 'rpttap_chan_freq' freq: [1x200 double] fourierspctrm: [220x2x200 double] cumsumcnt: [220x1 double] cumtapcnt: [220x1 double] elec: [1x1 struct] grad: [1x1 struct] trialinfo: [220x1 double] cfg: [1x1 struct] Now it has only selected the AudEnv and LipEnv channels ... even when I asked it to do MEGGRAD as well. Very strange. The coherence code is simple: cfg = []; cfg.method = 'coh'; cfg.channelcmb = {'MEG' 'AudEnv'}; AudCoh = ft_connectivityanalysis(cfg, FreqFourier_Aud); This attempt produces the error: Attempted to access indx(:,1); index out of bounds because size(indx)=[0,0]. Error in ft_channelcombination (line 173) collect = [datachannel(indx(:,1)) datachannel(indx(:,2))]; Error in ft_connectivityanalysis (line 174) cfg.channelcmb = ft_channelcombination(cfg.channelcmb, tmpchan, 1); Error in coh_sensors_audvis_AVspeech (line 194) AudCoh = ft_connectivityanalysis(cfg, FreqFourier_Aud); If I change 'MEG' to 'MEGGRAD' I still get the same error. I've used this code previously to compute coherence, but then on data where all channels (gradiometers and magnetometers) were present. Selecting 'MEG' all the way when the data contains all the channels doesn't cause me trouble. >> AudCoh AudCoh = labelcmb: {306x2 cell} dimord: 'chancmb_freq' cohspctrm: [306x40 double] freq: [1x40 double] grad: [1x1 struct] elec: [1x1 struct] dof: 270 cfg: [1x1 struct] Help?


Jan-Mathijs Schoffelen - 2018-03-21 14:06:40 +0100

Have you checked with your supervisor and local colleagues?


Heidi Solberg Økland - 2018-03-21 17:01:47 +0100

I've just come out of a meeting with my supervisor where we discussed this. What we found out was that selecting a subset of channels for the frequency analysis causes trouble, both for that and the subsequent coherence computation. If I take my dataset with all MEG channels in it (both magnetometers and gradiometers, plus the two extra ones called AudEnv and LipEnv), and try to analyse only gradiometers, then: % FFT settings freqMin = 1; % Minimum frequency in Hz freqMax = 20; % Maximum frequency in Hz freqStep = 0.5; % Frequency steps in Hz Padding = 10; % Total length of signal wanted in seconds Smoothing = 0.6; % Spectral smoothing in Hz cfg = []; cfg.output = 'fourier'; % use Fourier analysis cfg.method = 'mtmfft'; % spectral smoothing using multitapers cfg.foi = freqMin:freqStep:freqMax; % from x to y Hz in steps of cfg.pad = Padding; cfg.tapsmofrq = Smoothing; % Hz - determines degree of smoothing cfg.taper = 'hanning'; cfg.keeptrials = 'yes'; % cfg.channel = {'MEGGRAD''AudEnv' 'LipEnv'}; cfg.channelcmb = {'MEGGRAD' 'AudEnv' 'MEGGRAD''LipEnv' }; cfg.trials = AudTrl'; % use auditory trials FreqFourier_Aud = ft_freqanalysis(cfg, Data); >> FreqFourier_Aud FreqFourier_Aud = label: {308x1 cell} dimord: 'rpttap_chan_freq' freq: [1x39 double] fourierspctrm: [220x308x39 double] cumsumcnt: [220x1 double] cumtapcnt: [220x1 double] elec: [1x1 struct] grad: [1x1 struct] trialinfo: [220x1 double] cfg: [1x1 struct] .. so here, the structure still has all the original 308 channels, even if I asked for gradiometers only. And if we continue: cfg = []; cfg.method = 'coh'; cfg.channelcmb = {'MEGGRAD' 'AudEnv'}; AudCoh = ft_connectivityanalysis(cfg, FreqFourier_Aud); >> AudCoh AudCoh = labelcmb: {0x2 cell} dimord: 'chancmb_freq' cohspctrm: [0x39 double] freq: [1x39 double] grad: [1x1 struct] elec: [1x1 struct] dof: 220 cfg: [1x1 struct] .. empty coherence output. If I change 'MEGGRAD' to 'MEG', the output is fine.


Jan-Mathijs Schoffelen - 2018-03-22 08:01:27 +0100

The reason I asked about your supervisor / on site help is 1) that it's much easier to solve stuff while sitting together 2) local people know much more about the data you acquire 3) it's their job 4) there is no real incentive for me to help out, because I don't get money for it, nor a co-authorship and nor a future job. This being said, it's still not clear to me what the exact problem is, but my implicit suggestion to break it down in parts did not help, so let's make it explicit. In order to nail this you should zoom in at how ft_channelcombination/ft_channelselection behaves, not how freqanalysis or connectivityanalysis behave at a higher level. This suggests that there is a problem (at least with the fieldtrip version you are using: have you checked that you are using the latest version of the code? The reason I ask is because I have not been able to reproduce your problem on my end) with how the 'wildcard' syntax tries to extract the relevant channels from the datastructure at hand. All this said: Please first ensure that you have the latest version of the code, and if the problem persists, try to break it down to the lowest level at which the problem can be identified.