星期四, 12月 28, 2006

Topic: 人體受外力牽拉後引發之姿勢反應_肌肉活化情形_rev.2

程式更新描述:
1. 加入各個牽拉強度下3次測試IEMG平均值及標準差計算,並將每位受試者各個測試以及各個牽拉強度(平均值與標準差)的IEMG計算結果輸出於同一檔案中,並以.xls檔案形式儲存於特定資料夾中。
2. Missing data的處理
(1)當原始EMG資料中任一塊肌肉訊號有所遺漏時,其計算出來的IEMG數值會以NaN顯示,程式可判斷'如果同一次測試中,有任一塊肌肉IEMG數值缺乏時,則該次測試所有肌肉的IEMG數值以-99表示,且皆不列入最後的平均值與標準差之計算'。
(2)另外,程式亦可判斷'當某次測試的原始EMG資料檔案不存在時,則該次測試所有肌肉的IEMG數值以-99表示,且皆不列入最後的平均值與標準差之計算'。

程式內容:

% IEMG6.m
% function: IEMG calculation (including mean and std of the value of each
% perturbation amplitude) for all trials of each subject
% onset data were retrived automatically
% if the file of raw data is not existed or the data of the measurments of a trial is not recorded, print all the IEMG data of that trial '-99'
% the IEMG results were output and saved as .xls
% raw_data: 1_Time(ms) 2_Fy 3_Mx 4_MGr 5_HAMr 6_PARAr 7_GMr 8_Pullonset
% range from (600ms prior to the pull onset) to (5000ms after the pull
% onset)
% baseline EMG:time interval between (500ms prior to the pull onset) to (150ms priot to the pull onset)
% IEMG:time interval between (150ms after the burst onset) to (500ms after the burst onset)

global EMGdata_path;
EMGdata_path = input('Please input the folder of the EMG data: [e.g.: D:\\Physical Therapy\\Graduate School\\Thesis\\Pilot study for Thesis\\Data\\Processed data for Matlab]','s');

if isempty(EMGdata_path)
EMGdata_path = 'D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Data\Processed data for Matlab';
end

cd(EMGdata_path);
Subject_information = textread('Subject_information.txt','%s');
Subject_amount = size(Subject_information,1);

EMGoutput_path = ['D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab'];
if ~exist(EMGoutput_path,'dir')
mkdir('D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab'); % creates the directory dirname in the current directory, if dirname represents a relative path.
end

for i = 1:Subject_amount

subjectoutput_folder = ['D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab','\',Subject_information{i}];
if ~exist(subjectoutput_folder,'dir') % dir 顯示目前目錄下的檔案名稱
mkdir('D:\Physical Therapy\Graduate School\Thesis\Pilot study for Thesis\Results\Data output from Matlab',Subject_information{i});
end

Onsetdata_xls = xlsread([EMGdata_path,'\',Subject_information{i}(1:4),'\','Time events for EMG and pullonset signials.xls'],'B3:F14'); % [pullonset,MGronset,HAMronset,PARAronset,GMronset]

data_name=0;
Onsetdata=0;
IEMG=0;

fprintf('\n %s\t\t rMG (V*ms)\t rHAM (V*ms)\t rPARA (V*ms)\t rGM (V*ms)\n',Subject_information{i}(1:4))

IEMG_fid = fopen([subjectoutput_folder,'\',Subject_information{i},'Integrated EMG','.xls'],'w');
fprintf(IEMG_fid,' \t rMG (V*ms)\t rHAM (V*ms)\t rPARA (V*ms)\t rGM (V*ms)\n');

for j = 1:4 % 4 perturbation amplitudes
for k = 1:3 % 3 trials
data_name = [Subject_information{i}(1:4),'C',num2str(1),'V',num2str(j),'R',num2str(k)];
Onsetdata = Onsetdata_xls((j-1)*3+k,:);
rawdata_file = [EMGdata_path,'\',Subject_information{i}(1:4),'\',data_name,'.xls'];
if exist(rawdata_file)
raw_data = xlsread([EMGdata_path,'\',Subject_information{i}(1:4),'\',data_name,'.xls'],'C19:J5618');
baseline = mean(raw_data(101:451,4:7));

rawIEMG(1) = (1/2*(raw_data((Onsetdata(2)-Onsetdata(1)+149),4)+raw_data((Onsetdata(2)-Onsetdata(1)+499),4))+sum(raw_data((Onsetdata(2)-Onsetdata(1)+150):(Onsetdata(2)-Onsetdata(1)+498),4))); % unit:V*ms
rawIEMG(2) = (1/2*(raw_data((Onsetdata(3)-Onsetdata(1)+149),5)+raw_data((Onsetdata(3)-Onsetdata(1)+499),5))+sum(raw_data((Onsetdata(3)-Onsetdata(1)+150):(Onsetdata(3)-Onsetdata(1)+498),5))); % unit:V*ms
rawIEMG(3) = (1/2*(raw_data((Onsetdata(4)-Onsetdata(1)+149),6)+raw_data((Onsetdata(4)-Onsetdata(1)+499),6))+sum(raw_data((Onsetdata(4)-Onsetdata(1)+150):(Onsetdata(4)-Onsetdata(1)+498),6))); % unit:V*ms
rawIEMG(4) = (1/2*(raw_data((Onsetdata(5)-Onsetdata(1)+149),7)+raw_data((Onsetdata(5)-Onsetdata(1)+499),7))+sum(raw_data((Onsetdata(5)-Onsetdata(1)+150):(Onsetdata(5)-Onsetdata(1)+498),7))); % unit:V*ms

IEMG = rawIEMG-baseline; % [rMG rHAM rPARA rGM]
if ~isempty(find(isnan(IEMG))) % 如果有其中一個參數出現missing,則那一個trial內所有的參數皆不列入最後的平均計算
IEMG(1,1:4) = -99;
end
else
IEMG(1,1:4) = -99;
end

IEMG_command = ['IEMG_cell(',num2str(k),',:) ={IEMG};'];
eval(IEMG_command)

fprintf(' %s\t %f\t %f\t %f\t %f\n',data_name,IEMG)

fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n',data_name,IEMG);
end % for k loop

IEMG_array = reshape([IEMG_cell{:}],4,3)';
for l = 1:4
if ~isempty((find(IEMG_array(:,l) ~= -99)))
mean_IEMG(1,l) = mean(IEMG_array(find(IEMG_array(:,l) ~= -99),l));
std_IEMG(1,l) = std(IEMG_array(find(IEMG_array(:,l) ~= -99),l));
else
mean_IEMG(1,1:4) = -99;
std_IEMG(1,1:4) = -99;
end
end

fprintf(IEMG_fid,' \n');
fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n','Mean',mean_IEMG);
fprintf(IEMG_fid,' %s\t %.3f\t %.3f\t %.3f\t %.3f\n','Std',std_IEMG);
fprintf(IEMG_fid,' \n');
end % for j loop

fclose(IEMG_fid);

end % for i loop

討論:
待完成事項:
1. 將程式一開始改為3種mode選擇:mode1-計算IEMG;mode2-單純繪出代表的EMG圖形;mode3-計算肌肉活化程度(IEMG)與干擾強度之相關性並繪圖。

沒有留言: