Author Topic: Pitch in praat  (Read 16924 times)

Offline zaba

  • Serious Linguist
  • ****
  • Posts: 272
Re: Pitch in praat
« Reply #15 on: July 27, 2014, 01:30:20 AM »
Quote
It's really a misnomer for Praat to call it "pitch." What Praat calls "pitch" is f0. These are not the same; pitch is a psychoacoustic phenomenon, f0 is a property of periodic signals.
Very nice observation! Thank you. That really clears things up.

Quote
Praat's f0 estimates are based on autocorrelation. At each time point in a signal, an autocorrelation looks back in time over a range of lags. The lag that achieves the highest correlation is the wavelength of the fundamental frequency. You have to specify how far back you are willing to look; these provide hard bounds on the highest and the lowest fundamental frequency you can find. This is why Praat requires you to provide the pitch range.
This description looks very interesting - but I'm not sure what an "autocorrelation" is and what it means for f0 to estimates to be based on them. If you have a moment, I'd be so grateful if you could elaborate on this. I looked online and through several other linguistic resources, but to no avail. Perhaps its a technical term unfamiliar to my old dictionaries.

Offline jkpate

  • Forum Regulars
  • Linguist
  • *
  • Posts: 130
    • American English
    • jkpate.net
Re: Pitch in praat
« Reply #16 on: July 27, 2014, 04:05:05 AM »

Quote
Praat's f0 estimates are based on autocorrelation. At each time point in a signal, an autocorrelation looks back in time over a range of lags. The lag that achieves the highest correlation is the wavelength of the fundamental frequency. You have to specify how far back you are willing to look; these provide hard bounds on the highest and the lowest fundamental frequency you can find. This is why Praat requires you to provide the pitch range.
This description looks very interesting - but I'm not sure what an "autocorrelation" is and what it means for f0 to estimates to be based on them. If you have a moment, I'd be so grateful if you could elaborate on this. I looked online and through several other linguistic resources, but to no avail. Perhaps its a technical term unfamiliar to my old dictionaries.

The place to look for more information on this is not linguistics but digital signal processing, or, for a more cognitive/artificial intelligence perspective, computational audition. To understand autocorrelation, we first need to define a few terms, the most important of which are discrete-time signal and cross-correlation. A discrete-time signal is a sequence of numbers, called samples, that encodes a signal. For speech, each number expresses the air pressure at a particular time, and the discrete-time signal is a discrete approximation to the continuous speech signal. The sampling rate is the number of samples per second. The sampling rate is usually set fairly high to provide a good discrete approximation to the continuous signal. So, ultimately, a discrete-time signal is just a very long sequence of numbers.

The cross-correlation of a signal [latex]x[/latex] with a signal [latex]y[/latex] at a lag of [latex]\tau[/latex] is defined as:

[latex](x\star y)( \tau ) = \sum_{t=0}^{\infty} x(t) y(t-\tau) [/latex]

Remember that [latex]x[/latex] and [latex]y[/latex] are just sequences of numbers, and [latex]x(t)[/latex] is just the [latex]t^{\mbox{\scriptsize th}}[/latex] number in the sequence of numbers called [latex]x[/latex]. Because we are multiplying the signals together, this sum will be large when [latex]x[/latex] and [latex]y[/latex] are similar at a particular time lag. (if you are comfortable with linear algebra, note the similarity between this definition and the definition of a dot product.)

An autocorrelation is a cross-correlation where [latex]x[/latex] and [latex]y[/latex] are both the same signal, call it [latex]h[/latex]. An autocorrelation asks how similar a signal is to itself, at a particular time lag. If [latex]h[/latex] is perfectly periodic, with fundamental frequency [latex]f[/latex], then we have:

[latex]h(t) = h\left(t + \frac{1}{f} \right) = h\left(t - \frac{1}{f} \right) [/latex]

for all [latex]t[/latex]. (remember that frequency is the inverse of period). So a periodic signal is maximally similar, maximally correlated, to itself at a lag corresponding to the wavelength of the signal's fundamental frequency. Real speech is not perfectly periodic, because it changes over time, and the vocal folds don't maintain perfectly constant tension, but the same basic principle applies. We can get a pretty reliable estimate of the f0 by searching for the lag that produces the highest correlation over a restricted range of wavelengths corresponding to feasible f0.

