Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a data analysis matlab code about people fall actions. I have the CSV fi

ID: 2268376 • Letter: T

Question

This is a data analysis matlab code about people fall actions. I have the CSV file for thetime people start each actions aand stop. Also I have csv files about each person x,y,and z axies when they were doing each actions.  I need help for following things

1, I have to threshold for maximum and minimum acceleration to differentiate betwwen falls and non-falls.

2, I have to choose one singal subject to plot a bodplot and specturm for each activity.

3, I have to plot a low pass filter for that data that I have right now.

Here is what I am thinking right now. I want to build a matrix for time and all action. Then save it as .mat file. After that I think I can get plot for low pass filter. Howeve, I have problem about how can I save the .mat from few different CSV files. Also because of the data is about different acvtions. How can I plot the data for low pass filter? As I have the maximum and minimum acceleration. How can I choose one subject and get box plot for that?

Please explain each code that you use for. And give me and example for that. Thank you

Here is what I have for the code:

clc;
%% Extract indices of when each activity starts and stop
data=table2array(readtable('TimeStamps_Yo.csv'));
Sit1start = data(:,4);
Sit1stop = data(:,5);
Walkstart = data(:,7);
Walkstop = data(:,8);
Sit2start = data(:,10);
Sit2stop = data(:,11);
Standchairstart = data(:,13);
Standchairstop = data(:,14);
Fallstart = data(:,16);
Fallstop = data(:,17);
% Windows define hard-coded filenames of raw accelerometer data
filenames = {'.group_1_3_4d5la7xfr7-02-14T20-10-14-080Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-25-18-312Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-30-35-854Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-36-06-075Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-45-34-849Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-53-55-299Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-09-35-696Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-17-15-826Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-25-05-317Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-30-23-373Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-35-54-397Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-53-43-539Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-09-41-690Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-25-08-682Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-30-28-796Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-36-00-662Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-41-34-687Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-10-14-080Zccel.csv'};
% Pre-allocate cell array to store acceleration magnitude data
accelMag = cell(18,1);
% Pre-allocate arrays to store UPV and LPV data
UPV_Sit1 = zeros(18,1);
LPV_Sit1 = zeros(18,1);
UPV_Sit2 = zeros(18,1);
LPV_Sit2 = zeros(18,1);
UPV_Walk = zeros(18,1);
LPV_Walk = zeros(18,1);
UPV_StandChair = zeros(18,1);
LPV_StandChair = zeros(18,1);
UPV_Fall = zeros(18,1);
LPV_Fall = zeros(18,1);
% Loop over filenames, load data for each subject and compute and store acceleration magnitude
for sub_number=1:18
%Read data from file and extract data part of structure
accel_struct = importdata(filenames{sub_number});
accel_data = accel_struct.data;   
%Extract start time from data
start_time = accel_data(1,1);   
%Run data through normalize_data function to put in typical units
DATA=data_normalize(accel_data,start_time);
%Compute magnitude of acceleration and store in cell array
accelMag{sub_number} = sqrt(sum(DATA(:,2:4).^2,2));   
%Extract Max and Min values during each activity and store in arrays
%Sit 1
[UPV_Sit1(sub_number),LPV_Sit1(sub_number)] = compute_maxmin(accelMag{sub_number},...
Sit1start(sub_number),Sit1stop(sub_number));
%Sit 2
[UPV_Sit2(sub_number),LPV_Sit2(sub_number)] = compute_maxmin(accelMag{sub_number},...
Sit2start(sub_number),Sit2stop(sub_number));
%Walk
[UPV_Walk(sub_number),LPV_Walk(sub_number)] = compute_maxmin(accelMag{sub_number},...
Walkstart(sub_number),Walkstop(sub_number));
%Standing on Chair
[UPV_StandChair(sub_number),LPV_StandChair(sub_number)] = compute_maxmin(accelMag{sub_number},...
Standchairstart(sub_number),Standchairstop(sub_number));
%Fall
[UPV_Fall(sub_number),LPV_Fall(sub_number)] = compute_maxmin(accelMag{sub_number},...
Fallstart(sub_number),Fallstop(sub_number));
end  
%Create boxplot of data for each activity
figure;
boxplot([UPV_Sit1, UPV_Sit2, UPV_Walk, UPV_StandChair, UPV_Fall]);
ylabel('Maximum Acceleration Magnitude (m/s^2)');
xticklabels({'SitLow','SitHigh','Walk','StandChair','Fall'});

figure;
boxplot([LPV_Sit1, LPV_Sit2, LPV_Walk, LPV_StandChair, LPV_Fall]);
ylabel('Minimum Acceleration Magnitude');
xticklabels({'SitLow','SitHigh','Walk','StandChair','Fall'});
function reshapedData=data_normalize(accel_files,start_time)
% normalize to standard unit, accelarations(m/s^2) and times(s)
% All credit for this function goes to group 1 (TSway).
start = find(accel_files>=start_time,1,'first');
stop = length(accel_files);
time=(accel_files(start:stop,1)-accel_files(start,1))/1000;
acc_X=accel_files(start:stop,2)*9.81;
acc_Y=accel_files(start:stop,3)*9.81;%we no longer remove gravity cause we're moving
acc_Z=accel_files(start:stop,4)*9.81;
reshapedData=[time,acc_X,acc_Y,acc_Z];
end

function [maxval,minval] = compute_maxmin(data,start_ind,stop_ind)
% Function to extract the maximum and minimum values from range of Nx1
% column vector data specified by start_ind and stop_ind.
% Expects:
% 1 <= start_ind, stop_ind <= N
% size(data) = Nx1

