1

I am new in signal processing and trying to calculate formant frequency features for different .wav files.

For calcuating formant frequency, I need three parameters values :

  • Linear Prediction Coefficients ( LPC )
  • root
  • angle

I am trying to calculate Linear Prediction Coefficients ( LPC ) using librosa.core.lpc in python. it takes two parameters:

librosa.core.lpc(y, order)

I have Y but I don't know how to calculate order, I have many .wav files and I have to set order to extract features from all the files. How to determine the order for all wav files to calculate LPC?

Next two things root and angle can be calculated easily like this :

 rts = numpy.roots(A)
 rts = [r for r in rts if numpy.imag(r) >= 0]

angz = numpy.arctan2(numpy.imag(rts), numpy.real(rts))

# Get frequencies.
Fs = spf.getframerate()
frqs = sorted(angz * (Fs / (2 * math.pi)))

Thank you in advance!

Aaditya Ura
  • 12,007
  • 7
  • 50
  • 88

1 Answers1

2

There's no exact science behind the order of LPC that should be used, there are though two rules of thumb:

  1. Twice the number of formants one expects to find, plus two. Explanation as provided in in Systematic errors in the formant analysis of steady-state vowels: each formant corresponds to a damped sinusoid that can be captured by a pair of roots with the correct frequency and damping (one of the roots is the complex conjugate of the other). The two extra coefficients are there ‘‘just in case’’ to absorb any leftover energy in the signal

  2. The sampling frequency in kHz. If Fs=16000 i.e. 16kHz, set order to 16.

The first method appears to be somewhat more popular and is described e.g. on the Mathworks page.

Note on optimisation

Of no relevance to the question, but I could not resist proposing two small tweaks to the code to make it more numpy:

import numpy as np
import librosa

A = librosa.core.lpc(y, 12)
rts = np.roots(A)
rts = rts[np.imag(rts) >= 0]
angz = np.arctan2(np.imag(rts), np.real(rts))
frqs = angz * fs / (2 *  np.pi)
frqs.sort()
Lukasz Tracewski
  • 10,794
  • 3
  • 34
  • 53