Added normalized crosscorrelation function

This is to help Octave handle the MATLAB scripts
gr-droneid-3.8
David Protzman 2022-04-07 13:56:09 -04:00
rodzic 9b3e5d020f
commit 9b74213161
1 zmienionych plików z 19 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,19 @@
%% Computes the normalized cross correlation of two vectors
% Used https://www.researchgate.net/post/How-can-one-calculate-normalized-cross-correlation-between-two-arrays
% as the reference for this implementation
function [score] = normalized_xcorr(window_one, window_two)
assert(length(window_one) == length(window_two), "Windows must be equal length");
assert(isrow(window_one) || iscolumn(window_one), "Windows must be row/column vectors");
assert(isrow(window_two) || iscolumn(window_two), "Windows must be row/column vectors");
% Make both windows zero mean
window_one = window_one - mean(window_one);
window_two = window_two - mean(window_two);
% Cross correlate and get the average
xcorr_value = sum(window_one .* conj(window_two)) / length(window_one);
% Final step in normalization
score = xcorr_value / sqrt(var(window_one) * var(window_two));
end