-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateNewFeatures.m
57 lines (47 loc) · 1.52 KB
/
generateNewFeatures.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
%Features based on x,y,z and magnitude of accelerometer and gyroscope
function [feature]= generateNewFeatures(aNorm,SAMPLE_FREQ)
feature=zeros(1,19); %Number of features
%Mean Features
feature(1,1)=mean(aNorm);
%Max Features
feature(1,2) = max(aNorm);
%Min Features
feature(1,3) = min(aNorm);
%Std Deviation Features
feature(1,16)=std(aNorm);
%IQR features
IQR=quantile(aNorm,[0.25 0.75]);
feature(1,21)=IQR(2)-IQR(1);
%Frequency features
h=spectrum.welch('Hamming',length(aNorm));
Hpsd=psd(h,aNorm,'Fs',SAMPLE_FREQ,'ConfLevel',0.95);
feature(1,24)=Hpsd.avgpower;%/winSize;%Total Avg Power
%spectral entropy [0 10] band
%Advancing from Offline to Online Activity Recognition with Wearable Sensors
nHpsd=Hpsd.Data/sum(Hpsd.Data);%Normalize
SE=0;
for x=1:length(Hpsd.Frequencies)
SE = nHpsd(x)*log(nHpsd(x)) + SE;
end
feature(1,25)=-SE/log(x-1);
%FFT
m = length(aNorm); % Window length
n = pow2(nextpow2(m)); % Transform length
y = fft(aNorm,n); % DFT
%f = (0:n-1)*(SAMPLE_FREQ/n); % Frequency range
power = y.*conj(y)/n; % Power of the DFT
%power=power/winSize;%Normalize
feature(1,26)=power(1);
%Activity Recognition from User-Annotated Acceleration Data
power(1)=[];%remove dc component
feature(1,27)=norm(power);
FFTE=0;
for x=1:length(power)
FFTE = FFTE + power(x)*log(power(x));
end
feature(1,28)= -FFTE;
%Correlation between ax,ay and az
feature(1,29)= corr(ax,ay);
feature(1,30)= corr(ay,az);
feature(1,31)= corr(ax,az);
% fprintf('New-features\n');