Feature Extraction from Accelerometer Data using Matlab
Mostra commenti meno recenti
I would like to extract statistical features such as min, max,magnitude, standard deviation, mean, correlation, energy from raw accelerometer (x,y, and z) data collected from smartphone accelerometer. Features are to be extracted from raw acceleration data using a window size of 512 samples with 256 samples overlapping between consecutive windows (sliding window with 50% overlap) using Matlab.
Here is my code which i have developed so far and i would appreciate if anyone could verify if its correct. Will also be very thankful if someone could highlight on sliding window portion for Matlab.
Thanks a lot in advance for your assistance.
if true
clear all
data = load ('user_1703.txt');
accX = data(:,3)/9.8;%3rd column of the CSV file is the values of Accelerometer X accY = data(:,4)/9.8;%4th column of the CSV file is the values of Accelerometer Y accZ = data(:,5)/9.8;%5th column of the CSV file is the values of Accelerometer Z %**************************************************************************
[m,n]=size(accX); acc = ones(1,m); %%************Initialization of the statistical values of the windows******% avgX=zeros(1,500); avgY=zeros(1,500); avgZ=zeros(1,500); avgACC=zeros(1,500); maxACC=-3*ones(1,500); %these -3 and 100 values are random values which makes the inital values look a lot different than the actual values minACC=-3*ones(1,500); maxX=100*ones(1,500); maxY=100*ones(1,500); maxZ=100*ones(1,500); minX=-100*ones(1,500); minY=-100*ones(1,500); minZ=-100*ones(1,500); stdX=zeros(1,500); stdY=zeros(1,500); stdZ=zeros(1,500); stdACC=zeros(1,500); XYcorr=zeros(1,500); XZcorr=zeros(1,500); YZcorr=zeros(1,500); energy=zeros(1,500); %************************************************************************** %************************************************************************** for i=1:m acc(i)=sqrt((accX(i)^2+accY(i)^2+accZ(i)^2)); end
i=1; j=1; windowsize=50; %*******In each iteration, statistical values of a window are calculated %and raw data(accX,accY,accZ) index is inceremented by windowsize/2 to %provide %50 overlapping*************************************************% while(i<=m-52) corrmatrix=corrcoef([accX(i:i+windowsize-1),accY(i:i+windowsize-1),accZ(i:i+windowsize-1)]); XYcorr(j)=corrmatrix(1,2); XZcorr(j)=corrmatrix(1,3); YZcorr(j)=corrmatrix(2,3);
avgX(j)=mean(accX(i:i+windowsize-1));
stdX(j)=std(accX(i:i+windowsize-1))
maxX(j)=max(accX(i:i+windowsize-1));
minX(j)=min(accX(i:i+windowsize-1));
avgY(j)=mean(accY(i:i+windowsize-1));
stdY(j)=std(accY(i:i+windowsize-1));
maxY(j)=max(accY(i:i+windowsize-1));
minY(j)=min(accY(i:i+windowsize-1));
avgZ(j)=mean(accZ(i:i+windowsize-1));
stdZ(j)=std(accZ(i:i+windowsize-1));
maxZ(j)=max(accZ(i:i+windowsize-1));
minZ(j)=min(accZ(i:i+windowsize-1));
avgACC(j)=mean(acc(i:i+windowsize-1));
stdACC(j)=std(acc(i:i+windowsize-1));
maxACC(j)=max(acc(i:i+windowsize-1));
minACC(j)=min(acc(i:i+windowsize-1));
energy(j)=sum(abs(fft(acc(i:i+windowsize-1))))/26; %
%Energy is defined as the normalized summation of absolute values of
%Discrete Fourier Transform of a windowed signal sequence
i=i+windowsize/2-1;
j=j+1;
end
%**************************************************************************
%This cell represents a matrix consisting of each row representing a
%window and each column representing the statistical attribute
%calculated above%
cell=[maxX.',minX.',avgX.',stdX.',maxY.',minY.',avgY.',stdY.',maxZ.',minZ.',avgZ.',stdZ.',maxACC.',minACC.',avgACC.',stdACC.',XYcorr.',XZcorr.',YZcorr.',energy.'];
%MATLAB has a built-in function to write the matrix given as input into a file of the format of CSV.
csvwrite('features.csv',cell);
end
7 Commenti
Shashank
il 9 Mar 2014
Hi Rajeev
Could you please provide me the 'user_1703.txt' file for testing. Plus can you also send me the supporting documents (references) by which you are extracting these features.Then only I may be able to help you out.
Shasha
M.Noorazlan Shah Zainudin
il 10 Apr 2015
hi I am also run this code but got an error on the cell code. this error appear ??? Error using ==> horzcat CAT arguments dimensions are not consistent.
can you provide your dataset? Thanks
Md.Mobasshir Arshed
il 27 Giu 2015
Could u please give the text file? thanks
M.Noorazlan Shah Zainudin
il 3 Lug 2015
hi actually my problem solved after i did some changes when i read the data. but can u explain what is the purpose for some line of code such:
1. avgX=zeros(1,500); 2. maxX=100*ones(1,500);
and the window size is 50 and what is the meaning of while(i<=m-52)
thanks
Muhammad Hammad Malik
il 18 Gen 2021
had you used this code, i want to get some understanding.thanks
Saif Aljanahi
il 30 Mar 2021
Thanks man, this code really helped me, I'm so grateful.
Risposte (1)
Shrey Joshi
il 18 Mag 2022
0 voti
you can start by using features provided in feature extraction mode of signal labeler app.
https://www.mathworks.com/help/signal/ug/extract-signal-features.html
Categorie
Scopri di più su t Location-Scale Distribution in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!