Solution
Rahul answered on
May 07 2021
[Content_Types].xml
_rels/.rels
matla
document.xml
Mini Project Submission Template Name: Date: ID Number: Instructions Please read the miniproject.mlx file before starting the assignment. The assignment is
oken down into multiple sections, your job is to fillout the sections with your code and aswer all of the questions. You need to directly modify this document with your solutions, name, ect. Once you have completed the assignment convert it into a pdf and upload the .mlx file and the pdf to ilearn. Do not work on this project with a partner or in groups, everyone needs to have unique solutions. This project accounts for a significant portion of you grade; make sure you submit it on time, with unique solutions, in proper format, and answer all of the questions to the best of your ability. Your job is to design a script that process Human Motion Data and prepare it for machine learning. Once again read the miniproject.mlx file and run through the example code before starting the questions. In this project you will be analysing raw data, preprocessing it, creating feature extraction algorithms, and most importantly practicing matlab. Import Raw Data Make sure the RawData folder is in the same directory as this file and the miniproject.mlx file otherwise the data will not import. for i = 1:5 % five motions
if i == 1
file = 'E:\Study Material\Matlab\Machine_learning_070520/sitting1.mat'; % data location and file name
elseif i == 2
file = 'E:\Study Material\Matlab\Machine_learning_070520/standing1.mat';
elseif i == 3
file = 'E:\Study Material\Matlab\Machine_learning_070520/using1.mat';
elseif i == 4
file = 'E:\Study Material\Matlab\Machine_learning_070520/walking1.mat';
else
file = 'E:\Study Material\Matlab\Machine_learning_070520/windmill1.mat';
end
customData{:,i} = load(file); % saves each motion time table into the cell a
ay called customData
end
% Display CustomData
disp(customData)% 1 x 5 of structures, each structure contains X number of rows and 3 columns (x,y,Z) Assignment Part 1 - Visualizing Raw Data Look at accessing data in a structrue and visualizing raw data sections. 1) Choose 1 static motion and 1 dynamic motion. You can not choose sitting! 2) Plot all axes (X, Y, and Z) for each motion in tiledlayout plot for one motion. The other motion must have all axes (X, Y, and Z) plots within 1 figure window with unique colors, linestyles or markers and a ledgend. You need to include a title, x axis labels, y axis labels, increase the linewidth for each plot/ figure. Question: 1) What motions did you choose? Solution: There are two motion a. Standing b. Walking
%%%% Place Your Code Here %%%%
%% Visualizing Raw Data
% Categorizationof the customdata
sittingdata = customData{1}; % Sitting data
standingdata = customData{2} % Standing data
usingdata = customData{3} % Using data
walkingdata = customData{4}% Walking data
windmilldata = customData{5}% % Windmil data
% Choosing Standing Data for Visualisation
standingX = standingdata.Acceleration.X;
standingY = standingdata.Acceleration.Y;
standingZ = standingdata.Acceleration.Z;
% Checks to see if the X, Y, and Z data are the same length for standing motion
lengthX_std = length(standingX);
lengthY_std = length(standingY);
lengthZ_std = length(standingZ);
if (lengthX_std == lengthY_std) && (lengthY_std == lengthZ_std)
disp('X, Y and Z Standing data are the same length')
else
disp('Data is not the same length')
end
% Plotting X data of Standing Data
figure(1);
tiledlayout(3,1);
% plotting sitting X data
ax1_std = nexttile;
plot(ax1_std,(1:lengthX_std),standingX,'Linewidth',2);
title(ax1_std,'Raw Data for Standing Motion X axis');
xlabel(ax1_std,'Number of Data points');
ylabel(ax1_std,'Range of Data');
legend('Standing X','location','best')
% plotting sitting Y data
ax2_std = nexttile;
plot(ax2_std,(1:lengthY_std),standingY,'Linewidth',2)
title(ax2_std,'Raw Data for Sitting Motion Y axis');
xlabel(ax2_std,'Number of Data points');
ylabel(ax2_std,'Range of Data');
legend('Standing Y','location','best')
% plotting sitting Z data
ax3_std = nexttile;
plot(ax3_std,(1:lengthZ_std),standingZ,'Linewidth',2)
title(ax3_std,'Raw Data for Sitting Motion Z axis');
xlabel(ax3_std,'Number of Data points');
ylabel(ax3_std,'Range of Data');
legend('Standing Z','location','best')
%% Choose Walking motion Data
walkingX = walkingdata.Acceleration.X;
walkingY = walkingdata.Acceleration.Y;
walkingZ = walkingdata.Acceleration.Z;
% Checks to see if the X, Y, and Z data are the same length for Walking motion
lengthX_wlk = length(walkingX);
lengthY_wlk = length(walkingY);
lengthZ_wlk = length(walkingZ);
if (lengthX_wlk == lengthY_wlk) && (lengthY_wlk == lengthZ_wlk)
disp('X, Y and Z Walking data are the same length')
else
disp('Data is not the same length')
end
% Plotting X data
figure(2);
tiledlayout(3,1);
% plotting Walking X data
ax1_wlk = nexttile;
plot(ax1_wlk,(1:lengthX_wlk),walkingX,'k-.','Linewidth',1);
title(ax1_wlk,'Raw Data for Walking Motion X axis');
xlabel(ax1_wlk,'Number of Data points');
ylabel(ax1_wlk,'Range of Data');
legend('Walking X','location','best')
legend('boxoff')
% plotting Walking Y data
ax2_wlk = nexttile;
plot(ax2_wlk,(1:lengthY_wlk),walkingY,'k-.','Linewidth',1)
title(ax2_wlk,'Raw Data for Walking Motion Y axis');
xlabel(ax2_wlk,'Number of Data points');
ylabel(ax2_wlk,'Range of Data');
legend('Walking Y','location','best')
legend('boxoff')
% plotting Walking Z data
ax3_wlk = nexttile;
plot(ax3_wlk,(1:lengthZ_wlk),walkingZ,'k-.','Linewidth',1)
title(ax3_wlk,'Raw Data for Walking Motion Z axis');
xlabel(ax3_wlk,'Number of Data points');
ylabel(ax3_wlk,'Range of Data');
legend('Walking Z','location','best')
legend('boxoff')
Assignment Part 2 - Preprocess Data "Cleaning" Look at Preprocessing Data "Cleaning" Section 1) Clean the data for all axes (X, Y, and Z) for each motion. All axes for each motion needs to have a minimum of 1000 data points. Remember the amount of data points must be consistant for each axes and for both motions. 2) Plot the preprocess data for each motion. Use a seperate figure for each motion. You can choose whatever plot style you want, however you need to include a title, x axis labels, y axis labels, increase the linewidth for each plot/ figure. Questions: 1) How many data points did you cut off from the begining of the raw data? Solution: 1000 2) How many data points did you cut off from the end of the raw data? Solution: 2499 3) How many data points are included in your processed data? Solution: 1500 %%%% Place Your Code Here %%%%
%% Preprocess Data "Cleaning" for Standing
%%% Chunk standing X, Y, Z axis data %%%
%%% Cutting the begining and end of the data %%%
% Cut 500 data points from the begining of the raw data
start = 1000;
% Specify how many data points you want
amount = 1500;
% cut X amount of data points from the end of the raw data
stop = start + amount -1; % minus 1 because data goes to 2001
%%% Cleaned Data %%%
standingX_clean = standingX(start:stop,1);
standingY_clean = standingY(start:stop,1);
standingZ_clean = standingZ(start:stop,1);
%%% Plotting Clean Data %%%
figure(3);
tiledlayout(3,1);
% plotting standing X data
ax1 = nexttile;
plot(ax1,(1:length(standingX_clean)),standingX_clean,'Linewidth',2);
title(ax1,'Clean Data for Standing Motion X axis');
xlabel(ax1,'Number of Data points');
ylabel(ax1,'Range of Data');
legend('Standing X Clean','location','best')
% plotting standing Y data
ax2 = nexttile;
plot(ax2,(1:length(standingY_clean)),standingY_clean,'Linewidth',2),
title(ax2,'Clean Data for Standing Motion Y axis');
xlabel(ax2,'Number of Data points');
ylabel(ax2,'Range of Data');
legend('Standing Y Clean','location','best')
% plotting standing Z data
ax3 = nexttile;
plot(ax3,(1:length(standingZ_clean)),standingZ_clean,'Linewidth',2)
title(ax3,'Clean Data for Standing Motion Z axis');
xlabel(ax3,'Number of Data points');
ylabel(ax3,'Range of Data');
legend('Standing Z Clean','location','best')
%% Preprocess Data "Cleaning" for Walking
%%% Chunk walking X, Y, Z axis data %%%
%%% Cutting the begining and end of the data %%%
% Cut 500 data points from the begining of the raw data
start = 1000;
% Specify how many data points you want
amount = 1500;
% cut X amount of data points from the end of the raw data
stop = start + amount -1; % minus 1 because data goes to 2499
%%% Cleaned Data %%%
walkingX_clean = walkingX(start:stop,1);
walkingY_clean = walkingY(start:stop,1);
walkingZ_clean = walkingZ(start:stop,1);
%%% Plotting Clean Data %%%
figure(4);
tiledlayout(3,1);
% plotting walking X data
ax1 = nexttile;
plot(ax1,(1:length(walkingX_clean)),walkingX_clean,'k-.','Linewidth',1);
title(ax1,'Clean Data for Walking Motion X axis');
xlabel(ax1,'Number of Data points');
ylabel(ax1,'Range of Data');
legend('Walking X Clean','location','best');
legend('boxoff');
% plotting walking Y data
ax2 = nexttile;
plot(ax2,(1:length(walkingY_clean)),walkingY_clean,'k-.','Linewidth',1),
title(ax2,'Clean Data for Walking Motion Y axis');
xlabel(ax2,'Number of Data points');
ylabel(ax2,'Range of Data');
legend('Walking Y Clean','location','best');
legend('boxoff');
% plotting walking Z data
ax3 = nexttile;
plot(ax3,(1:length(walkingZ_clean)),walkingZ_clean,'k-.','Linewidth',1)
title(ax3,'Clean Data for Walking Motion Z axis');
xlabel(ax3,'Number of Data points');
ylabel(ax3,'Range of Data');
legend('Walking Z Clean','location','best');
legend('boxoff');
Assignment Part 3 - Windowing Your Data "Chunking" Look at Preprcoessing Data "Windowing or Chunking" Section 1) Preprocess the data into windows/chunks for all axes (X, Y, and Z) for each motion. You can choose any window data point length, however you must have a minimum of 30 windows of data for each axis and motion. You can not choose a window length of 25 datapoints and you must have a whole number of data windows. Example: 1000 data points = cleaned data 10 data points for window length equals 100 data windows. You can not have a 12 data points for window length because this would result in 83.333 data windows. Questions: 1) How many data points did you use for your data window? solution: 30 2) How many data windows did you have? solution: 50 %%%% Place Your Code Here %%%%
%% Choose Window/ Chunk Length for Standing %%%
chunkSize = 30;
numChunk = length(standingX_clean)/chunkSize; % 80 Windows
%%% Chunk sitting X, Y, Z axis data %%%
for i = 1:numChunk
startIndex = ((i-1)*30)+1;
stopIndex = (i*30);
% create windows storage locations
standingXWindows(:,i) = standingX_clean(startIndex:stopIndex,1); % new size is 25 by 80, each column represnts 1 window of data
standingYWindows(:,i) = standingY_clean(startIndex:stopIndex,1);
standingZWindows(:,i) = standingZ_clean(startIndex:stopIndex,1);
end
%% Choose Window/ Chunk Length for Walking %%%
chunkSize = 30;
numChunk = length(walkingX_clean)/chunkSize; % 80 Windows
%%% Chunk sitting X, Y, Z axis data %%%
for i = 1:numChunk
startIndex = ((i-1)*30)+1;
stopIndex = (i*30);
% create windows storage locations
walkingXWindows(:,i) = walkingX_clean(startIndex:stopIndex,1); % new size is 25 by 80, each column represnts 1 window of data
walkingYWindows(:,i) = walkingY_clean(startIndex:stopIndex,1);
walkingZWindows(:,i) = walkingZ_clean(startIndex:stopIndex,1);
end
Assignment Part 4 - Custom Feature Extraction Look at Feature Extraction Section. 1) Create 2 custom feature extraction functions. You can not use MATLAB built in functions or create a custom Average function. You can design your feature extraction functions to highlight any feature "patterns" in the process data. Make sure you process all data axes for each motion. Include your functions at the bottom of the MLX script in the function section. Some common feature extraction methods: ● Mean "Average" - Do not use! ● Number of Positive Numbers ● Number of negative Numbers ● Number of slope Sign Changes ● Standard Deviation ● Number of data above a threshold value ● Number of data peaks 2) Plot the feature extracted data for each motion. Use a seperate figure for each motion. You can choose whatever plot style you want, however you need to include a title, x axis labels, y axis labels, increase the linewidth for each plot/figure. Questions: 1) What is the name of your custom feature extracted functions? Solution: a. NegativeN b. PositiveN 2) What feature extraction methods did you use? Solution: a. Total Negative number b. Total Positive Numbers Feature extraction method for negative number u %%%% Place Your Code Here %%%%
%% Feature extraction is to find number of negative number in each window
for i = 1:length(standingXWindows)
standingxclean = sum(standingXWindows(:,i)<0)% To find the number negative number in each window
standingyclean = sum(standingYWindows(:,i)<0)
standingzclean = sum(standingZWindows(:,i)<0)
standingXFeatures(1,i) = standingxclean
standingYFeatures(1,i) = standingyclean;
standingZFeatures(1,i) = standingzclean;
end
%%% Plotting Feature Extracted Data %%%
figure(5);
tiledlayout(3,1);
% plotting standing X data
ax1 = nexttile;
plot(ax1,standingXFeatures,'Linewidth',2);
title(ax1,'Feature Extracted Data for Standing Motion X axis - Number of Negative Number');
xlabel(ax1,'Number of Data points');
ylabel(ax1,'Range of Data');
legend('- in Standing X ','location','best');
% plotting standing Y data
ax2 = nexttile;
plot(ax2,standingYFeatures,'Linewidth',2)
title(ax2,'Feature Extracted Data for Standing Motion Y axis - Number of Negative Number');
xlabel(ax2,'Number of Data points');
ylabel(ax2,'Range of Data');
legend('- in Standing Y','location','best');
% plotting standing Z data
ax3 = nexttile;
plot(ax3,standingZFeatures,'Linewidth',2)
title(ax3,'Feature Extracted Data for Standing Motion Z axis - Number of Negative Number');
xlabel(ax3,'Number of Data points');
ylabel(ax3,'Range of Data');
legend('- in Standing Z ','location','best');
%% Feature extraction is to find number of negative number in each window
for i = 1:length(walkingXWindows)
walkingxclean = sum(walkingXWindows(:,i)>0)% To find the number negative number in each window
walkingyclean = sum(walkingYWindows(:,i)>0)
walkingzclean = sum(walkingZWindows(:,i)>0)
walkingXFeatures(1,i) = walkingxclean
walkingYFeatures(1,i) = walkingyclean;
walkingZFeatures(1,i) = walkingzclean;
end
%%% Plotting Feature Extracted Data %%%
figure(6);
tiledlayout(3,1);
% plotting walking X data
ax1 = nexttile;
plot(ax1,walkingXFeatures,'k-.','Linewidth',1);
title(ax1,'Feature Extracted Data for Walking Motion X axis - Number of Positive Number');
xlabel(ax1,'Number of Data points');
ylabel(ax1,'Range of Data');
legend('+ in Walking X ','location','best');
legend('boxoff')
% plotting walking Y data
ax2 = nexttile;
plot(ax2,walkingYFeatures,'k-.','Linewidth',1)
title(ax2,'Feature Extracted Data for Walking Motion Y axis - Number of Positive Number');
xlabel(ax2,'Number of Data points');
ylabel(ax2,'Range of Data');
legend('+ in Walking Y ','location','best');
legend('boxoff')
% plotting walking Z data
ax3 = nexttile;
plot(ax3,walkingZFeatures,'k-.','Linewidth',1)
title(ax3,'Feature Extracted Data for Walking Motion Z axis - Number of Positive Number');
xlabel(ax3,'Number of Data points');
ylabel(ax3,'Range of Data');
legend('+ in Walking Z ','location','best');
legend('boxoff')
Assignment Part 5 - Feature Matrix Organization Look at Feature Matrix "Data Organization" Section. 1) Organize all the feature extracted data into a single matrix. The format of the matrix is listed below: You should have 12 rows of data and X number of column depending on the number of data windows you chose. r1: X axis data for first Motion, first feature extraction method r2: Y axis data for first Motion, first feature extraction method r3: Z axis data for first Motion , first feature extraction method r4: X axis data for first Motion, second feature extraction method r5: Y axis data for first Motion, second feature extraction method r6: Z axis data for first Motion , second feature extraction method r7: X axis data for second Motion, first feature extraction method r8: Y axis data for second Motion, first feature extraction method r9: Z axis data for second Motion , first feature extraction method r10: X axis data for second Motion, second feature extraction method r11: Y axis data for second Motion, second feature extraction method r12: Z axis data for second Motion , second feature extraction method Questions: 1) What is the name of your feature matrix? solution: Data 2) What is the size of your feature matrix? solution: 12 50 %%%% Place Your Code Here %%%%
%% Feature Matrix Organization
% Finding all the row using custom function
[r1,r2,r3] = NegativeN(standingXWindows,standingYWindows,standingZWindows)
[r4,r5,r6] = PositiveN(standingXWindows,standingYWindows,standingZWindows)
[r7,r8,r9] = NegativeN(walkingXWindows,walkingYWindows,walkingZWindows)
[r10,r11,r12] = PositiveN(walkingXWindows,walkingYWindows,walkingZWindows)
Data = [r1;r2;r3;r4;r5;r6;r7;r8;r9;r10;r11;r12];
size_data = size(Data);
Place Your Custom Feature Extraction Functions Here %%%% Place Your Code Here %%%%
%% Code for NegativeN Custom Feature Function function [walkingXFeatures,walkingYFeatures,walkingZFeatures] = NegativeN(walkingXWindows,walkingYWindows,walkingZWindows)
for i = 1:length(walkingXWindows)
walkingxclean = sum(walkingXWindows(:,i)<0)% To find the number negative number in each window
walkingyclean = sum(walkingYWindows(:,i)<0)
walkingzclean = sum(walkingZWindows(:,i)<0)
walkingXFeatures(1,i) = walkingxclean
walkingYFeatures(1,i) = walkingyclean;
walkingZFeatures(1,i) = walkingzclean;
end
end
%% Code for PositiveN Custom Feature Function
function [walkingXFeatures,walkingYFeatures,walkingZFeatures] = PositiveN(walkingXWindows,walkingYWindows,walkingZWindows)
for i = 1:length(walkingXWindows)
walkingxclean = sum(walkingXWindows(:,i)>0)% To find the number negative number in each window
walkingyclean = sum(walkingYWindows(:,i)>0)
walkingzclean = sum(walkingZWindows(:,i)>0)
walkingXFeatures(1,i) = walkingxclean
walkingYFeatures(1,i) = walkingyclean;
walkingZFeatures(1,i) = walkingzclean;
end
end
matla
output.xml
manual code ready 0.4 text {1×1 struct} {1×1 struct} {1×1 struct} {1×1 struct} {1×1 struct}
false false 16 variableString standingdata Acceleration: [2535×3 timetable]
false false