I said Praat's approach was based on autocorrelation because Praat does more work to get more reliable estimates. The method just described assumes the signal is periodic (i.e. it never says that there is no f0), and is not specialized to the characteristics of human speech. For the first point, Praat incorporates a system of heuristics to decide when the correlation is too weak to have an f0. For the second point, Praat uses the autocorrelation to return multiple f0 candidates at each time, and then finds a smooth sequence of estimates to avoid implausibly large and jagged jumps in the f0 trace.

So the overall approach is something like this:

  • Decide to estimate the f0 at time [latex]t[/latex].
  • Extract a window of the signal around time [latex]t[/latex], producing windowed signal [latex]h[/latex].
  • Find a series of f0 candidates [latex]\tau[/latex] that are local maxima in [latex](h \star h)(\tau).[/latex].
  • Decide whether there is any f0 at time [latex]t[/latex], and compare the f0 candidates to the f0 candidates of nearby time points.

For the complete algorithm, have a look at Boersma (1993). It's a pretty old paper (by technology standards) but it doesn't look like much has changed, based on the options in the To Pitch (ac) window.


« Last Edit: July 27, 2014, 05:33:52 PM by jkpate »
All models are wrong, but some are useful - George E P Box

Offline zaba

  • Serious Linguist
  • ****
  • Posts: 272
Re: Pitch in praat
« Reply #17 on: July 27, 2014, 08:01:46 AM »
Wow, thanks a lot for the very thorough and detailed answer. Much obliged!

Offline zaba

  • Serious Linguist
  • ****
  • Posts: 272
Re: Pitch in praat
« Reply #18 on: July 27, 2014, 11:28:25 PM »
By the way, how does one best "eyeball" pitch in a spectrogram? Is there a way to do this, just to get a rough impression

Offline Daniel

  • Administrator
  • Experienced Linguist
  • *****
  • Posts: 2090
    • English
Re: Pitch in praat
« Reply #19 on: July 28, 2014, 06:22:00 AM »
The height of the dark band of voicing near the bottom. But eyeballing it probably won't distinguish anything but the most extreme contrasts.
Welcome to Linguist Forum! If you have any questions, please ask.

Offline zaba

  • Serious Linguist
  • ****
  • Posts: 272
Re: Pitch in praat
« Reply #20 on: July 30, 2014, 04:38:56 AM »
Quote
So the overall approach is something like this:

Decide to estimate the f0 at time .
Extract a window of the signal around time , producing windowed signal .
Find a series of f0 candidates  that are local maxima in .
Decide whether there is any f0 at time , and compare the f0 candidates to the f0 candidates of nearby time points.

@jkpate: Do you think I can do this with "least squares method"?

http://en.wikipedia.org/wiki/Least_squares

Offline jkpate

  • Forum Regulars
  • Linguist
  • *
  • Posts: 130
    • American English
    • jkpate.net
Re: Pitch in praat
« Reply #21 on: July 30, 2014, 05:15:41 AM »
Do which part? Least squares is just an approach to regression. Which variable would you be regressing against which other variable(s)?
All models are wrong, but some are useful - George E P Box

Offline zaba

  • Serious Linguist
  • ****
  • Posts: 272
Re: Pitch in praat
« Reply #22 on: July 30, 2014, 11:27:46 PM »
lesastsq function in python minimises the sum of squared components of the array returned by function foo([k,m]). It does this by altering values of parameters k and m (of the straight line equation k*x + m). Then, foo returns a difference between each f0 value and a straight line by f = k * t + m for that time, t.  Thoughts?
« Last Edit: July 31, 2014, 01:58:32 AM by zaba »

Offline jkpate

  • Forum Regulars
  • Linguist
  • *
  • Posts: 130
    • American English
    • jkpate.net
