Dear Diane,
I got the file and it's very helpful. There are several separate
problems that we should resolve carefully step by step.
1) Your channel labels seem like those of a Biosemi system but there
is no 64-channel Biosemi system we are familiar with. Do you have a
system with more channels of which you are only using half or is it a
really 64 channel system? In the latter case we'll need some
additional info to support it.
2) The other examples you showed me had 10-20 labels. How did you
assign them? Was it with montage?
3) The problem is that the set of labels in that file is not
recognized by SPM as EEG labels. As a result the channels are not
classified as EEG channels and they are not filtered. So if you want
to change the labels to 10-20 you should do it earlier in your
processing stream. At least you should set the EEG channel types
manually in 'Prepare' and save the file before filtering.
4) There was a problem that went unnoticed for quite a long time, that
the SPM filtering function also did baseline-correction for epoched
data and for that it looked for negative time points. Your time axis
starts at 0.5 sec so there was a problem. I removed that baseline
correction that didn't belong there anyway so you can use the attached
version. Then filtering works.
5) Even after all this if I average the file there doesn't seem to be
any ERP. So if there should be an ERP in this data perhaps you have
some problem with your triggers.
6) Your sampling rate of 2048Hz is too high for most purposes. This
really slows SPM down. Perhaps you should downsample your file to just
a few hundred Hz as one of the first steps.
I think it'd help if you could write in more details about your EEG
system, the experimental paradigm, how you define your trials , what
processing steps you have before merging and what is the purpose of
your analysis. Then we could come up with a sequence of steps that
would be suitable for your purposes.
Best,
Vladimir
>>
>> On Fri, Jun 19, 2009 at 11:01 AM, Diane Whitmer<[log in to unmask]>
>> wrote:
>> > Vladimir,
>> > The problem of losing my data is arising at the time of filtering.
>> > Are the filter functions supposed to work on epoched data? If so, is
>> > there
>> > anything special I should do to get the filtering to work? e.g. I am
>> > trying
>> > to high pass above 2 Hz using the gui. My sampling rate is 2048 Hz and
>> > my
>> > epochs are 3.5 seconds in length.
>> > Thank you,
>> > Diane
>> >
>> >
>> > On Thu, Jun 18, 2009 at 1:47 PM, Vladimir Litvak
>> > <[log in to unmask]>
>> > wrote:
>> >>
>> >> Display->M/EEG
>> >>
>> >> On Thu, Jun 18, 2009 at 12:37 PM, Diane
>> >> Whitmer<[log in to unmask]>
>> >> wrote:
>> >> > Hi Vladimir,
>> >> > How do I access the Reviewing tool?
>> >> > When I look under Prepare > Review, I cannot find the EEG traces.
>> >> > Thanks,
>> >> > Diane
>> >> >
>> >> >
>> >> >
>> >> > On Thu, Jun 18, 2009 at 12:57 PM, Vladimir Litvak
>> >> > <[log in to unmask]> wrote:
>> >> >>
>> >> >> Dear Diane,
>> >> >>
>> >> >> The file you sent me contains just zeros in the data so it's not
>> >> >> surprising that SPM can't do much with it. Also the montage you
>> >> >> applied is just an identity matrix so it doesn't do anything, but
>> >> >> that's not the reason why the data is invalid. You should use the
>> >> >> reviewing tool to see at which stage in the processing your data
>> >> >> disappears.
>> >> >>
>> >> >> Best,
>> >> >>
>> >> >> Vladimir
>> >> >>
>> >> >> On Thu, Jun 18, 2009 at 11:42 AM, Diane
>> >> >> Whitmer<[log in to unmask]>
>> >> >> wrote:
>> >> >> > Hi Vladimir,
>> >> >> > I changed the montage to average reference, and then averaged my
>> >> >> > trials.
>> >> >> > The same error message appears when I try to run the Inverse
>> >> >> > Solution.
>> >> >> > I just sent both the .dat and the .mat via yousendit.
>> >> >> > Please let me know if you are able to figure out the source of the
>> >> >> > errors. I
>> >> >> > *very much* appreciate your help.
>> >> >> > Sincerely,
>> >> >> > Diane
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > On Wed, Jun 17, 2009 at 12:29 PM, Vladimir Litvak
>> >> >> > <[log in to unmask]> wrote:
>> >> >> >>
>> >> >> >> Dear Diane,
>> >> >> >>
>> >> >> >> Your new montage is quite good, but you should decide what you
>> >> >> >> want
>> >> >> >> to
>> >> >> >> do about the 'EXG1' channel. Presently it appears in the montage,
>> >> >> >> but
>> >> >> >> is actually set to zero. I understand this is your reference. I
>> >> >> >> saw
>> >> >> >> in
>> >> >> >> the history that you are using SPM's default channel locations.
>> >> >> >> SPM
>> >> >> >> wouldn't have a location for EXG1 and wouldn't mark it as 'EEG'
>> >> >> >> by
>> >> >> >> default. So you have two options:
>> >> >> >>
>> >> >> >> 1) If you want to use it as an extra EEG channel you need to
>> >> >> >> either
>> >> >> >> change its name to some 10-20 name and assign default channel
>> >> >> >> types
>> >> >> >> and default locations again or at least change its type to 'EEG'
>> >> >> >> in
>> >> >> >> the 'prepare' interface and load a locations file where this
>> >> >> >> channel
>> >> >> >> appears. Then you should make a montage like what you did just
>> >> >> >> with
>> >> >> >> 65
>> >> >> >> channels including EXG1 so
>> >> >> >> tra = eye(65) - ones(65)/65;
>> >> >> >>
>> >> >> >> 2) If you can live without it, you can use the montage you sent
>> >> >> >> me,
>> >> >> >> or
>> >> >> >> even simpler just don't include EXG1 in the montage at all. You
>> >> >> >> can
>> >> >> >> either keep it in the file as a non-EEG channel or not keep it,
>> >> >> >> for
>> >> >> >> source reconstruction it doesn't matter.
>> >> >> >>
>> >> >> >> Once you convert the data to average reference, try the source
>> >> >> >> reconstruction again. If there is still a problem, average your
>> >> >> >> data
>> >> >> >> and see if for averaged data you get the same error message. If
>> >> >> >> so
>> >> >> >> send it to me, the file will be much smaller. If you only get the
>> >> >> >> error for epoched data, but not for averaged let me know and
>> >> >> >> we'll
>> >> >> >> think of a way for you to send me the epoched file.
>> >> >> >>
>> >> >> >> Best,
>> >> >> >>
>> >> >> >> Vladimir
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> On Wed, Jun 17, 2009 at 11:12 AM, Diane
>> >> >> >> Whitmer<[log in to unmask]>
>> >> >> >> wrote:
>> >> >> >> > Vladimir,
>> >> >> >> > I tried to send the .dat file, but it was over 100MB and
>> >> >> >> > therefore
>> >> >> >> > cannot be
>> >> >> >> > sent via yousendit without a subscription. Do you have another
>> >> >> >> > suggestion?
>> >> >> >> > Thanks,
>> >> >> >> > Diane
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > On Tue, Jun 16, 2009 at 9:38 PM, Vladimir Litvak
>> >> >> >> > <[log in to unmask]>
>> >> >> >> > wrote:
>> >> >> >> >>
>> >> >> >> >> Dear Diane,
>> >> >> >> >>
>> >> >> >> >> The error might have something to do with the fact that the
>> >> >> >> >> montage
>> >> >> >> >> matrix you used is wrong. To do what you intended you'd need
>> >> >> >> >> the
>> >> >> >> >> transpose of what you specified, but as I mentioned to be on
>> >> >> >> >> the
>> >> >> >> >> safe
>> >> >> >> >> side it'd be better to convert the data to average reference.
>> >> >> >> >> In
>> >> >> >> >> your
>> >> >> >> >> case of a 64 channel system you'd need something like:
>> >> >> >> >>
>> >> >> >> >> tra = eye(64) - ones(64)/64;
>> >> >> >> >>
>> >> >> >> >> for the EEG channels (or if you have 65, the same with 65).
>> >> >> >> >>
>> >> >> >> >> Best,
>> >> >> >> >>
>> >> >> >> >> Vladimir
>> >> >> >> >>
>> >> >> >> >> On Tue, Jun 16, 2009 at 12:37 PM, Diane
>> >> >> >> >> Whitmer<[log in to unmask]>
>> >> >> >> >> wrote:
>> >> >> >> >> > Dear SPMers,
>> >> >> >> >> >
>> >> >> >> >> > I am using SPM8 with EEG data. When I try to compute the
>> >> >> >> >> > Inverse
>> >> >> >> >> > solution, I
>> >> >> >> >> > get the following error message:
>> >> >> >> >> >
>> >> >> >> >> > Warning: Matrix is singular, close to singular or badly
>> >> >> >> >> > scaled.
>> >> >> >> >> > Results may be inaccurate. RCOND = NaN.
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > Does anyone have suggestions for how to debug this?
>> >> >> >> >> >
>> >> >> >> >> > A subset of these data previously worked for computing an
>> >> >> >> >> > Inverse
>> >> >> >> >> > Solution.
>> >> >> >> >> > One difference with my current dataset is that I have
>> >> >> >> >> > re-referenced
>> >> >> >> >> > to
>> >> >> >> >> > one
>> >> >> >> >> > of the EEG channels (because it's not clear that SPM selects
>> >> >> >> >> > a
>> >> >> >> >> > reference
>> >> >> >> >> > channel when importing from Biosemi). This may or may not be
>> >> >> >> >> > related
>> >> >> >> >> > to
>> >> >> >> >> > the
>> >> >> >> >> > problem I'm having.
>> >> >> >> >> >
>> >> >> >> >> >
>> >> >> >> >> > Thank you,
>> >> >> >> >> > --
>> >> >> >> >> > Diane Whitmer, Ph.D.
>> >> >> >> >> > Researcher in Applied Neuroscience
>> >> >> >> >> >
>> >> >> >> >> > C. de l' Observatori Fabra s/n
>> >> >> >> >> > 08035 - Barcelona - Spain
>> >> >> >> >> > tel. +34 93 254 03 68
>> >> >> >> >> > fax. +34 93 212 64 45
>> >> >> >> >> > skype. dwhitmer
>> >> >> >> >> > email. [log in to unmask]
>> >> >> >> >> > ______________________________________
>> >> >> >> >> > STARLAB, Living Science http://www.starlab.es
>> >> >> >> >> >
>> >> >> >> >> > This e-mail and the attached files contain confidential
>> >> >> >> >> > information
>> >> >> >> >> > and
>> >> >> >> >> > are
>> >> >> >> >> > of exclusive use for the addressee. The disclosure, copy and
>> >> >> >> >> > distribution of
>> >> >> >> >> > the present message and its attachments are prohibited. If
>> >> >> >> >> > you
>> >> >> >> >> > are
>> >> >> >> >> > not
>> >> >> >> >> > the
>> >> >> >> >> > intended recipient and you receive this communication, we
>> >> >> >> >> > inform
>> >> >> >> >> > you
>> >> >> >> >> > that it
>> >> >> >> >> > is forbidden by law to read, copy or use it. Please notify
>> >> >> >> >> > us
>> >> >> >> >> > at
>> >> >> >> >> > [log in to unmask] and proceed immediately to delete it.
>> >> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > --
>> >> >> >> > Diane Whitmer, Ph.D.
>> >> >> >> > Researcher in Applied Neuroscience
>> >> >> >> >
>> >> >> >> > C. de l' Observatori Fabra s/n
>> >> >> >> > 08035 - Barcelona - Spain
>> >> >> >> > tel. +34 93 254 03 68
>> >> >> >> > fax. +34 93 212 64 45
>> >> >> >> > skype. dwhitmer
>> >> >> >> > email. [log in to unmask]
>> >> >> >> > ______________________________________
>> >> >> >> > STARLAB, Living Science http://www.starlab.es
>> >> >> >> >
>> >> >> >> > This e-mail and the attached files contain confidential
>> >> >> >> > information
>> >> >> >> > and
>> >> >> >> > are
>> >> >> >> > of exclusive use for the addressee. The disclosure, copy and
>> >> >> >> > distribution of
>> >> >> >> > the present message and its attachments are prohibited. If you
>> >> >> >> > are
>> >> >> >> > not
>> >> >> >> > the
>> >> >> >> > intended recipient and you receive this communication, we
>> >> >> >> > inform
>> >> >> >> > you
>> >> >> >> > that it
>> >> >> >> > is forbidden by law to read, copy or use it. Please notify us
>> >> >> >> > at
>> >> >> >> > [log in to unmask] and proceed immediately to delete it.
>> >> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > --
>> >> >> > Diane Whitmer, Ph.D.
>> >> >> > Researcher in Applied Neuroscience
>> >> >> >
>> >> >> > C. de l' Observatori Fabra s/n
>> >> >> > 08035 - Barcelona - Spain
>> >> >> > tel. +34 93 254 03 68
>> >> >> > fax. +34 93 212 64 45
>> >> >> > skype. dwhitmer
>> >> >> > email. [log in to unmask]
>> >> >> > ______________________________________
>> >> >> > STARLAB, Living Science http://www.starlab.es
>> >> >> >
>> >> >> > This e-mail and the attached files contain confidential
>> >> >> > information
>> >> >> > and
>> >> >> > are
>> >> >> > of exclusive use for the addressee. The disclosure, copy and
>> >> >> > distribution of
>> >> >> > the present message and its attachments are prohibited. If you are
>> >> >> > not
>> >> >> > the
>> >> >> > intended recipient and you receive this communication, we inform
>> >> >> > you
>> >> >> > that it
>> >> >> > is forbidden by law to read, copy or use it. Please notify us at
>> >> >> > [log in to unmask] and proceed immediately to delete it.
>> >> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Diane Whitmer, Ph.D.
>> >> > Researcher in Applied Neuroscience
>> >> >
>> >> > C. de l' Observatori Fabra s/n
>> >> > 08035 - Barcelona - Spain
>> >> > tel. +34 93 254 03 68
>> >> > fax. +34 93 212 64 45
>> >> > skype. dwhitmer
>> >> > email. [log in to unmask]
>> >> > ______________________________________
>> >> > STARLAB, Living Science http://www.starlab.es
>> >> >
>> >> > This e-mail and the attached files contain confidential information
>> >> > and
>> >> > are
>> >> > of exclusive use for the addressee. The disclosure, copy and
>> >> > distribution of
>> >> > the present message and its attachments are prohibited. If you are
>> >> > not
>> >> > the
>> >> > intended recipient and you receive this communication, we inform you
>> >> > that it
>> >> > is forbidden by law to read, copy or use it. Please notify us at
>> >> > [log in to unmask] and proceed immediately to delete it.
>> >> >
>> >
>> >
>> >
>> > --
>> > Diane Whitmer, Ph.D.
>> > Researcher in Applied Neuroscience
>> >
>> > C. de l' Observatori Fabra s/n
>> > 08035 - Barcelona - Spain
>> > tel. +34 93 254 03 68
>> > fax. +34 93 212 64 45
>> > skype. dwhitmer
>> > email. [log in to unmask]
>> > ______________________________________
>> > STARLAB, Living Science http://www.starlab.es
>> >
>> > This e-mail and the attached files contain confidential information and
>> > are
>> > of exclusive use for the addressee. The disclosure, copy and
>> > distribution of
>> > the present message and its attachments are prohibited. If you are not
>> > the
>> > intended recipient and you receive this communication, we inform you
>> > that it
>> > is forbidden by law to read, copy or use it. Please notify us at
>> > [log in to unmask] and proceed immediately to delete it.
>> >
>
>
>
> --
> Diane Whitmer, Ph.D.
> Researcher in Applied Neuroscience
>
> C. de l' Observatori Fabra s/n
> 08035 - Barcelona - Spain
> tel. +34 93 254 03 68
> fax. +34 93 212 64 45
> skype. dwhitmer
> email. [log in to unmask]
> ______________________________________
> STARLAB, Living Science http://www.starlab.es
>
> This e-mail and the attached files contain confidential information and are
> of exclusive use for the addressee. The disclosure, copy and distribution of
> the present message and its attachments are prohibited. If you are not the
> intended recipient and you receive this communication, we inform you that it
> is forbidden by law to read, copy or use it. Please notify us at
> [log in to unmask] and proceed immediately to delete it.
>
function D = spm_eeg_filter(S)
% Filter M/EEG data
% FORMAT D = spm_eeg_filter(S)
%
% S - input structure (optional)
% (optional) fields of S:
% S.D - MEEG object or filename of M/EEG mat-file
% S.filter - struct with the following fields:
% type - type of filter, currently only 'butterworth'
% band - filterband [low|high|bandpass|stop]
% PHz - cutoff frequency [Hz]
% parameter - filter coefficients
%
% D - MEEG object (also written to disk)
%__________________________________________________________________________
%
% This function filters M/EEG data and requires the signal processing
% toolbox from The MathWorks:
% http://www.mathworks.com/products/signal/
% (functions butter.m and filtfilt.m)
%__________________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
% Stefan Kiebel
% $Id: spm_eeg_filter.m 3213 2009-06-19 16:49:42Z vladimir $
SVNrev = '$Rev: 3213 $';
%-Startup
%--------------------------------------------------------------------------
spm('FnBanner', mfilename, SVNrev);
spm('FigName','M/EEG filter'); spm('Pointer', 'Watch');
%-Test for the presence of required Matlab toolbox
%--------------------------------------------------------------------------
if ~license('test','signal_toolbox')
error('M/EEG filtering requires the Signal Processing Toolbox.');
end
%-Get MEEG object
%--------------------------------------------------------------------------
try
D = S.D;
catch
[D, sts] = spm_select(1, 'mat', 'Select M/EEG mat file');
if ~sts, D = []; return; end
S.D = D;
end
D = spm_eeg_load(D);
%-Get parameters
%--------------------------------------------------------------------------
try
filter.type = S.filter.type;
catch
filter.type = spm_input('filter type', '+1', 'b', 'butterworth');
S.filter.type = filter.type;
end
switch filter.type
case 'butterworth'
try
filter.order = S.filter.order;
catch
filter.order = 5;
S.filter.order = filter.order;
end
try
filter.para = S.filter.para;
catch
filter.para = [];
S.filter.para = filter.para;
end
otherwise
error('Unknown filter type.');
end
try
filter.band = S.filter.band;
catch
filter.band = cell2mat(...
spm_input('filterband', '+1', 'm',...
'lowpass|highpass|bandpass|stopband',...
{'low','high','bandpass','stop'}));
S.filter.band = filter.band;
end
try
filter.PHz = S.filter.PHz;
catch
switch lower(filter.band)
case {'low','high'}
str = 'Cutoff [Hz]';
YPos = -1;
while 1
if YPos == -1
YPos = '+1';
end
[PHz, YPos] = spm_input(str, YPos, 'r');
if PHz > 0 && PHz < D.fsample/2, break, end
str = 'Cutoff must be > 0 & < half sample rate';
end
case {'bandpass','stop'}
str = 'band [Hz]';
YPos = -1;
while 1
if YPos == -1
YPos = '+1';
end
[PHz, YPos] = spm_input(str, YPos, 'r', [], 2);
if PHz(1) > 0 && PHz(1) < D.fsample/2 && PHz(1) < PHz(2), break, end
str = 'Cutoff 1 must be > 0 & < half sample rate and Cutoff 1 must be < Cutoff 2';
end
otherwise
error('unknown filter band.')
end
filter.PHz = PHz;
S.filter.PHz = filter.PHz;
end
switch filter.type
case 'butterworth'
if isempty(filter.para)
[B, A] = butter(filter.order, filter.PHz/(D.fsample/2), filter.band);
filter.para{1} = B;
filter.para{2} = A;
end
otherwise
error('Unknown filter type.');
end
%-
%--------------------------------------------------------------------------
% generate new meeg object with new filenames
Dnew = clone(D, ['f' fnamedat(D)], [D.nchannels D.nsamples D.ntrials]);
% determine channels for filtering
Fchannels = unique([D.meegchannels, D.eogchannels]);
if strcmp(D.type, 'continuous')
% continouous data
spm_progress_bar('Init', nchannels(D), 'Channels filtered'); drawnow;
if nchannels(D) > 100, Ibar = floor(linspace(1, nchannels(D),100));
else Ibar = [1:nchannels(D)]; end
% work on blocks of channels
% determine blocksize
% determine block size, dependent on memory
try
% 2/3 of largest block of contiguous memory, for Windows platforms
evalc('memsz=2/3*feature(''memstats'');');
catch
memsz = 200*1024*1024; % 200 MB
end
datasz = nchannels(D)*nsamples(D)*8; % datapoints x 8 bytes per double value
blknum = ceil(datasz/memsz);
blksz = ceil(nchannels(D)/blknum);
% now filter blocks of channels
chncnt=1;
for blk=1:blknum
% load old meeg object blockwise into workspace
blkchan=chncnt:(min(nchannels(D), chncnt+blksz-1));
if isempty(blkchan), break, end
Dtemp=D(blkchan,:,1);
chncnt=chncnt+blksz;
%loop through channels
for j = 1:numel(blkchan)
if ismember(blkchan(j), Fchannels)
Dtemp(j, :) = filtfilt(filter.para{1}, filter.para{2}, Dtemp(j,:));
end
if ismember(j, Ibar), spm_progress_bar('Set', blkchan(j)); end
end
% write Dtemp to Dnew
Dnew(blkchan,:,1)=Dtemp;
clear Dtemp;
end;
else
% single trial or epoched
spm_progress_bar('Init', D.ntrials, 'Events filtered'); drawnow;
if D.ntrials > 100, Ibar = floor(linspace(1, D.ntrials,100));
else Ibar = [1:D.ntrials]; end
for i = 1:D.ntrials
d = squeeze(D(:, :, i));
for j = 1:nchannels(D)
if ismember(j, Fchannels)
d(j,:) = filtfilt(filter.para{1}, filter.para{2}, double(d(j,:)));
end
end
Dnew(:, 1:Dnew.nsamples, i) = d;
if ismember(i, Ibar), spm_progress_bar('Set', i); end
end
end
spm_progress_bar('Clear');
%-Save new evoked M/EEG dataset
%--------------------------------------------------------------------------
D = Dnew;
D = D.history(mfilename, S);
save(D);
%-Cleanup
%--------------------------------------------------------------------------
spm('FigName','M/EEG filter: done'); spm('Pointer', 'Arrow');
|