%% project the input and template on another space that maximizies the correlation
%input: data (time*ch)
%frequency: data fundamental frequency
%harmonics: number of harmonics
function [out] = myCCA(input, resolution, frequency, harmonics)
%column major
template = zeros(size(input,1),harmonics*2);
time = size(input,1);
T = 1/time*resolution;                     % Sample time
L = size(input,1);                     % Length of signal
t = (0:L-1)*T;                % Time vector
index=1;
for harm=1:(harmonics)
    template(:,index) = sin(2*harm*pi*frequency*t);
    template(:,index+1) = cos(2*harm*pi*frequency*t);
    index= index+2;
end
[A,B,r,U,V] = canoncorr(input,template);
out = U;
end