Re: Pitch in praat
« Reply #23 on: July 30, 2014, 11:59:28 PM »
Right, but I don't quite see how you want to use a linear regression. Are you wanting to use this to replace the step that compares f0 candidates to their neighbors to produce a smooth f0 trace? Or are you wanting to characterize the final output of Praat's approach by using the parameters of the best-fit line? (i.e. k and m in your example)
All models are wrong, but some are useful - George E P Box

Offline jkpate

  • Forum Regulars
  • Linguist
  • *
  • Posts: 130
    • American English
    • jkpate.net
Re: Pitch in praat
« Reply #24 on: July 31, 2014, 06:27:29 AM »
I want to be clear; I'm genuinely asking what you have in mind, I'm not suggesting or endorsing either idea. The first one is a Bad Idea. For example, in "easy" cases, the top f0 candidate will be the true f0, and the second f0 candidate will be the first harmonic. In such a case, the linear regression will split the difference, and decide that the f0 is 50% higher than it actually is. More generally, the f0 candidates are not random samples of some distribution centered on the true f0, but a linear regression would assume they are. Praat's approach of finding a best path that penalizes sharp jumps is a much better strategy. The second one is more reasonable, but you might need to go beyond a simple linear regression (again, depending on exactly what your goal is). A linear regression will not distinguish between an f0 trace that drops and then rises and an f0 trace that rises and then drops, for example. Coming up with the right amount of freedom in the functional form is not straightforward
All models are wrong, but some are useful - George E P Box

Offline zaba

  • Serious Linguist
  • ****
  • Posts: 272
Re: Pitch in praat
« Reply #25 on: August 06, 2014, 08:12:56 AM »
Before I elaborate, let me ask a question which may belie a surprising degree of ignorance:

How is the best candidate for f0 (AKA pitch) in praat calculated? I know that there is some kind of "goodness measurement" (what a strange term!) but am fuzzy on how that is determined. Is this something you know about?

Offline MalFet

  • Global Moderator
  • Serious Linguist
  • *****
  • Posts: 282
Re: Pitch in praat
« Reply #26 on: August 06, 2014, 09:52:47 AM »
How is the best candidate for f0 (AKA pitch) in praat calculated?

That's exactly what the autocorrelation function jkpate described in Reply #16 does.

Offline jkpate

  • Forum Regulars
  • Linguist
  • *
  • Posts: 130
    • American English
    • jkpate.net
Re: Pitch in praat
« Reply #27 on: August 06, 2014, 07:00:59 PM »
I think zaba is asking about the Praat implementation around autocorrelation, which uses the autocorrelation to get a set of candidates at each time point, and then, in step 4 above, compares those candidates to each other to get a smooth f0 trace. Praat uses a lowest cost path algorithm, described on pages 105 and 106 of the paper I linked to.

At each time point t, there will be n candidates, each with a correlation score from the autocorrelation. We can draw a line from each candidate at time t to each candidate at time t+1. This creates a lattice, and any path along these lines (that always moves forward in time) corresponds to one f0 trace by choosing one candidate at each time. We say that traveling along a line from a candidate at time t to a candidate at time t+1 is a transition. We can furthermore associate each transition with a cost, so that a transition from a very low f0 to a very high f0 at the next time point has a high cost. Paths with lower cost will then be smoother than paths with higher cost. Finding the lowest cost path in this kind of lattice can be solved easily with a well-known algorithm called the Viterbi algorithm (The wikipedia article implies that the Viterbi algorithm requires the costs to be probabilities, which is not true. The probabilistic setting is just the most common use case for Viterbi). Praat also includes "no voicing" as one of the candidates at each time step, and assigns a high cost to transitions between one of the f0 states to one of the unvoiced states. This voicing/devoicing cost prevents Praat from interspersing very short f0 stretches with very short voicing stretches.
« Last Edit: August 06, 2014, 07:07:49 PM by jkpate »
All models are wrong, but some are useful - George E P Box

Offline zaba

  • Serious Linguist
  • ****
  • Posts: 272
Re: Pitch in praat
« Reply #28 on: August 06, 2014, 11:15:29 PM »
Thanks. Must think before replying. You've given me a lot to chew on.