|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| clear;
|
| clc;
|
| data_root = 'Gait120 Data';
|
| kinematicsVisualizer(data_root);
|
| EMGSignalVisualizer(data_root);
|
|
|
|
|
| function kinematicsVisualizer(data_root)
|
| target_task_name = {'LevelWalking', 'StairAscent', 'StairDescent',"SlopeAscent", 'SlopeDescent', 'SitToStand', 'StandToSit'};
|
| task_name_num = numel(target_task_name);
|
| target_mot_col_idx = [8, 9, 10, 11, 13];
|
| target_spline_normal_num = 101;
|
|
|
| total_data_cell = cell(1,task_name_num);
|
| total_data_subject_cell = cell(1,task_name_num);
|
| mot_data_struct = RealDir(data_root);
|
| task_data_num = zeros(1,task_name_num);
|
|
|
| for subject_idx = 1:numel(mot_data_struct)
|
| subject_trial = 0;
|
| subject_name = mot_data_struct(subject_idx).name;
|
| subject_folder = fullfile(mot_data_struct(subject_idx).folder, mot_data_struct(subject_idx).name, 'JointAngle');
|
| for task_idx = 1:task_name_num
|
| task_name = target_task_name{task_idx};
|
| task_directory = fullfile(subject_folder, task_name);
|
| task_struct = RealDir(task_directory);
|
|
|
| for trial_idx = 1:numel(task_struct)
|
| trial_name = task_struct(trial_idx).name;
|
| trial_directory = fullfile(task_directory, trial_name);
|
| trial_struct = RealDir(trial_directory);
|
| for step_idx = 1:numel(trial_struct)
|
| task_data_num(task_idx) = task_data_num(task_idx)+1;
|
| if task_idx == 6
|
| subject_trial = subject_trial + 1;
|
| end
|
| end
|
| end
|
| end
|
| end
|
| task_data_idx = ones(1,task_name_num);
|
| for i=1:task_name_num
|
| total_data_cell{i} = zeros(target_spline_normal_num,numel(target_mot_col_idx), task_data_num(i));
|
| total_data_subject_cell{i} = zeros(task_data_num(i),4);
|
| end
|
|
|
| for subject_idx = 1:numel(mot_data_struct)
|
| subject_name = mot_data_struct(subject_idx).name;
|
| subject_folder = fullfile(mot_data_struct(subject_idx).folder, mot_data_struct(subject_idx).name, 'JointAngle');
|
| for task_idx = 1:task_name_num
|
| task_name = target_task_name{task_idx};
|
| task_directory = fullfile(subject_folder, task_name);
|
| task_struct = RealDir(task_directory);
|
|
|
| for trial_idx = 1:numel(task_struct)
|
| trial_name = task_struct(trial_idx).name;
|
| trial_directory = fullfile(task_directory, trial_name);
|
| trial_struct = RealDir(trial_directory);
|
| for step_idx = 1:numel(trial_struct)
|
| mot_file_directory = fullfile(trial_struct(step_idx).folder, trial_struct(step_idx).name);
|
| splined_mot_data = SplineMotData(mot_file_directory, target_mot_col_idx, target_spline_normal_num);
|
| total_data_cell{task_idx}(:,:,task_data_idx(task_idx)) = splined_mot_data;
|
| total_data_subject_cell{task_idx}(task_data_idx(task_idx),:) = [task_data_idx(task_idx), subject_idx, trial_idx, step_idx];
|
| task_data_idx(task_idx) = task_data_idx(task_idx) + 1;
|
| end
|
| end
|
| end
|
| fprintf("Loaded %s subject kinematics.\n", subject_name);
|
| end
|
|
|
| f=figure();
|
| for task_idx = 1:task_name_num
|
| temp_task_data = total_data_cell{task_idx};
|
| joint_num = size(temp_task_data,2);
|
| color_list = varycolor(joint_num);
|
| for joint_idx = 1:joint_num
|
| plot_idx = task_name_num*(joint_idx-1)+task_idx;
|
| subplot(joint_num,task_name_num,plot_idx);
|
| temp_joint_data = squeeze(temp_task_data(:,joint_idx,:));
|
| if joint_idx == 4
|
| temp_joint_data = -temp_joint_data;
|
| end
|
| plot_std_box(linspace(0,100,101), temp_joint_data',color_list(joint_idx,:));
|
|
|
| end
|
| end
|
|
|
| target_task_name = {"Level Walking", "Stair Ascent", "Stair Descent","Slope Ascent", "Slope Descent", "Sit-to-Stand", "Stand-to-Sit"};
|
| joint_name = {"Hip Flexion (Deg)", "Hip Adduction (Deg)", "Hip Int. Rot. (Deg)", "Knee Flexion (Deg)", "Ankle Dorsiflexion (Deg)"};
|
| figure(1);
|
| for i=1:7
|
| subplot(5,7,i);
|
| title(target_task_name{i}, 'FontSize',10, 'FontName','Times new roman');
|
| end
|
| for i=1:5
|
| subplot(5,7,7*(i-1)+1);
|
| ylabel(joint_name{i}, 'FontSize',10, 'FontName','Times new roman');
|
| end
|
| for i=1:7
|
| subplot(5,7,4*7+i);
|
| if (i<6)
|
| xlabel('Gait cycle (
|
| elseif (i==6)
|
| xlabel('Sit-to-stand (%)', 'FontSize',10, 'FontName','Times new roman');
|
| else
|
| xlabel('Stand-to-sit (%)', 'FontSize',10, 'FontName','Times new roman');
|
| end
|
| end
|
| f.Position = [422.500000000000 55.5000000000000 1147 835];
|
| end
|
|
|
| function EMGSignalVisualizer(data_root)
|
| target_task_name = {'LevelWalking', 'StairAscent', 'StairDescent',"SlopeAscent", 'SlopeDescent', 'SitToStand', 'StandToSit'};
|
| task_name_num = numel(target_task_name);
|
|
|
| total_data_cell = cell(1,task_name_num);
|
| data_struct = RealDir(data_root);
|
|
|
| for subject_idx = 1:numel(data_struct)
|
| subject_trial = 0;
|
| subject_name = data_struct(subject_idx).name;
|
| subject_folder = fullfile(data_struct(subject_idx).folder, data_struct(subject_idx).name, 'EMG');
|
| emg_processed_data = load(fullfile(subject_folder, 'ProcessedData.mat'));
|
|
|
| for task_idx = 1:task_name_num
|
| task_name = target_task_name{task_idx};
|
|
|
| for trial_idx = emg_processed_data.(task_name).AvailableTrialIdx
|
| trial_name = sprintf('Trial%02d', trial_idx);
|
| for step_idx = 1:emg_processed_data.(task_name).(trial_name).nSteps
|
| step_name = sprintf('Step%02d', step_idx);
|
| emg_step_table = emg_processed_data.(task_name).(trial_name).(step_name).EMGs_interpolated;
|
| if (subject_idx == 1 && task_idx == 1 && trial_idx == 1 && step_idx ==1)
|
| muscle_names = emg_step_table.Properties.VariableNames;
|
| end
|
| emg_step_array = table2array(emg_step_table);
|
| emg_step_array_reshaped = permute(emg_step_array, [1, 3, 2]);
|
| total_data_cell{task_idx} = cat(2, total_data_cell{task_idx}, emg_step_array_reshaped);
|
| if task_idx == 7
|
| subject_trial = subject_trial + 1;
|
| end
|
| end
|
| end
|
| end
|
| fprintf("Loaded %s subject EMG data.\n", subject_name);
|
| end
|
|
|
| f=figure();
|
|
|
| task_name_num = 7;
|
| plot_task_name = {'Level Walking', 'Stair Ascent', 'Stair Descent',"Slope Ascent", 'Slope Descent', 'Sit-to-Stand', 'Stand-to-Sit'};
|
|
|
| muscle_names_small = {'VL', 'RF', 'VM', 'TA', 'BF', 'ST', 'GM','GL','SM','SL','PL','PB'};
|
| muscle_num = numel(muscle_names);
|
| ymax_list = zeros(1,muscle_num);
|
| ymin_list = zeros(1,muscle_num);
|
| for task_idx = 1:task_name_num
|
| temp_task_data = total_data_cell{task_idx};
|
| color_list = varycolor(muscle_num);
|
| for muscle_idx = 1:muscle_num
|
| plot_idx = task_name_num*(muscle_idx-1)+task_idx;
|
| subplot(muscle_num,task_name_num,plot_idx);
|
| temp_joint_data = squeeze(temp_task_data(:,:,muscle_idx));
|
| plot_std_box(linspace(0,100,101), temp_joint_data',color_list(muscle_idx,:));
|
| ax = gca;
|
| yMax = ax.YLim(2);
|
| yMin = ax.YLim(1);
|
|
|
| if muscle_idx == 1
|
| title(plot_task_name{task_idx}, 'FontSize',10, 'FontName','Times new roman');
|
| end
|
| if muscle_idx == muscle_num
|
| if task_idx < 6
|
| xlabel('Gait cycle (
|
| elseif task_idx == 6
|
| xlabel('Sit-to-stand (%)', 'FontSize',10, 'FontName','Times new roman');
|
| else
|
| xlabel('Stand-to-sit (%)', 'FontSize',10, 'FontName','Times new roman');
|
| end
|
| end
|
| if task_idx == 1
|
| ylabel(muscle_names_small{muscle_idx}, 'FontSize',10, 'FontName','Times new roman', 'Color','k');
|
| end
|
| if ymax_list(muscle_idx) < yMax
|
| ymax_list(muscle_idx) = yMax;
|
| end
|
| if ymin_list(muscle_idx) > yMin
|
| ymin_list(muscle_idx) = yMin;
|
| end
|
| end
|
| end
|
| f.Position = [376.500000000000 2 1088.50000000000 1002];
|
| for muscle_idx =1:muscle_num
|
| for task_idx = 1:task_name_num
|
| plot_idx = task_name_num*(muscle_idx-1)+task_idx;
|
| subplot(muscle_num,task_name_num,plot_idx);
|
| ylim([ymin_list(muscle_idx), ymax_list(muscle_idx)]);
|
| end
|
| end
|
|
|
| han = axes(figure(1), 'Visible', 'off');
|
| han.YLabel.Visible = 'on';
|
| ylabel(han, 'Muscle activation', 'FontSize',15, 'FontName','Times new roman');
|
| han.YLabel.Position(1) = han.YLabel.Position(1) - 0.01;
|
| end
|
|
|
| function dir_struct = RealDir(directory)
|
| dir_struct = dir(directory);
|
| dir_struct = dir_struct(~ismember({dir_struct.name}, {'.', '..'}));
|
| end
|
|
|
| function splined_mot_data = SplineMotData(mot_filename, target_idx, target_spline_normal_num)
|
| mot_data = readMOT(mot_filename);
|
| target_mot_data = mot_data.data(:,target_idx);
|
| x = linspace(0, 1, mot_data.nr);
|
| y = target_mot_data';
|
| xq = linspace(0,1,target_spline_normal_num);
|
| splined_mot_data = spline(x, y, xq)';
|
| end
|
|
|
| function q = readMOT(fname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| fid = fopen(fname, 'r');
|
| if fid == -1
|
| error(['unable to open ', fname])
|
| end
|
|
|
|
|
| q.nr = 0;
|
| q.nc = 0;
|
| nextline = fgetl(fid);
|
| while ~strncmpi(nextline, 'endheader', length('endheader'))
|
| if strncmpi(nextline, 'datacolumns', length('datacolumns'))
|
| q.nc = str2num(nextline(findstr(nextline, ' ')+1 : length(nextline)));
|
| elseif strncmpi(nextline, 'datarows', length('datarows'))
|
| q.nr = str2num(nextline(findstr(nextline, ' ')+1 : length(nextline)));
|
| elseif strncmpi(nextline, 'nColumns', length('nColumns'))
|
| q.nc = str2num(nextline(findstr(nextline, '=')+1 : length(nextline)));
|
| elseif strncmpi(nextline, 'nRows', length('nRows'))
|
| q.nr = str2num(nextline(findstr(nextline, '=')+1 : length(nextline)));
|
| elseif strncmpi(nextline, 'inDegrees', length('inDegrees'))
|
| q.inDeg = nextline(findstr(nextline, '=')+1 : length(nextline));
|
| end
|
| nextline = fgetl(fid);
|
| end
|
|
|
| nextline = fgetl(fid);
|
| if (all(isspace(nextline)))
|
| nextline = fgetl(fid);
|
| end
|
| a=textscan(nextline,'%s','MultipleDelimsAsOne',1,'Delimiter',sprintf('\t'));
|
| q.labels = [a{:}]';
|
| % Process the data.
|
| % Note: transpose is needed since fscanf fills columns before rows.
|
| % Text = fscanf(fid, '
|
| Data = fscanf(fid, '%f', [q.nc, q.nr])';fclose(fid);
|
|
|
| if any(size(Data)~=[q.nr, q.nc]) || (q.nr==0 && q.nc==1)
|
| fid = fopen(fname, 'r');
|
| Text = fscanf(fid,'
|
| if any(strfind(Text,'1.#QNAN0000000'))
|
| Text=strrep(Text,'1.#QNAN0000000','0.000000000000');
|
| end
|
| if any(strfind(Text,'-1.#IND00000000'))
|
| Text=strrep(Text,'-1.#IND00000000','0.000000000000');
|
| end
|
| if any(strfind(Text,'-1.#INF00000000'))
|
| Text=strrep(Text,'-1.#INF00000000','0.000000000000');
|
| end
|
| if any(strfind(Text,'242373565591244840000000000000000000000000000000000000000000000000000000000000000.000000000000'))
|
| Text=strrep(Text,'242373565591244840000000000000000000000000000000000000000000000000000000000000000.000000000000','0.000000000000');
|
| end
|
|
|
| fid = fopen(fname, 'w');
|
| fprintf(fid,'%s',Text);fclose(fid);
|
| DataStart = strfind(Text,q.labels{end});
|
| DataStart=DataStart-1+min(strfind(Text(DataStart:end),char(13)))+1;
|
| DataText = Text(DataStart:end);
|
| LettersFound = intersect(regexp(DataText,'\w'),regexp(DataText,'\D'));
|
| if any(LettersFound)
|
| warning('letters found in data :')
|
| DataText(LettersFound)
|
| end
|
| DataText = strrep(DataText,DataText(LettersFound),'');
|
| Data = textscan(DataText, '%f');
|
| Data = Data{1};
|
| if length(Data) == q.nc*q.nr
|
| Data = reshape(Data,q.nc,q.nr)';
|
| else
|
| warning('not correct size of data specified in header, using size of Data vector and length of column labels')
|
| q.nc = length(q.labels);
|
| q.nr = length(Data)./q.nc;
|
| Data = reshape(Data,q.nc,q.nr)';
|
| end
|
| if any(size(Data)~=[q.nr q.nc])
|
| warning('File read error still'),beep
|
| end
|
| end
|
| q.data = Data;
|
| end
|
|
|
| function ColorSet=varycolor(NumberOfPlots)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| error(nargchk(1,1,nargin))
|
| error(nargoutchk(0, 1, nargout))
|
|
|
| if NumberOfPlots<1
|
| ColorSet=[];
|
| elseif NumberOfPlots==1
|
| ColorSet=[0 1 0];
|
| elseif NumberOfPlots==2
|
| ColorSet=[0 1 0; 0 1 1];
|
| elseif NumberOfPlots==3
|
| ColorSet=[0 1 0; 0 1 1; 0 0 1];
|
| elseif NumberOfPlots==4
|
| ColorSet=[0 1 0; 0 1 1; 0 0 1; 1 0 1];
|
| elseif NumberOfPlots==5
|
| ColorSet=[0 1 0; 0 1 1; 0 0 1; 1 0 1; 1 0 0];
|
| elseif NumberOfPlots==6
|
| ColorSet=[0 1 0; 0 1 1; 0 0 1; 1 0 1; 1 0 0; 0 0 0];
|
| else
|
|
|
| EachSec=floor(NumberOfPlots/5);
|
|
|
|
|
| ExtraPlots=mod(NumberOfPlots,5);
|
|
|
|
|
| ColorSet=zeros(NumberOfPlots,3);
|
|
|
|
|
|
|
| Adjust=zeros(1,5);
|
| for m=1:ExtraPlots
|
| Adjust(m)=1;
|
| end
|
|
|
| SecOne =EachSec+Adjust(1);
|
| SecTwo =EachSec+Adjust(2);
|
| SecThree =EachSec+Adjust(3);
|
| SecFour =EachSec+Adjust(4);
|
| SecFive =EachSec;
|
| for m=1:SecOne
|
| ColorSet(m,:)=[0 1 (m-1)/(SecOne-1)];
|
| end
|
| for m=1:SecTwo
|
| ColorSet(m+SecOne,:)=[0 (SecTwo-m)/(SecTwo) 1];
|
| end
|
|
|
| for m=1:SecThree
|
| ColorSet(m+SecOne+SecTwo,:)=[(m)/(SecThree) 0 1];
|
| end
|
|
|
| for m=1:SecFour
|
| ColorSet(m+SecOne+SecTwo+SecThree,:)=[1 0 (SecFour-m)/(SecFour)];
|
| end
|
| for m=1:SecFive
|
| ColorSet(m+SecOne+SecTwo+SecThree+SecFour,:)=[(SecFive-m)/(SecFive) 0 0];
|
| end
|
|
|
| end
|
| end
|
|
|
| function plot_std_box(x, data, color)
|
| data_mean = mean(data);
|
| data_std = std(data);
|
|
|
| xconf = [x x(end:-1:1)] ;
|
| yconf = [data_mean+data_std data_mean(end:-1:1)-data_std(end:-1:1)];
|
|
|
| plot(x,data_mean,'Color', color);
|
| hold on;
|
| p = fill(xconf,yconf, 'k');
|
| p.FaceAlpha = 0.1;
|
| p.EdgeColor = 'none';
|
|
|
| hold on;
|
| plot(x,data_mean,'Color',color, "LineWidth", 2);
|
| hold off;
|
| end
|
|
|