40
Linear Prediction Digital Audio Coding [email protected]

Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear PredictionDigital Audio Coding

[email protected]

Page 2: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Parametric Models

Assume that is onto ; invert with

param. datamodel

Synthesis

Analysis

Page 3: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Parametric ModelsQuantization

Analysis Synthesis

Page 4: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear Prediction Principles

Given a sequence of values ,find the best approximation of such that:

The prediction is linear and (strictly) causal.The number is the prediction order.The prediction error/residual is defined by:

Page 5: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear Prediction

+

Synthesis Filter (autoregressive)

Page 6: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear PredictionCovariance Method

Solve

with

Page 7: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear Prediction

Covariance Method:

Page 8: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear Prediction

Unique solution if is into:

Otherwise, one solution of:

provided by:

where

Page 9: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear Prediction

def lp(x, m): ”Linear predictor coefficients -- covariance method” n = len(x) A = array([x[m - 1 - arange(0, m) + i] for i in range(n-m)]) b = x[m:n] a = lstsq(A, b)[0] return a

With numpy.linalg least-square solution to :

Page 10: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

AutoCorrelation

The solutions are the same if we minimize:

Variant: treat the data as an infinite signal.Set if and minimize:

Page 11: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

AutoCorrelation

def lp(x, m, method="covariance"): ”Linear predictor coefficients - cov./autocor. methods” if method == "autocorrelation": x = r_[zeros(m), x, zeros(m)] n = len(x) A = array([x[m - 1 - arange(0, m) + i] for i in range(n-m)]) b = x[m:n] a = lstsq(A, b)[0] return a

(Implemented in the audio.lp module)

Page 12: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Method Selection

Covariance: - Fast computation, - Accurate solution.

Autocorrelation: - Even faster computation, - Stable synthesis filter.

Page 13: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms
Page 14: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Voice Audio DataYou Wanna Have Babies ?

8 kHz, mono.

20 ms frame

Page 15: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Voice Audio Data Short-Term Prediction

voice prediction error

order 16, autocorrelation

Page 16: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Analysis FilterFinite Impulse Response filter - FIR

class FIR(Filter): def __call__(self, input): output = self.a[0] * input + dot(self.a[1:], self.state) self.state = r_[input, self.state[:-1]] return output

FIR

Page 17: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

FIR ExampleMoving Average

>>> from audio.filters import FIR>>> ma = FIR(0.25 * ones(4))>>> ma(1.0)0.25>>> ma(2.0)0.75>>> ma([3.0, 4.0])array([1.5, 2.5])

Page 18: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

FIR for Linear Prediction>>> a = lp(data, order=m, ...)

Predictor>>> predictor = FIR(r_[0, a])

Analysis Filter>>> error = FIR(r_[1.0, -a])

Page 19: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Synthesis FilterAuto-Regressive filter - AR

class AR(Filter): def __call__(self, input): output = dot(self.a, self.state) + input self.state = r_[output, self.state[:-1]] return output

AR

Page 20: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

AR Example>>> from audio.filters import AR>>> ar = AR([0.5])>>> ar(1.0)1.0>>> ar(0.0)0.5>>> ar(0.0)0.25>>> ar([0.0, 0.0])array([ 0.125 , 0.0625])

Page 21: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

AR for Linear PredictionSynthesis Filter

>>> a = lp(data, m, ...)>>> synthesis = AR(a)>>> data = synthesis(error)

Page 22: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Transfer Function

are related by:

Given , the inputs and outputs belowfilter

FIR:

AR:

Page 23: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms
Page 24: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Frequency ResponseIt can be deduced from the transfer function:

The input signal

generates the output

or equivalently

with

Page 25: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms
Page 26: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms
Page 27: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Vocal Tract: Horn Model

Law of Motion

density

Compressibility

bulk modulus

: pressure

: air flow

: cross-section

Page 28: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Webster's EquationWave Velocity Impedance

If is constant:

Page 29: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Discrete Model

Reflection Coefficients:

Page 30: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Ladder/Lattice FiltersKelly-Lochbaum Junction

Compensate for delay and aenuation:

Page 31: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear Predictive CodingAR synthesis filters: laice filters oen replace register-based implementations.

- Levinson-Durbin and Schur algorithms are fast and provide directly the reflection coefficients that match the experimental data.

- Synthesis filter are stable iff . antize the area ratio and preserve stability:

Page 32: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms
Page 33: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms
Page 34: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Basic Pitch DetectionSolve where

offset

Page 35: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Autocorrelation Function

def ACF(data, frame_length): def normalize(x): return x / norm(x) m, n = frame_length, len(data) A = array([normalize(data[n-m-i:n-i]) for i in range(n-m+1)]) return dot(A, normalize(data[-m:]))

Page 36: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Long-Term Prediction

LTP Synthesis (AR) Filter

LTP residual

Page 37: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

Linear Predictive Coding

parameter estimation

stp ltpAnalysis Filter

stpltpSynthesis Filter

Page 38: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

"Pure" LPC

Analysis power

whitenoise Synthesis

Page 39: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

APC / RELP

Analysis

Synthesis

Adaptative Predictive CodingResidual-Excited Linear Prediction

Page 40: Linear Prediction · 2018. 3. 5. · Linear Predictive Coding AR synthesis filters: la ice filters o en replace register-based implementations. - Levinson-Durbin and Schur alg orithms

CELPCode-Excited Linear Prediction

Analysis Synthesismatch

codebook + gain

Synthesiscodebook + gain