Home > bml > signal > bml_pad.m

bml_pad

PURPOSE ^

BML_PAD returns a padded version of the raw (crops if necessary)

SYNOPSIS ^

function [padded, presamples, postsamples] = bml_pad(raw, starts, ends, padval)

DESCRIPTION ^

 BML_PAD returns a padded version of the raw (crops if necessary)

 Use as
   padded = bml_pad(raw, starts, ends, padval)
   padded = bml_pad(cfg, raw)
   [padded, presamples, postsamples] = bml_pad(___)

 raw     - FT_DATATYPE_RAW to be padded and/or cropped
 starts  - double: global time at which to start
 ends    - double: global time at which to end
 padval  - double: value used for padding, defaults to zero

 padded  - FT_DATATYPE_RAW: padded version of raw
 presamples - integer: number of padval samples added at the begging 
 postsamples - integer: number of padval samples added at the end

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [padded, presamples, postsamples] = bml_pad(raw, starts, ends, padval)
0002 
0003 % BML_PAD returns a padded version of the raw (crops if necessary)
0004 %
0005 % Use as
0006 %   padded = bml_pad(raw, starts, ends, padval)
0007 %   padded = bml_pad(cfg, raw)
0008 %   [padded, presamples, postsamples] = bml_pad(___)
0009 %
0010 % raw     - FT_DATATYPE_RAW to be padded and/or cropped
0011 % starts  - double: global time at which to start
0012 % ends    - double: global time at which to end
0013 % padval  - double: value used for padding, defaults to zero
0014 %
0015 % padded  - FT_DATATYPE_RAW: padded version of raw
0016 % presamples - integer: number of padval samples added at the begging
0017 % postsamples - integer: number of padval samples added at the end
0018 
0019 if nargin==2
0020   cfg=raw;
0021   raw=starts;
0022   if istable(cfg)
0023     if height(cfg) > 1; error('cfg should be a 1 row table'); end
0024     cfg=table2struct(cfg);
0025   end
0026   starts = bml_getopt(cfg,'starts');
0027   ends = bml_getopt(cfg,'ends');
0028   padval = bml_getopt(cfg,'padval');
0029 elseif nargin==3
0030   padval = 0;
0031 elseif nargin ~=4
0032   error('invalid use of bml_pad');
0033 end
0034 
0035 if numel(raw.time) > 1; error('single trial continuous raw required'); end
0036 nSamples = length(raw.time{1});
0037 
0038 % tc=[];
0039 % tc.s1=1; tc.s2=length(raw.time{1});
0040 % tc.t1=raw.time{1}(1); tc.t2=raw.time{1}(end);
0041 tc = bml_raw2coord(raw);
0042 [s,e]=bml_crop_idx(tc,starts,ends);
0043 
0044 padded = bml_crop(raw,starts,ends);
0045 presamples = max([1-s, 0]);
0046 postsamples = max([e-nSamples, 0]);
0047 
0048 if presamples>0 
0049   padded.trial{1} = padarray(padded.trial{1},[0 presamples],padval,'pre');
0050 end
0051 if postsamples > 0
0052   padded.trial{1} = padarray(padded.trial{1},[0 postsamples],padval,'post');
0053 end
0054 padded.time{1} = bml_idx2time(tc,s:e);
0055 
0056 padded.sampleinfo = [s,e];
0057

Generated on Tue 25-Sep-2018 10:08:19 by m2html © 2005