Skip to main content

The Missing Guide to Linear Predictive Coding

Linear Predictive Coding (LPC) is a well-established method for analysis and lossy resynthesis of speech signals, dating back to at least the 1970's. Its primary purpose is data compression of speech for transmission, such as in the GSM, but it had important applications in speech synthesizers as well, most famously the Speak 'n' Spell. A niche application more relevant to this blog is the use of LPC as a musical effect to impart a lo-fi sound, additionally allowing transformations in pitch and timbre. Sonic Charge's VST plugin Bitspeek is one example of this.

LPC is a source-filter model where a pitched impulse train for voiced phonemes or noise for unvoiced phonemes is fed into a filter modeling the vocal tract. The filter creates a number of spectral peaks that mimic formants in the human voice. Reverse-engineering the filter from the input signal can be done with an elegant analysis formula that indirectly extracts the spectral envelope of the input signal and produces the coefficients for the filter.

LPC is a well-trodden method with many variants in the literature. However, there is a frustrating problem: every resource on LPC I've seen is missing at least one bit of information about how to actually implement the analysis and resynthesis. The pedagogy situation for LPC just isn't to my liking, so I decided to write my own guide that walks through everything from mathematics to implementation. I wrote this to explain LPC to myself as much as to other people.

Linear prediction

In a linear prediction filter of order \(N\) (often 10), every sample is modeled as a linear combination of the previous \(N\) samples:

\begin{equation*} y[t] = x[t] + \sum_{k = 1}^N a_k y[t - k] \end{equation*}

where \(a_k\) are filter coefficients.