function [freq, ac] = autoc(signal,Fs)
freq = 0;
M = 6; %downsampling coefficient
Fs2 = Fs/M; %Fs after downsampling
downs = signal(1:M:length(signal)); %downsampling

ac = xcorr(downs);
[pks,locs,w,h] = findpeaks(ac);% removing the low signals which create errors
minp = 0.8*mean(h);
clear w
[pks,locs,w,h] = findpeaks(ac,'MinPeakheight',minp);% more precise peaks
ac_coef = 2*mean(w); %getting the coefficient of the autocorrelation
freq = Fs2/(ac_coef); %calculating the frequency from the coefficient

clear pks locs h
%disp(['Measured: ',num2str(frequency),' Hz on mic number: ',num2str(ind)]);
end

%Measuring directional characteristics of sound sources
%Made by Benjamin Nimmerrichter 2022/23 for BUT