JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for SPM Archives


SPM Archives

SPM Archives


SPM@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

SPM Home

SPM Home

SPM  March 2009

SPM March 2009

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: time frequency

From:

Vladimir Litvak <[log in to unmask]>

Reply-To:

Vladimir Litvak <[log in to unmask]>

Date:

Mon, 2 Mar 2009 10:57:58 +0000

Content-Type:

multipart/mixed

Parts/Attachments:

Parts/Attachments

text/plain (78 lines) , spm_eeg_convert2images.m (1 lines)

Hi Felix,

On Sun, Mar 1, 2009 at 1:51 PM, Felix Blankenburg
<[log in to unmask]> wrote:

> I am trying to convert EEG time-frequency maps to nifti-images. The option
> of averaging over frequencies works. Unfortunately, if I am averaging over
> channels (for example: electrodes[s] [33 34 35 35] and region number 2),  I
> get the following error message (see below).

I fixed the problem. Use the attached version.

> It's also not clear to me what
> the meaning of the 'region number' is.
>

As far as I can see from the code it's only the number that is
pre-pended to directory name. It's not used for anything else. In
general the code for all the sensor-level and TF analysis hasn't
changed much since SPM5. I'm planning to do a deep re-write of it but
I won't have time for it in the near future.

> My plan is to write an EEG time-frequency map for every single channel as a
> 2D or ideally as a 3D nifti images i.e. time, frequency and channels. Is
> there a simple way in SPM8 for EEG to do this?

Since representing channels requires 2 dimensions -  time, frequency
and channels would be 4 dimensions and this is not supported. You can
either have channels and frequencies or channels and time or time
frequency for a single (or averaged) channel, but not everything
together.

>
> PS: Is there something noteworthiness that only up-going flanks are
> supported for Biosemi in SPM for EEG.

No. I think it's just a property of Biosemi that there are no
down-going flanks and SPM always asks for both directions so there is
a warning. As long as you can find the triggers you are interested in,
this is not something to worry about.

Best,

Vladimir

>
> Warning: Divide by zero.
>> In mean at 29
>  In spm_cond_units at 19
>  In spm_eeg_convert2images at 135
>  In spm at 879
> Warning: Divide by zero.
>> In mean at 29
>  In spm_cond_units at 19
>  In spm_eeg_convert2images at 135
>  In spm at 879
> ??? Error using ==> nifti.subsasgn>assigndat at 382
> "raw" must be of class "file_array"
>
> Error in ==> nifti.subsasgn>fun at 76
>           obj      = assigndat(obj,val);
>
> Error in ==> nifti.subsasgn at 20
>       obji    = fun(obji,subs,val);
>
> Error in ==> spm_eeg_convert2images at 135
>                   N.dat = spm_cond_units(dat);
>
> Error in ==> spm at 879
> evalin('base',CBs{v-1})
>
> ??? Error while evaluating uicontrol Callback
>
>
>
>



