-
Notifications
You must be signed in to change notification settings - Fork 2
/
rsa_prewhitenDist.m
41 lines (40 loc) · 1.26 KB
/
rsa_prewhitenDist.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
function dist_pw = rdm_prewhitenDist(dist,V,varargin)
%function dist_pw = rdm_prewhitenDist(dist,V)
% prewhitens the distances using the covariance matrix of the vector
% distances (V)
%
% INPUT: - dist: vector containing distances (1 x d) vectorized form of rdm - upper triangular, use rsa_vectorizeRDM)
% - V: covariance matrix of the vector distances (d x d)
%
% OUTPUT: - dist_pw: vector containing prewhitened distances (1 x d)
%
% VARARGIN: - type: 'multi' or 'uni' - multivariate or univariate prewhitening
% default multi
% Note: allows multiple distance matrices (e.g. k) prewhitened at the same time
% - dist (k x d)
% - V k cells of size d x d
% - output k x d
%
type = 'multi';
vararginoptions(varargin,{'type'});
% check the type and dimension of inputs
if iscell(V)
nRDM = size(V,2);
else
nRDM = 1;
tmp{1} = V;
clear V; V = tmp;
end
if size(dist,2) ~= size(V{1},1) || (size(V{1},1)~=size(V{1},2))
error('Incorrect dimensions of input arguments!');
end
dist_pw=zeros(nRDM,size(V{1},2));
% do the calculation
for i=1:nRDM
switch type
case 'multi'
dist_pw(i,:) = dist(i,:)*V{i}^(-1/2);
case 'uni'
dist_pw(i,:) = dist(i,:).*(diag(V{i}).^(-1/2))';
end
end