Reed Foster
Low-Latency Monophonic Pitch Detection in Digital Logic
Motivation
Pitch detection has a wide array of applications:
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
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
Boosting Pertinent Information
Peakiness:
Amplitude Thresholding:
Define the saliency of a frequency bin as the product of its peakiness score and amplitude threshold score
Kraft et. al. 2013
DFT Size and Latency
sampling rate of 48kHz:
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
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
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
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
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
More Plots: Effect of Phase Vocoder
fundamental frequency vs STFT bin index
index of bin containing fundamental (fbin = k*fsamp/N)
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
Sources
https://sethares.engr.wisc.edu/vocoders/Transforms.pdf
https://web.mit.edu/6.111/www/f2014/projects/trebawa_Project_Final_Report.pdf
http://dave.ucsc.edu/physics195/thesis_2009/m_peimani.pdf
https://www.mdpi.com/2079-9292/8/12/1533/htm
http://musicweb.ucsd.edu/~trsmyth/analysis/Harmonic_Product_Spectrum.html
Kraft. et. al. “The Tonalness Spectrum: Feature-based Estimation Of Tonal Components”, Proc. of the 16th Int. Conference on Digital Audio Effects (DAFx-13). 2013
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