%Error checking for start and stop indices
if start_ind < 1
start_ind = 1;
end
if start_ind > stop_ind
start_ind = stop_ind;
end
if stop_ind > length(data)
stop_ind = length(data);
end
  
%Compute max and min values over interval from start_ind to stop_ind
maxval = max(data(start_ind:stop_ind,1));
minval = min(data(start_ind:stop_ind,1));
end

Explanation / Answer

%% extract indices of when each activity starts and stop
data=table2array(readtable('TimeStamps_Yo.csv'));
Sit1start = data(:,4);
Sit1stop = data(:,5);
Walkstart = data(:,7);
Walkstop = data(:,8);
Sit2start = data(:,10);
Sit2stop = data(:,11);
Standchairstart = data(:,13);
Standchairstop = data(:,14);
Fallstart = data(:,16);
Fallstop = data(:,17);
% windows define hard-coded filenames of raw accelerometer data
filenames = {'.group_1_3_4d5la7xfr7-02-14T20-10-14-080Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-25-18-312Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-30-35-854Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-36-06-075Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-45-34-849Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-53-55-299Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-09-35-696Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-17-15-826Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-25-05-317Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-30-23-373Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-35-54-397Zccel.csv',...
'.group_1_3_4d5la7xsh7-02-14T20-53-43-539Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-09-41-690Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-25-08-682Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-30-28-796Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-36-00-662Zccel.csv',...
'.group_1_3_4d5la7xuo7-02-14T20-41-34-687Zccel.csv',...
'.group_1_3_4d5la7xfr7-02-14T20-10-14-080Zccel.csv'};
% previous-allocate cell array to store acceleration magnitude data
accelMag = cell(18,1);
% Previous-allocate arrays to store UPV and LPV data
UPV_Sit1 = zeros(18,1);
LPV_Sit1 = zeros(18,1);
UPV_Sit2 = zeros(18,1);
LPV_Sit2 = zeros(18,1);
UPV_Walk = zeros(18,1);
LPV_Walk = zeros(18,1);
UPV_StandChair = zeros(18,1);
LPV_StandChair = zeros(18,1);
UPV_Fall = zeros(18,1);
LPV_Fall = zeros(18,1);
% loop over filenames, load data for each subject and compute and store acceleration magnitude
for sub_number=1:18
%read data from file and extract data part of structure
accel_struct = importdata(filenames{sub_number});
accel_data = accel_struct.data;   
%extract start time from data
start_time = accel_data(1,1);   
%run data through normalize_data function to put in typical units
DATA=data_normalize(accel_data,start_time);
%Compute magnitude of acceleration and store in cell array
accelMag{sub_number} = sqrt(sum(DATA(:,2:4).^2,2));   
%extract Max and Min values during each activity and store in arrays
%Sit 1
[UPV_Sit1(sub_number),LPV_Sit1(sub_number)] = compute_maxmin(accelMag{sub_number},...
Sit1start(sub_number),Sit1stop(sub_number));
%Sit 2
[UPV_Sit2(sub_number),LPV_Sit2(sub_number)] = compute_maxmin(accelMag{sub_number},...
Sit2start(sub_number),Sit2stop(sub_number));
%walk
[UPV_Walk(sub_number),LPV_Walk(sub_number)] = compute_maxmin(accelMag{sub_number},...
Walkstart(sub_number),Walkstop(sub_number));
%standing on Chair
[UPV_StandChair(sub_number),LPV_StandChair(sub_number)] = compute_maxmin(accelMag{sub_number},...
Standchairstart(sub_number),Standchairstop(sub_number));
%fall
[UPV_Fall(sub_number),LPV_Fall(sub_number)] = compute_maxmin(accelMag{sub_number},...
Fallstart(sub_number),Fallstop(sub_number));
end  
figure;
boxplot([UPV_Sit1, UPV_Sit2, UPV_Walk, UPV_StandChair, UPV_Fall]);
ylabel('Maximum Acceleration Magnitude (m/s^2)');
xticklabels({'SitLow','SitHigh','Walk','StandChair','Fall'});

figure;
boxplot([LPV_Sit1, LPV_Sit2, LPV_Walk, LPV_StandChair, LPV_Fall]);
ylabel('Minimum Acceleration Magnitude');
xticklabels({'SitLow','SitHigh','Walk','StandChair','Fall'});
function reshapedData=data_normalize(accel_files,start_time)
% normalize to standard unit, accelarations(m/s^2) and times(s)
% All credit for this function goes to group 1 (TSway).
start = find(accel_files>=start_time,1,'first');
stop = length(accel_files);
time=(accel_files(start:stop,1)-accel_files(start,1))/1000;
acc_X=accel_files(start:stop,2)*9.81;
acc_Y=accel_files(start:stop,3)*9.81;%we no longer remove gravity cause we're moving
acc_Z=accel_files(start:stop,4)*9.81;
reshapedData=[time,acc_X,acc_Y,acc_Z];
end

function [maxval,minval] = compute_maxmin(data,start_ind,stop_ind)
% function to extract the maximum and minimum values from range of Nx1
% column vector data specified by start_ind and stop_ind.
% Expects:
% 1 <= start_ind, stop_ind <= N
% size(data) = Nx1

%error observation for start and stop indices
if start_ind < 1
start_ind = 1;
end
if start_ind > stop_ind
start_ind = stop_ind;
end
if stop_ind > length(data)
stop_ind = length(data);
end
  
%examine the max and min values over interval from start_ind to stop_ind
maxval = max(data(start_ind:stop_ind,1));
minval = min(data(start_ind:stop_ind,1));
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote