# 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>0 & x2<0) | (xin<0 & x2>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.

• What is the "mean fundamental frequency" of speech? – MBaz Feb 17 '18 at 15:56
• Why take the absolute value of the data? – AnonSubmitter85 Feb 17 '18 at 15:57
• How long is your data record? You cannot distinguish frequencies below approximately $\frac{1}{T}$ with $T$ the length of your data record. For an accurate estimate $T$ should be a multiple of this lower limit value. So for a fundamental of 1 Hz you will need more than 1 second of data (silence will not do). – user883521 Feb 17 '18 at 19:02
• @MBaz That is one of the things I could not understand about the dataset. As a reference- dataset information. It says "meanfun: average of fundamental frequency measured across acoustic signal", but by my understanding, a signal will have one fundamental frequency. – aadinaik Feb 18 '18 at 6:09
• @user883521 Since I am trying to just process various audio inputs, my audio signal length is variable. – aadinaik Feb 18 '18 at 6:14