function[maximumcorrelation] = corr(templates,input);

[row col] = size(templates);
input = fft(input);

% This is to find correlation when the note is right side up

 for i = 1:row
      output(i,:) = input*templates(i,:)';
      output(i,:) = ifft(output(i,:));
      output(i,:) = real(output(i,:));
end

 [maximumcorrelationup index]  = max(output);

 % This is to find the correlation when the note is flipside up
for i = 1:row
     output1(i,:) = input*conj(templates(i,:))';
     output1(i,:) = ifft(output1(i,:));
     output1(i,:) = real(output1(i,:));
end

 [maximumcorrelationdown index1]  = max(output1);

% Output the maximum correlation between the right side up or the flipside
% up.
 if maximumcorrelationup > maximumcorrelationdown
     maximumcorrelation = maximumcorrelationup;
 else
     maximumcorrelation = maximumcorrelationdown;
 end
 
    