2010/bmi10/EMG: tdfeats.m

File tdfeats.m, 2.9 KB (added by adutta1, 8 years ago)

Time domain feature extraction

Line 
1
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% TDFEATS        Compute all time domain features
4%                        and the mean features [Hudgins 1991]
5%                       
6%%% Anirban Dutta
7%%% a-dutta@northwestern.edu
8%%% Creation date: 7/03/2010
9%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
11function [Features] = tdfeats(DataSet,Nframe,inc)
12
13DEADZONE = 0.025;
14SCALE_ZC = 15;
15SCALE_MAV = 2;
16MAV_SIZE = 100;
17ruler = 1/inc;
18rulersq = ruler^2;
19lscale = inc/40;
20tscale=(inc/40.0)*10;
21
22
23
24Ntotal = size(DataSet,1);
25Nsig = size(DataSet,2);
26DataSet = DataSet - ones(Ntotal,1)*mean(DataSet);
27
28
29for 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 + (frame-1)*inc;
42                range = index:index+inc-1;
43                mav(frame) = mean(abs(DataSet(range,SigNum)));
44                flag1 = 1;
45                flag2 = 1;
46                for i = 1:inc-2;
47                        idx = index + i;
48                        fst = abs(DataSet(idx-1,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(idx-1,SigNum)>=0) | (DataSet(idx,SigNum)<=0 & DataSet(idx-1,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(((fst-mid)/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 = (len-1)./lscale;
82        turns = turns/tscale;
83        sd = std(dmav(:));
84        Features(:,SigNum) = [mav(:)' len(:)' zero_count(:)' turns(:)']';
85end