# createdatamatpb

## PURPOSE

## SYNOPSIS

function data=createdatamatpb(data,E,Fs,win)

## DESCRIPTION

     Helper function to create an event triggered matrix from a single
     channel of data.
     Usage: data=createdatamatpb(data,E,Fs,win)
     Inputs:
     data   (input time series as a single vector) - required
     E      (events to use as triggers) - required
     Fs     (sampling frequency of data) - required
     win    (window around triggers to use data matrix -[winl winr]) - required
              e.g [1 1] uses a window starting 1 sec before E and
                  ending 1 sec after E if E is in secs
     Note that E, Fs, and win must have consistent units

     Outputs:
     data      (event triggered data)

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- coherencysegcpb Multi-taper coherency,cross-spectrum and individual spectra with segmenting
- coherencysegpb Multi-taper coherency,cross-spectrum and individual spectra computed by segmenting
- mtspecgramtrigpb Multi-taper event triggered time-frequency spectrum - binned point process
- mtspectrumsegpb Multi-taper segmented spectrum for a univariate binned point process
- mtspectrumtrigpb Multi-taper event triggered time-frequency spectrum - binned point process

## SOURCE CODE

    0001 function data=createdatamatpb(data,E,Fs,win)
    0002 %
    0003 % Helper function to create an event triggered matrix from a single
    0004 % channel of data.
    0005 % Usage: data=createdatamatpb(data,E,Fs,win)
    0006 % Inputs:
    0007 % data   (input time series as a single vector) - required
    0008 % E      (events to use as triggers) - required
    0009 % Fs     (sampling frequency of data) - required
    0010 % win    (window around triggers to use data matrix -[winl winr]) - required
    0011 %          e.g [1 1] uses a window starting 1 sec before E and
    0012 %              ending 1 sec after E if E is in secs
    0013 % Note that E, Fs, and win must have consistent units
    0014 %
    0015 % Outputs:
    0016 % data      (event triggered data)
    0017 %
    0018 if nargin < 4
    0019    error('Need all input arguments');
    0020 end
    0021 NE=length(E);
    0022 nwinl=round(win(1)*Fs);
    0023 nwinr=round(win(2)*Fs);
    0024 nE=floor(E*Fs)+1;
    0025 datatmp=[];
    0026 for n=1:NE;
    0027     indx=nE(n)-nwinl:nE(n)+nwinr-1;
    0028     datatmp=[datatmp data(indx)];
    0029 end
    0030 data=datatmp;