1 of 14

Reed Foster

Low-Latency Monophonic Pitch Detection in Digital Logic

2 of 14

Motivation

Pitch detection has a wide array of applications:

  • assistive device for performers
    • create harmonization/backing vocals programmatically
    • autotune
  • speech analysis
    • formant/overtone analysis can be useful in recognizing vowels
  • digital logic is cool

3 of 14

How to Do Pitch Detection

Time-domain (Autocorrelation)

Frequency-domain (Spectrum)

Time-domain (Zero-crossing)

lag peaks indicate periodicity of underlying signal

peaks of a 180 Hz sawtooth waveform, sampled at 48kHz with a DFT size of 1024

first peak indicates fundamental frequency

wikimedia commons: Acf_new.svg

4 of 14

Boosting a Weak Fundamental:�Harmonic Product Spectrum

f0

2f0

3f0

...

X

Original:

Overtones are integer multiples of fundamental*

peak where harmonic overtones overlap

f0 is the bin frequency with largest magnitude!

f0

*this approximation is generally close enough for lowest overtones in the human voice

3x Decimation

2x Decimation

5 of 14

Boosting Pertinent Information

Peakiness:

  • high score for frequency bins with higher amplitude than their neighbors

Amplitude Thresholding:

  • tonal bins (bins with high SNR) receive a higher score

Define the saliency of a frequency bin as the product of its peakiness score and amplitude threshold score

Kraft et. al. 2013

6 of 14

DFT Size and Latency

sampling rate of 48kHz:

  • 1024-point DFT -> 21ms sampling latency, 46.88Hz/bin
  • 4096-point DFT -> 85ms sampling latency, 11.72Hz/bin

latency of digital logic is low enough (~100μs) that the only relevant metric is sampling latency

1024-point DFT gives a decent tradeoff between latency and frequency resolution (only 21ms lag)

Improve frequency resolution by using DFT phase information

7 of 14

Improving Frequency Resolution:�Phase Vocoder

47Hz/bin is very poor resolution for making a voice-controlled synth

Use relative phase information between adjacent STFT windows

https://sethares.engr.wisc.edu/vocoders/phasevocoder.html

Select a value of n which brings f close to the center frequency of the bin containing the fundamental

8 of 14

Hardware

FPGA - field programmable gate array

can configure a custom digital circuit to�run in real time

for example:�~1-10ns per clock cycle -> 1024-point FFT takes around 75μs, sine of phasor takes around 250ns

this is overkill for this simple of a pitch detection scheme, but allows for extension that uses more advanced signal processing techniques which may introduce additional latency in a conventional computation paradigm

9 of 14

Debugging and Intermediate Signals

Plots are from direct measurement of signals inside the device using a logic analyzer

input signal�(raw 24-bit value)

windowed signal�(1024-point Hamming window)

re/im part of DFT

10 of 14

More Plots: Harmonic Product Spectrum (HPS)

X

hps bin magnitudes (shifted left by 2)

2x decimated shifted magnitude spectrum

shifted magnitude spectrum

*spectra are shifted to prevent selection of fundamentals below 90Hz

11 of 14

More Plots: Effect of Phase Vocoder

fundamental frequency vs STFT bin index

index of bin containing fundamental (fbin = k*fsamp/N)

12 of 14

Effect of Weak Fundamental

sawtooth (test waveform) has a lot of harmonics and a very strong fundamental, so the harmonic product spectrum technique works very well

doesn’t perform well with harsh vocals

need to boost relevant peaks before computing harmonic product spectrum to remove inharmonic overtones and high frequency noise

13 of 14

Sources

14 of 14

Peak Selection

The fundamental will be the first “peak” in the spectrum

It’s mostly straightforward to qualitatively decide where the first peak is, but how to do it quantitatively so we can apply an algorithm?

An idea:�Start from frequency bin zero, and skip bins until you find a bin with a large enough DFT magnitude and high enough saliency

  • the trick is tuning these two thresholds for “high enough”
  • thresholds were found through trial-and-error