1 


2  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


3  % TDFEATS Compute all time domain features


4  % and the mean features [Hudgins 1991]


5  %


6  %%% Anirban Dutta


7  %%% adutta@northwestern.edu


8  %%% Creation date: 7/03/2010


9  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


10 


11  function [Features] = tdfeats(DataSet,Nframe,inc)


12 


13  DEADZONE = 0.025;


14  SCALE_ZC = 15;


15  SCALE_MAV = 2;


16  MAV_SIZE = 100;


17  ruler = 1/inc;


18  rulersq = ruler^2;


19  lscale = inc/40;


20  tscale=(inc/40.0)*10;


21 


22 


23 


24  Ntotal = size(DataSet,1);


25  Nsig = size(DataSet,2);


26  DataSet = DataSet  ones(Ntotal,1)*mean(DataSet);


27 


28 


29  for SigNum = 1:Nsig


30  clear mav dmav turns zero_count len;


31  for frame = 1:Nframe


32  zero_count(frame) = 0;


33  maxvalue(frame) = 0;


34  len(frame) = 0;


35  f_len(frame) = 0;


36  mav(frame) = 0;


37  dmav(frame) = 0;


38  turns(frame) = 0;


39 


40 


41  index = 1 + (frame1)*inc;


42  range = index:index+inc1;


43  mav(frame) = mean(abs(DataSet(range,SigNum)));


44  flag1 = 1;


45  flag2 = 1;


46  for i = 1:inc2;


47  idx = index + i;


48  fst = abs(DataSet(idx1,SigNum));


49  mid = abs(DataSet(idx,SigNum));


50  lst = abs(DataSet(idx+1,SigNum));


51 


52  % Compute Zero Crossings


53  if ((DataSet(idx,SigNum)>=0 & DataSet(idx1,SigNum)>=0)  (DataSet(idx,SigNum)<=0 & DataSet(idx1,SigNum)<=0))


54  flag1 = flag2;


55  elseif ((mid<DEADZONE) & (fst<DEADZONE))


56  flag1 = flag2;


57  else


58  flag1 = (1)*flag2;


59  end


60  if (flag1~=flag2);


61  zero_count(frame) = zero_count(frame) + 1;


62  flag1 = flag2;


63  end


64  % Compute Turns (Slope Changes


65  if((mid>fst & mid>lst)  (mid<fst & mid<lst))


66  % turns threshold of 15mV (i.e. 3uV noise)


67  if((abs(mid)abs(fst))>0.015  (abs(mid)abs(lst))>0.015)


68  turns(frame)=turns(frame)+1;


69  end


70  end


71  % Compute Waveform Length


72  len(frame) = len(frame) + sqrt(((fstmid)/20.0)^2 + rulersq);


73  end


74  end


75 


76 


77  % Scale the features to normalize for the neural network


78  zero_count = (zero_count./SCALE_ZC)*40/inc;


79  % scaling based on 40 ms


80  mav = mav/SCALE_MAV;


81  len = (len1)./lscale;


82  turns = turns/tscale;


83  sd = std(dmav(:));


84  Features(:,SigNum) = [mav(:)' len(:)' zero_count(:)' turns(:)']';


85  end 
