39
Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung University Office: EC538 (03)5731877 [email protected] http://www.csie.nctu.edu.tw/~cmliu/Courses/Compression/

[CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Differential Encoding

C.M. LiuPerceptual Signal Processing Lab College of Computer ScienceNational Chiao-Tung University

Office: EC538(03)5731877

[email protected]

http://www.csie.nctu.edu.tw/~cmliu/Courses/Compression/

Page 2: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Idea2

Reducing the dynamic range/variance of coded sequence by encoding sample differences

Page 3: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Example Image Histogram3

99% ∈ [-31, 31] 5 bits/pixel (or less)

Page 4: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Basic Algorithm4

Consider sequence:6.2 9.7 13.2 5.9 8 7.4 4.2 1.8

Differences:6.2 3.5 3.5 −7.3 2.1 −0.6 −3.2 −2.4

Lossless encodingSimply coding the difference is sufficient to recover original

Lossy encodingQuantizer: −6 -4 -2 0 2 4 6

Quantized sequence: 6 4 4 −6 2 0 −4 −2

‘Lossless’ reconstruction: 6 10 14 8 10 10 6 4

QE: 0.2 −0.3 −0.8 −2.1 −2 −2.6 −1.8 −2.2Observation:

QE seems to grow over time—is it a coincidence?

Page 5: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Basic Algorithm (2)5

Consider: {xn} and dn = xn – xn-1

nnnn qddQd +== ][ˆ

001 ˆ,ˆˆˆ xxdxx nnn =+= −

011 xxd −=

1111 ][ˆ qddQd +==

11110001ˆˆ qxqdxdxx +=++=+=

122 xxd −=

2222 ][ˆ qddQd +==

212

2111212ˆˆ

qqxqdqxdxx

++=+++=+=

∑ =+=⇒

n

k knn qxx1

ˆ

Page 6: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Basic Algorithm (3)6

Alternative coding: 1ˆ −−= nnn xxd

011 xxd −=

1111 ][ˆ qddQd +==

11110001ˆˆ qxqdxdxx +=++=+=

122 x̂xd −=

2222 ][ˆ qddQd +==

22221212 ˆˆˆˆ qxqdxdxx +=++=+=

nnn qxx +=⇒ ˆ

Page 7: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Basic Algorithm: Example7

Page 8: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Differential Encoding Scheme8

Page 9: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Differential Pulse Code Modulation (DPCM)9

( )021 ˆ,,ˆ,ˆ xxxfp nnn K−−=

Page 10: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Prediction in DPCM10

Choice of f (·) affects σd, however

( )[ ]22nnd pxE −=σ

nnn qxx +=ˆ where qn depends on the variance of dn

Dependencies:

( ) ( )⋅→→→⋅ fxf nd ˆ2σ

Fine Quantization Assumption:Granularity is fine enough so thatThus,

nn xx ≈ˆ

( )021 ,,, xxxfp nnn K−−=

Page 11: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear Predictor11

N is caller order of the predictor∑= −=N

i inin xap1

ˆ

( ) ⎥⎦⎤⎢⎣⎡ −= ∑ = −

2

12 N

i inind xaxEσFind {ai}: minimize

( )[ ]

( )[ ] 02

02

1

2

111

2

=−−=∂∂

=−−=∂∂

−= −

−= −

NnN

i ininN

d

nN

i inind

xxaxEa

xxaxEa

σ

σ

M

Page 12: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear Predictor (2)12

where Rxx is the autocorrelation function:

∑∑

=

=

=

=−

=−

=−

N

i xxxxi

N

i xxxxi

N

i xxxxi

NRNiRa

RiRa

RiRa

1

1

1

)()(

)2()2(

)1()1(

M

( ) [ ]knnxx xxEkR +=

Page 13: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear Predictor (3)13

⎥⎥⎥⎥

⎢⎢⎢⎢

−−

−−

=

)0()2()1(

)2()0()1()1()1()0(

xxxxxx

xxxxxx

xxxxxx

RNRNR

NRRRNRRR

R

L

MOMM

L

L

)()()(

)1(1

kRkRNR

RP

a

aA xxxx

xx

xx

n

=−⎥⎥⎥

⎢⎢⎢

⎡=

⎥⎥⎥

⎢⎢⎢

⎡= MM

.1PRAPRA −=⇒=

Page 14: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear Predictor Example: Speech14

Page 15: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear Predictor Example (2)15

N = 1 a1 = 0.66N = 2 a1 = 0.596, a2 = 0.096N = 3 a1 = 0.577, a2 = -0.025, a3 = 0.204

( ) ∑ −

= +−=

kM

i kiixx xxkM

kR1

1

Page 16: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear Predictor Example: Laplacian Quantization

16

Uniform Step sizes4-level: 1st order: 0.75, 2nd order: 0.59, 3rd order: 0.438-level: 1st order: 0.3, 2nd order: 0.4, 3rd order: 0.5

( )

( )∑∑

∑∑

=

=

=

=

−=

−=

M

i ii

M

i i

M

i ii

M

i i

px

x

xx

x

12

12

12

12

)dB(SPER

ˆ)dB(SNR

Prediction Error

Page 17: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear Predictor Example: Performance17

SNR increases a lot for order 1 to order 2.

Page 18: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear Predictor Example: Reconstruction18

Original Reconstruction:8-level quantizer

Laplacian pdf3rd-order predictor

Although the reconstructed sequence looks like the original, notice that there is significant distortion in areas where the source output values are small.

Page 19: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Adaptive DPCM19

MotivationEven after DPCM, a lot of structure remains in the signalStructure more compression is possible

Residuals for 3rd-order predictor

Page 20: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Approaches Adaptive DPCM20

Adaptation can be applied toQuantizationPrediction

ObservationQuantization adaptation is independent of predictionPrediction adaptation quantization adaptation

Good prediction depends on good quantization

Page 21: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Adaptive Quantization in DPCM21

Forward adaptationParameters are estimated for each blockTransmitted to receiverOverall, this is inconvenient in DPCM as parameters are not explicitly available (due to feedback loop)

Backward adaptationEssentially, a version of the Jayant quantizerExample:

8-level quantizer, 3rd-order predictorM0 = 0.9, M1 = 0.9, M2 = 1.25, M3 = 1.75

Page 22: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Example: Adaptive Jayant DPCM22

Original

Non-adaptive

Jayant

Page 23: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Forward Adaptive Prediction: DPCM-APF23

Speech coding8000 sample/sec, 128 samples/block (16ms)

Image coding8x8 blocks

Autocorrelation coefficientsAssuming samples are zero outside block. l means the lth block.

)()(

0for1)(

0for,1)(

)()(

1)1(

)(

1)1(

)(

kRkR

kxxkM

kR

kxxkM

kR

lxx

lxx

lM

Mlikii

lxx

klM

Mlikii

lxx

−=

<−

=

>−

=

+−=+

−−=+ Rxx(k) can be efficiently

encoded usingpartial correlation (parcor)

coefficients

Page 24: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Backward Adaptive Prediction: DPCM-APB24

1st-order predictor

Adapts with sample

Replacing by to have the consistent result with decoder

1)(

11

2)(

1)1(

1 ˆ2 −+ +=

∂∂

−= nnnnnn xda

adaa αα

Nth-order predictor

jnnnn

jnnn

jn

j

d

xdaa

−+

−+

+=

−=

XAA ˆˆˆˆ

)()1(

)()1(

α

α

A.k.a. Least Mean Squared (LMS)

1)(

1)1(

1 ˆˆ−

+ += nnnn xdaa α

nd nd̂

Page 25: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Delta Modulation (DM)25

DM = DPCM w/ 1-bit quantizerSampling frequency

At least twice the highest frequency signal componentUsually, much higher

Page 26: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Linear DM Reconstruction26

Page 27: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Constant Factor Adaptive DM (CFDM)27

⎩⎨⎧

<−>

=0ˆif10ˆif1

n

nn d

ds⎩⎨⎧

≠Δ=Δ

=Δ−−

−−

112

111

ifif

nnn

nnnn ssM

ssM

211 21 <==< MMM

Page 28: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Second-Order CFDM 28

Examples for 2 samples prediction

Page 29: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Speech Coding29

Autocorrelation function for speech sampleIndicates a period of 47 samples

Pitch period

Need a separate component to take advantage of it

Page 30: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

DPCM with Pitch Predictor30

Also: Noise Feedback Coding (NFC)Shaping of QE such that most falls in high-amplitude periods

periodpitch,ˆ: =− ττnp xbP

Page 31: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

DPCM with Pitch Predictor Performance31

DPCM Residuals DPCM w/ Pitch PredictorResiduals

Page 32: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

G.72632

ITU recommendation for standard ADPCMSupersedes G.721 & G.723Rates: 40/32/24/16 kbits/secCompression w.r.t. 8-bit PCM:1.6:1, 2:1, 2.67:1, 4:1Quantizer levels: 2nb-1

midtread quantizer

Backward adaptive quantizationA version of the Jayant quantizerDescribed in terms of a scale factor αk

Q[dk/αk] * αk

Page 33: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

G.726 24kb Quantizer I/O Map33

Page 34: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

G.726: Quantizer Adaptation34

Based on y(k) = log2αk

Two factors:yu unlocked—to handle large fluctuations (e.g. speech)yl locked—for small ones like data transmission.

( ) )1()(1)1()()( 11 −−+−= kykakykaky lu

a1 depend on input variance: for speech it is close to 1

[ ] [ ] [ ] 51 2,logwhere,)1()1()( −− =⋅=⋅+−−= εεε MWIWkyky ku

62),()1()1()( −=+−−= γγγ kykyky ull

Page 35: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

G.726: Predictor35

Backward adaptable based onlast 2 reconstructed values

last 6 quantized differences

∑∑ = −−

= −− +=

6

1)1(2

1)1( ˆˆ

i ikk

ii ikk

ik dbxap

Simplified LMS:

Page 36: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Differential Image Coding36

Consider the predictor

… in combination with 2-bit uniform quantizer & AC1 bit/pixel encoding—compare to JPEG at the same rate

Diff coded: SNR=22dB, PSNR=31dB JPEG: SNR=33dB, PSNR=42dB

Page 37: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Differential Image Coding (2)37

Improved schemeRecursively indexed quantizer

Improved predictor

Diff coded: SNR=29dB, PSNR=38dB JPEG: SNR=33dB, PSNR=42dB

Page 38: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Remarks38

Prediction in DPCMAdaptive DPCMDelta ModulationSpeech CodingImage Coding

Page 39: [CSCI 6990-DC] 10: Differential Encodingcmliu/Courses/Compression/...Differential Encoding C.M. Liu Perceptual Signal Processing Lab College of Computer Science National Chiao-Tung

Homeworks39

P. 352 3, 4, 6