[Eeglablist] EEGlab function to trim datasets

James Jones-Rounds jj324 at cornell.edu
Thu Feb 13 13:37:24 PST 2014


Here is some code I have used to trim data away from datasets that are
substantially longer than the actual periods of interest. The code
basically looks for inter-trial intervals longer than a few seconds (you
can adjust that of course), and then takes those time points at either end
of a long "event-less" spell as the time-points to feed into pop_select for
eliminating.

%%% Here we will identify all the segments of the recording
%%% that are in between event blocks, and we'll delete those segments from
the
%%% continuous dataset.
            indices_in_datapoints_to_delete = [];
            time_thresh_between_events_in_sec = 5;
            time_thresh_between_events_in_pts =
time_thresh_between_events_in_sec * EEG.srate;

            for event_index =  1:length(EEG.event)

                prev_event_latency_in_pts = [];
                this_event_latency_in_pts = [];
                next_event_latency_in_pts = [];

                if event_index == 1

                    prev_event_latency_in_pts =
EEG.event(event_index).latency;
                    this_event_latency_in_pts =
EEG.event(event_index).latency;
                    next_event_latency_in_pts =
EEG.event(event_index+1).latency;

                    indices_in_datapoints_to_delete =
                                      [indices_in_datapoints_to_delete;
1

((EEG.event(event_index).latency)-(2*EEG.srate))];

                elseif event_index == length(EEG.event)


                    this_event_latency_in_pts =
EEG.event(event_index).latency;

                    indices_in_datapoints_to_delete =
                         [indices_in_datapoints_to_delete;
this_event_latency_in_pts
                         (EEG.xmax*EEG.srate)];

                else

                    prev_event_latency_in_pts = EEG.event(event_index -
1).latency;
                    this_event_latency_in_pts =
EEG.event(event_index).latency;
                    next_event_latency_in_pts =
EEG.event(event_index+1).latency;

                end

                prev_inter_trial_latency = this_event_latency_in_pts -
                                         prev_event_latency_in_pts;

                next_inter_trial_latency = next_event_latency_in_pts -
                                          this_event_latency_in_pts;

                if next_inter_trial_latency >
time_thresh_between_events_in_pts

                    indices_in_datapoints_to_delete =
                             [indices_in_datapoints_to_delete;
(this_event_latency_in_pts
                          + (2*EEG.srate)) (next_event_latency_in_pts -
(2*EEG.srate))];


                elseif  prev_inter_trial_latency >
time_thresh_between_events_in_pts

                    indices_in_datapoints_to_delete =
                          [indices_in_datapoints_to_delete;
(prev_event_latency_in_pts
                          + (2*EEG.srate)) (this_event_latency_in_pts -
2*EEG.srate)];

                end

            end %%% END for event_index loop

            EEG = pop_select(EEG, 'nopoint',
indices_in_datapoints_to_delete);

            EEG.comments = pop_comments(EEG.comments, '', 'Identified the
periods of time in between runs (i.e. blocks of trials) and deleted
those.', 1);

Hope that helps. Also "Out of Memory" errors can sometimes be solved by
increasing your MATLAB Java Heap Memory in the MATLAB > Preferences >
General section.

Good luck,

James

On Thu, Feb 13, 2014 at 12:25 PM, <eeglablist-request at sccn.ucsd.edu> wrote:

> Send eeglablist mailing list submissions to
>         eeglablist at sccn.ucsd.edu
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         http://sccn.ucsd.edu/mailman/listinfo/eeglablist
> or, via email, send a message with subject or body 'help' to
>         eeglablist-request at sccn.ucsd.edu
>
> You can reach the person managing the list at
>         eeglablist-owner at sccn.ucsd.edu
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of eeglablist digest..."
>
> Today's Topics:
>
>    1. EEGlab function to trim datasets (Brent A. Field)
>    2. UK EEGLAB workshop September 2015 (Elizabeth Milne)
>    3. Re: EEGlab function to trim datasets (Tarik S Bel-Bahar)
>    4. Why does GUI not update the "filename" field after I      save a
>       new dataset? (James Jones-Rounds)
>    5. Re: How to "difference plot" of coherences from two different
>       datasets or conditions in SIFT and/or EEGLAB (James Jones-Rounds)
>
>
> ---------- Forwarded message ----------
> From: "Brent A. Field" <bfield at princeton.edu>
> To: "eeglablist at sccn.ucsd.edu" <eeglablist at sccn.ucsd.edu>
> Cc:
> Date: Wed, 12 Feb 2014 22:26:10 +0000
> Subject: [Eeglablist] EEGlab function to trim datasets
>
> I running a computationally intensive analysis on a high-end cluster, but
> have been confounded because I periodically hit a Matlab Out of Memory
> error. The input data has a high sampling rate, has a lot of channels, and
> is collected over a long period. These can be simplified at later stages,
> but the first step requires inputting roughly a 4 GB continuous data file,
> with memory requirement far beyond that to actually run the analysis. I
> won't go into it, but there is a reason why the data needs processed as one
> block.
>
>
>
> There are other tricks I can try, but one obviously one is just to slim
> down the input. And fortunately there is some fat I can trim out of input
> datasets. But it seems that EEGlab deals with this by offering the option
> to mark data in continuous files as irrelevant, not by making a new copy of
> the dataset which just contains the data of interest. Is this correct?
>
>
>
> Obviously I can write my own function to remove irrelevant sections from
> the dataset, but I just wanted to check that there wasn't already some
> function out there first that chopped data out of EEG datasets.
>
>
>
> Thanks for any thoughts on this matter!
>
>
>
> Brent Field
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20140213/7d2328c6/attachment.html>


More information about the eeglablist mailing list