added distance based correlation function in matlab and java
This commit is contained in:
41
matlab/distCorr.m
Normal file
41
matlab/distCorr.m
Normal file
@@ -0,0 +1,41 @@
|
||||
% Autocorrelation for Points based on the distance between those points
|
||||
% data is the sensor data. one point per row.
|
||||
% lag_size is the number of required lags
|
||||
function [corr, lag] = distCorr(data, lag_size)
|
||||
|
||||
n = length(data);
|
||||
|
||||
%if lag size is bigger as data, then use data length - 1
|
||||
% -1 because the max. lag is -1 of the data length..
|
||||
if(lag_size >= n)
|
||||
lag_size = n - 1; %
|
||||
end
|
||||
|
||||
%init
|
||||
corr = zeros(lag_size + 1, 1); % +1, because the first index is lag 0.
|
||||
lag = (-lag_size:1:lag_size)';
|
||||
|
||||
%mean shift and l2 normalization
|
||||
%data = data - mean(data);
|
||||
%data = data / norm(data);
|
||||
|
||||
for j = 1:lag_size + 1 % +1, because the first index is lag 0.
|
||||
dist = zeros(n - abs(j), 1);
|
||||
idx = 1;
|
||||
|
||||
for i = j:n
|
||||
%x_i * x_i-(j-1)
|
||||
dist(idx) = norm(data(i, :) - data(i-(j-1), :));
|
||||
idx = idx + 1;
|
||||
end
|
||||
|
||||
corr(j) = geomean(dist);
|
||||
end
|
||||
|
||||
%mirror corr(2:512) and put it infront
|
||||
corr = [flipud(corr(2:end)); corr];
|
||||
|
||||
%to [0, 1]
|
||||
corr = ((corr .* -1) / max(corr)) + 1;
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user