-
Notifications
You must be signed in to change notification settings - Fork 0
/
performWaveformCorr.m
60 lines (41 loc) · 1.97 KB
/
performWaveformCorr.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function [wavecorr, dataidx] = performWaveformCorr(final, pcainfo, pcadata, pcaweights)
%PERFORMPCWAVEFORMCORR Correlation of PC scores against original waveforms
% Prasanna Sritharan, March 2022
%
% Based on PCA scripts by Prasanna Sritharan for ACLR hopping
% (published AnnBiomedEng 2022)
% User settings
user = getUserScriptSettings();
outpath = user.OUTPATH1;
limbs = user.LIMBS;
fprintf('Correlations of PC scores against original waveform data.\n');
fprintf('------------------------------------------------\n');
% Data tables
wavecorr = struct;
dataidx = struct;
% Limbs
labels = {'ik','id'};
alias = {'angle','moment'};
pcregexp = '(moment|angle)_(\w+)_PC\d+$';
for b=1:2
fprintf('\nWaveform correlations: %s LIMB\n', upper(limbs{b}));
% Perform correlation against waveforms
dataidx.(limbs{b}) = cell(length(final.(limbs{b}).labels), 2);
for s=1:length(final.(limbs{b}).labels)
fprintf('%s\n', final.(limbs{b}).labels{s});
% Get indices of original waveform data
tokens = regexpi(final.(limbs{b}).labels{s}, pcregexp, 'tokens');
dataidx.(limbs{b}){s, 1} = labels{strcmpi(alias, tokens{1}{1})};
dataidx.(limbs{b}){s, 2} = find(strcmpi(pcainfo.(limbs{b}).(dataidx.(limbs{b}){s, 1}).varnames, tokens{1}{2}), 1);
% Calculate waveform correlation coefficients
fprintf('---> Calculating correlation coefficients...\n');
wavecorr.(limbs{b}).coeffs(:, :, s) = weightedcorrs([final.(limbs{b}).data(:,s) squeeze(pcadata.(limbs{b}).(dataidx.(limbs{b}){s, 1})(:, :, dataidx.(limbs{b}){s, 2}))], pcaweights.(limbs{b}));
wavecorr.(limbs{b}).norms(:, s) = squeeze(wavecorr.(limbs{b}).coeffs(2:end,1,s)).^2;
end
end
% Save results
fprintf('\nSaving Waveform Correlation inputs and outputs...\n');
if ~exist(outpath,'dir'), mkdir(outpath); end
save(fullfile(outpath,'waveformcorr.mat'),'wavecorr','dataidx');
fprintf('------------------------------------------------\n');
end