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);

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.

  • 1
    $\begingroup$ What is the "mean fundamental frequency" of speech? $\endgroup$
    – MBaz
    Feb 17 '18 at 15:56
  • $\begingroup$ Why take the absolute value of the data? $\endgroup$ Feb 17 '18 at 15:57
  • $\begingroup$ 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). $\endgroup$
    – user883521
    Feb 17 '18 at 19:02
  • $\begingroup$ @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. $\endgroup$
    – aadinaik
    Feb 18 '18 at 6:09
  • $\begingroup$ @user883521 Since I am trying to just process various audio inputs, my audio signal length is variable. $\endgroup$
    – aadinaik
    Feb 18 '18 at 6:14

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

  • 1
    $\begingroup$ Thanks! I'll look into that! Do you recommend any specific site/tutorial for this? $\endgroup$
    – aadinaik
    Feb 18 '18 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.