-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimmx.m
34 lines (28 loc) · 849 Bytes
/
simmx.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
function M = simmx(A,B)
% M = simmx(A,B)
% calculate a sim matrix between specgram-like feature matrices A and B.
% size(M) = [size(A,2) size(B,2)]; A and B have same #rows.
% Omitting B gives simmx(A,A).
% 2003-03-15 [email protected]
% $Header: /Users/dpwe/matlab/columbiafns/RCS/simmx.m,v 1.2 2009/07/08 20:24:17 dpwe Exp $
% Copyright (c) 2003-2009 Dan Ellis <[email protected]>
% released under GPL - see file COPYRIGHT
if nargin < 2
B = A;
end
EA = sqrt(sum(A.^2));
EB = sqrt(sum(B.^2));
% Avoid div0
EA(EA==0) = 1;
EB(EB==0) = 1;
%ncA = size(A,2);
%ncB = size(B,2);
%M = zeros(ncA, ncB);
%for i = 1:ncA
% for j = 1:ncB
% % normalized inner product i.e. cos(angle between vectors)
% M(i,j) = (A(:,i)'*B(:,j))/(EA(i)*EB(j));
% end
%end
% this is 10x faster
M = (A'*B)./(EA'*EB);