Home > bml > sync > bml_annot2coord.m

bml_annot2coord

PURPOSE ^

BML_ANNOT2COORD gets s1,t1,s2,t2 coordinates from annot and Fs

SYNOPSIS ^

function coord = bml_annot2coord(annot, Fs)

DESCRIPTION ^

 BML_ANNOT2COORD gets s1,t1,s2,t2 coordinates from annot and Fs

 Use as 
   coord = bml_annot2coord(annot, Fs)

 annot - ANNOT table with 'starts', 'ends' and optionally 'Fs' variables 
        (all other vars ignored)
 Fs - numeric, exact sampling frequency of returned s1,t1,s2,t2 coords. 
      if absent a Fs var in annot is required

 returns a table/struct if annot is a table/struct

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function coord = bml_annot2coord(annot, Fs)
0002 
0003 % BML_ANNOT2COORD gets s1,t1,s2,t2 coordinates from annot and Fs
0004 %
0005 % Use as
0006 %   coord = bml_annot2coord(annot, Fs)
0007 %
0008 % annot - ANNOT table with 'starts', 'ends' and optionally 'Fs' variables
0009 %        (all other vars ignored)
0010 % Fs - numeric, exact sampling frequency of returned s1,t1,s2,t2 coords.
0011 %      if absent a Fs var in annot is required
0012 %
0013 % returns a table/struct if annot is a table/struct
0014 
0015   if istable(annot)
0016     if exist('Fs','var')
0017       annot.Fs(:) = Fs;
0018     end
0019     assert(ismember('Fs',annot.Properties.VariableNames),"Fs required");
0020     assert(ismember('starts',annot.Properties.VariableNames),"starts required");
0021     assert(ismember('ends',annot.Properties.VariableNames),"ends required");  
0022     coord = annot;
0023     coord.s1(:)=0;
0024     coord.t1(:)=0;
0025     coord.s2(:)=0;
0026     coord.t2(:)=0;
0027     for i=1:height(annot)
0028       i_coord = annot2coord(annot.starts(i),annot.ends(i),annot.Fs(i));
0029       coord.s1(i)=i_coord.s1;
0030       coord.t1(i)=i_coord.t1;
0031       coord.s2(i)=i_coord.s2;
0032       coord.t2(i)=i_coord.t2;
0033     end
0034   elseif isstruct(annot)
0035     if exist('Fs','var')
0036       annot.Fs = Fs;
0037     end
0038     assert(ismember('Fs',fields(annot)),"Fs required");
0039     assert(ismember('starts',fields(annot)),"starts required");
0040     assert(ismember('ends',fields(annot)),"ends required");
0041     coord = annot2coord(annot.starts,annot.ends,annot.Fs);
0042   else
0043     error('Unknown type for annot. Table or struct accepted.');
0044   end
0045 end
0046 
0047 function simple_coord = annot2coord(starts,ends,Fs)
0048   pTT = 9; %pTT = pTimeTol = -log10(timetol)
0049   simple_coord=[];
0050   simple_coord.s1=1;
0051   simple_coord.t1=round(starts+0.5/Fs,pTT);
0052   simple_coord.s2=round((ends-starts)*Fs)-1;
0053   simple_coord.t2=simple_coord.t1 + (simple_coord.s2 - simple_coord.s1)/Fs; 
0054 end
0055

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