Octave: Finding the mean fundamental frequency given an audio signal I have an audio .wav file of someone's speech of which I want to find the mean fundamental frequency. Till now, all I have managed to do is load the data into a vector and (roughly) filter the silence out. I referred to a MATLAB example of finding the fundamental frequency, but it lies way out of the range of the mean fundamental frequencies which I have in a dataset I am referring to. The code on MATLAB is so-

function F0 = fundafreq(data)
  % Copied from matlab site
  F0 = 0;
  Fs = 48000;  % My sampling frequency
  [b0,a0] = butter(2,325/(Fs/2));
  xin = abs(data);
  xin = filter(b0,a0,xin);
  xin = xin-mean(xin);
  x2 = zeros(length(xin),1);
  x2(1:length(data)-1) = xin(2:length(data));
  zc = length(find((xin&gt;0 &amp; x2&lt;0) | (xin&lt;0 &amp; x2&gt;0)));
  F0 = 0.5*Fs*zc/length(data);
end


This gives me the fundamental frequency of around 40 Hz whereas my data set has mean fundamental frequencies not more than 1. I am only a beginner when it comes to digital signal processing, so I am not completely aware whether this code is giving me the answer or whether I need further calculations.

Also, it would be preferable if I could calculate this without needing the sampling frequency.
Your code appears to be looking for zero crossings of the rectified signal, which won’t work reliably if your signal has strong harmonics or overtones of the fundamental frequency within your filter’s passband.  Strong overtones of low frequencies is very common in audio data.

As a likely better alternative, look up pitch detection/estimation algorithms, such as autocorrelation, ASDF and AMDF