function [D, S] = spm_eeg_convert2images(S) % User interface for conversion of M/EEG-files to SPM image file format % FORMAT D = spm_eeg_convert2images(S) % % struct S is optional and has the following (optional) fields: % D - matrix of EEG mat-files % images.fmt - string that determines type of input file. Currently, this % string can be 'electrodes' or 'frequency' % images.elecs - electrodes of interest (as vector of indices) % images.freqs - frequency window of interest (2-vector) [Hz] % n - dimension of output images in voxels (scalar because % output will be square image) % interpolate_bad - flag (0/1) that indicates whether values for % bad channels should be interpolated (1) or left % out (0). % output: % S - can be used to construct script (as in the history-function) %_______________________________________________________________________ % % spm_eeg_convert2images is a user interface to convert M/EEG-files in SPM % format to SPM's image format, using an interpolation on a 2D-plane. % This function assembles some necessary information before % branching to the format-specific conversion routines. % % % Output: The converted data are written to files. The header % structs, but not the data, are returned in D as a cell vector of structs, % and the struct S is returned to allow for saving the history of function % calls. %_______________________________________________________________________ % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging % James Kilner, Stefan Kiebel % $Id: spm_eeg_convert2images.m 2803 2009-03-02 10:47:41Z vladimir $ [Finter,Fgraph,CmdLine] = spm('FnUIsetup','TF',0); try D = S.D; catch D = spm_select(1, '\.mat$', 'Select EEG mat file'); S.D = D; end P = spm_str_manip(D, 'H'); try D = spm_eeg_load(D); catch error(sprintf('Trouble reading file %s', D)); end if strcmp(D.type, 'continuous') error('Data are continuous. Try epoched data.'); end if strcmp(D.transformtype, 'TF'); try images.fmt = S.images.fmt; catch spm_input('average over ...', 1, 'd') Ctype = { 'channels',... 'frequency'}; str = 'Average over which dimension'; Sel = spm_input(str, 2, 'm', Ctype); images.fmt = Ctype{Sel}; end switch images.fmt case {'channels'} try images.electrodes_of_interest = S.images.elecs; catch str = 'electrodes[s]'; Ypos = -1; while 1 if Ypos == -1 [images.electrodes_of_interest, Ypos] = spm_input(str, '+1', 'r', [], [1 Inf]); else images.electrodes_of_interest = spm_input(str, Ypos, 'r', [], [1 Inf]); end if any(ismember(images.electrodes_of_interest, [1:D.nchannels])) break end end S.images.elecs = images.electrodes_of_interest; end try images.Nregion = S.images.region_no; catch str = 'region number'; Ypos = -1; while 1 if Ypos == -1 [images.Nregion, Ypos] = spm_input(str, '+1', 'r', [], [1 Inf]); else images.Nregion = spm_input(str, Ypos, 'r', [], [1 Inf]); end if ~isempty(images.Nregion) break, end str = 'No data'; end S.images.region_no = images.Nregion; end cl = D.condlist; for i = 1 : D.nconditions Itrials = pickconditions(D, cl{i}, 1)'; cd(D.path) dname = sprintf('%dROI_TF_trialtype_%s', images.Nregion, cl{i}); [m, sta] = mkdir(dname); cd(dname); for l = Itrials(:)' % if single trial data make new directory for single trials, % otherwise just write images to trialtype directory if strcmp(D.type, 'single') % single trial data fname = sprintf('trial%04d.img', l); else fname = 'average.img'; end dat = file_array(fname, [D.nfrequencies D.nsamples], 'FLOAT64'); dat(:, :) = spm_cond_units(squeeze(mean(D(images.electrodes_of_interest, :, :, l), 1))); N = nifti; N.dat = dat; N.mat = [1 0 0 min(D.frequencies); 0 1000/D.fsample 0 time(D, 1, 'ms'); 0 0 1 0; 0 0 0 1]; N.mat_intent = 'Aligned'; create(N); end end case {'frequency'} try images.Frequency_window = S.images.freqs; Ypos = -1; while 1 if Ypos == -1 Ypos = '+1'; end inds = find(D.frequencies >= Frequency_window(1) & D.frequencies <= Frequency_window(2)); if ~isempty(inds) break, end str = 'No data in range'; end catch str = 'Frequency window'; Ypos = -1; while 1 if Ypos == -1 Ypos = '+1'; end [images.Frequency_window, Ypos] = spm_input(str, Ypos, 'r', [], 2); inds = find(D.frequencies >= images.Frequency_window(1) & D.frequencies <= images.Frequency_window(2)); if ~isempty(inds) break, end str = 'No data in range'; end end % generate new meeg object with new filenames fnamedat = ['F' num2str(images.Frequency_window(1)) '_' num2str(images.Frequency_window(2)) '_' D.fnamedat]; Dnew = clone(D, fnamedat, [D.nchannels D.nsamples D.ntrials]); Dnew(1:Dnew.nchannels, 1:Dnew.nsamples, 1:Dnew.ntrials) = ... squeeze(mean(D(:, inds, :, :), 2)); % fake time-series data Dnew = transformtype(Dnew, 'time'); save(Dnew); S.Fname = fullfile(Dnew.path, Dnew.fname); try n = S.n; catch S.n = spm_input('Output image dimension', '+1', 'n', '32', 1); n = S.n; end if length(n) > 1 error('n must be scalar'); end try interpolate_bad = S.interpolate_bad; catch S.interpolate_bad = spm_input('Interpolate bad channels or mask out?',... '+1', 'b', 'Interpolate|Mask out', [1,0]); end spm_eeg_convertmat2nifti3D(S); end else clear S; S.Fname = fullfile(D.path, D.fname); spm_eeg_convertmat2nifti3D(S); end

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager