[fileName, folder] = uigetfile('.xlsx', 'Please select the raw Excel data file with the subject numbers'); if ispc sep = '\'; else sep = '/'; end [SPD, HN, SZ] = importExcelSubNumbers(folder, fileName); % calls a little function I wrote to use an Excel file to store the numbers of valid subjects. textFileFolder = [folder sep 'Text files' sep ]; %% Cycle through groups for g = 1:3 switch g case 1 group = 'HN'; case 2 group = 'SPD'; case 3 group = 'SZ'; end if strcmp(group, 'SPD') subnums = SPD; elseif strcmp(group, 'HN') subnums = HN; elseif strcmp(group, 'SZ') subnums = SZ; else error('Group must be SPD,HN, or SZ!') end %% Make name strings and load text files for s = 1:length(subnums) %% for condition = 1:4 switch condition case 1 cond = 'EOOB'; case 2 cond = 'EOCB'; case 3 cond = 'ECOB'; case 4 cond = 'ECCB'; end sub = num2str((subnums(s))); %% Make file paths for each subject. filenameCoP = [textFileFolder sub '_' cond 'COP.txt']; % make file path filenameRaw = [textFileFolder sub '_' cond '_RAW.txt']; resultsFolder = [folder sep 'RESULTS' sep group sep sub] ; if ~exist(resultsFolder, 'dir') mkdir(resultsFolder); end resultsFileName = [resultsFolder sep sub '_' group '_' cond '_RESULTS.mat']; %% if ~exist(resultsFileName, 'file') [CoPx, CoPy, Mx, My, Fx, Fy] = CalcCoPandMoment(filenameCoP, filenameRaw); % call function to extract data from text files data.weight = CalcWeight(filenameRaw); %% Preprocess data ML_dec = decimate(CoPx, 4); % donwsample to 50 Hz - this depends on your original frequency obviously! If it's 1000 Hz, you'll downsample by 20. AP_dec = decimate(CoPy, 4); data.Fx_dec = decimate(Fx, 4); data.Fy_dec = decimate(Fy, 4); data.Mx_dec = decimate(Mx, 4); data.My_dec = decimate(My, 4); % %% Center on first 100 data points ML_dec = ML_dec - mean(ML_dec(1:100)); AP_dec = AP_dec - mean(AP_dec(1:100)); data.ML_dec = ML_dec*10; % convert from cm to mm - if your data is in M you'll need to change this. data.AP_dec = AP_dec*10; % convert from cm to mm %% Butterworth filter on the data to smooth out artifacts Fs = 50; % sampling rate Hz = 18; % cutoff frequency for filter Wn = Hz/(Fs/2); [b,a]=butter(4, Wn, 'low'); % low-pass order 4 Butterworth filter data.filtAP=filter(b,a,data.AP_dec); data.filtML=filter(b,a, data.ML_dec); data.filtFx=filter(b,a,data.Fx_dec); data.filtFy=filter(b,a, data.Fy_dec); data.filtMx=filter(b,a,data.Mx_dec); data.filtMy=filter(b,a, data.My_dec); %% Calculate path for i = 2:length(data.filtAP) Path(i) = sqrt((data.filtML(i)- data.filtML(i-1))^2+(data.filtAP(i)- data.filtAP(i-1))^2); end results.pathTotal = sum(Path); %% Calculate sway areas [results.area,results.axes,results.angles,results.ellip] = ellipse (data.filtML, data.filtAP, [], .95); % don't plot %% Save results save(resultsFileName, 'data', 'results') end end end end