Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1...

83
6.003: Signals and Systems Sampling and Quantization November 29, 2011 1

Transcript of Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1...

Page 1: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

6.003: Signals and Systems

Sampling and Quantization

November 29, 2011 1

Page 2: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Last Time: Sampling

Sampling allows the use of modern digital electronics to process,

record, transmit, store, and retrieve CT signals.

• audio: MP3, CD, cell phone

• pictures: digital camera, printer

• video: DVD

• everything on the web

2

Page 3: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

x[n] Impulse

Reconstruction

xp(t) =∑x[n]δ(t− nT )

xr(t)

LPF

−ωs2

ωs2

ωT

x[n] xr(t)Impulse

Reconstruction

xp(t) =∑x[n]δ(t− nT )

LPF

Last Time: Sampling Theory

Sampling

x(t) → x[n] = x(nT )

Impulse Reconstruction

2π Bandlimited Reconstruction ωs =

T

ωsSampling Theorem: If X(jω) = 0 ∀ |ω| > then xr(t) = x(t).2

3

Page 4: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Aliasing

−ωs ωsFrequencies outside the range < ω < alias.2 2

ω

Xp(jω) = 12π (X(j · ) ∗ P (j · ))(ω)

−ωs2

ωs2

1T

ω

P (jω)

−ωs ωs

2πT

ω

X(jω)1

4

Page 5: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Anti-Aliasing Filter

To avoid aliasing, remove frequency components that alias before

sampling.

−ωs2

ωs2

ω1

×−ωs

2ωs2

ωT

x(t)

p(t)

xr(t)xp(t)

ReconstructionFilter

Anti-aliasingFilter

5

Page 6: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Anti-Aliasing

−ωs ωsRemove frequencies outside the range < ω < before sampling 2 2 to avoid aliasing.

ω

Xp(jω) = 12π (X(j · ) ∗ P (j · ))(ω)

−ωs2

ωs2

1T

ω

P (jω)

−ωs ωs

2πT

ω

Anti-aliased X(jω)

6

Page 7: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Today

Digital recording, transmission, storage, and retrieval requires dis­

crete representations of both time (e.g., sampling) and amplitude.

• audio: MP3, CD, cell phone

• pictures: digital camera, printer

• video: DVD

• everything on the web

Quantization: discrete representations for amplitudes

7

Page 8: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantization

We measure discrete amplitudes in bits.

­1­1

0

0

1

1Input voltage

Outputvoltage 2 bits 3 bits 4 bits

00

01

10

0 0.5 1­1

0

1

Time (second)0 0.5 1

Time (second)0 0.5 1

Time (second)

­1 0 1Input voltage

­1 0 1Input voltage

Bit rate = (# bits/sample)×(# samples/sec)

8

Page 9: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

We hear sounds that range in amplitude from 1,000,000 to 1.

How many bits are needed to represent this range?

1. 5 bits

2. 10 bits

3. 20 bits

4. 30 bits

5. 40 bits

9

Page 10: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

How many bits are needed to represent 1,000,000:1?

bits

1 2 3 4 5 6 7 8 9

10 11 12 13 14 15 16 17 18 19 20

range

2 4 8

16 32 64

128 256 512

1, 024 2, 048 4, 096 8, 192

16, 384 32, 768 65, 536

131, 072 262, 144 524, 288

1, 048, 576 10

Page 11: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

We hear sounds that range in amplitude from 1,000,000 to 1.

How many bits are needed to represent this range? 3

1. 5 bits

2. 10 bits

3. 20 bits

4. 30 bits

5. 40 bits

11

Page 12: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantization Demonstration

Quantizing Music

• 16 bits/sample

• 8 bits/sample

• 6 bits/sample

• 4 bits/sample

• 3 bits/sample

• 2 bit/sample

J.S. Bach, Sonata No. 1 in G minor Mvmt. IV. Presto

Nathan Milstein, violin

12

Page 13: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantization

We measure discrete amplitudes in bits.

­1­1

0

0

1

1Input voltage

Outputvoltage 2 bits 3 bits 4 bits

00

01

10

0 0.5 1­1

0

1

Time (second)0 0.5 1

Time (second)0 0.5 1

Time (second)

­1 0 1Input voltage

­1 0 1Input voltage

2 channels× 16 bits

sample× 44, 100 samples

sec× 60 sec

min× 74 min ≈ 6.3 G bits

≈ 0.78 G bytes

Example: audio CD

13

Page 14: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images

Converting an image from a continuous representation to a discrete

representation involves the same sort of issues.

This image has 280 × 280 pixels, with brightness quantized to 8 bits.

14

Page 15: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images

8 bit image 7 bit image

15

Page 16: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images

8 bit image 6 bit image

16

Page 17: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images

8 bit image 5 bit image

17

Page 18: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images

8 bit image 4 bit image

18

Page 19: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images

8 bit image 3 bit image

19

Page 20: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images

8 bit image 2 bit image

20

Page 21: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images

8 bit image 1 bit image

21

Page 22: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

What is the most objectionable artifact of coarse quantization?

8 bit image 4 bit image

22

Page 23: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Dithering

One very annoying artifact is banding caused by clustering of pixels

that quantize to the same level.

Banding can be reduced by dithering.

Dithering: adding a small amount (±12 quantum) of random noise to

the image before quantizing.

Since the noise is different for each pixel in the band, the noise

causes some of the pixels to quantize to a higher value and some to

a lower. But the average value of the brightness is preserved.

23

Page 24: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Dither

7 bit image 7 bits with dither

24

Page 25: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Dither

6 bit image 6 bits with dither

25

Page 26: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Dither

5 bit image 5 bits with dither

26

Page 27: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Dither

4 bit image 4 bits with dither

27

Page 28: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Dither

3 bit image 3 bits with dither

28

Page 29: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Dither

2 bit image 2 bits with dither

29

Page 30: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Dither

1 bit image 1 bit with dither

30

Page 31: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

What is the most objectionable artifact of dithering?

3 bit image 3 bit dithered image

31

Page 32: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

What is the most objectionable artifact of dithering?

One annoying feature of dithering is that it adds noise.

32

Page 33: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantization Schemes

Example: slowly changing backgrounds.

Quantization: y = Q(x)

Quantization with dither: y = Q(x + n)

33

Page 34: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

What is the most objectionable artifact of dithering?

One annoying feature of dithering is that it adds noise.

Robert’s technique: add a small amount (±12 quantum) of random

noise before quantizing, then subtract that same amount of random

noise.

34

Page 35: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantization Schemes

Example: slowly changing backgrounds.

Quantization: y = Q(x)

Quantization with dither: y = Q(x + n)

Quantization with Robert’s technique: y = Q(x + n) − n

35

Page 36: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Robert’s Method

7 bits with dither 7 bits with Robert’s method

36

Page 37: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Robert’s Method

6 bits with dither 6 bits with Robert’s method

37

Page 38: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Robert’s Method

5 bits with dither 5 bits with Robert’s method

38

Page 39: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Robert’s Method

4 bits with dither 4 bits with Robert’s method

39

Page 40: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Robert’s Method

3 bits with dither 3 bits with Robert’s method

40

Page 41: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Robert’s Method

2 bits with dither 2 bits with Robert’s method

41

Page 42: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images with Robert’s Method

1 bits with dither 1 bit with Robert’s method

42

Page 43: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images: 3 bits

8 bits 3 bits

dither Robert’s

43

Page 44: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images: 2 bits

8 bits 2 bits

dither Robert’s

44

Page 45: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Quantizing Images: 1 bit

8 bits 1 bit

dither Robert’s

45

Page 46: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Progressive Refinement

Trading precision for speed.

Start by sending a crude representation, then progressively update

with increasing higher fidelity versions.

46

Page 47: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling (Resampling)

DT sampling is much like CT sampling.

×x[n] xp[n]

p[n] =∑k δ[n− kN ]

n

xp[n]

0

n

x[n]

0

n

p[n]

0

47

Page 48: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

jΩ).As in CT, sampling introduces additional copies of X(e

×x[n] xp[n]

p[n] =∑k δ[n− kN ]

0 2π3

4π3

2π−2π3

−4π3

−2π

13

Ω

Xp(ejΩ)

0 2π−2π

1

Ω

X(ejΩ)

0 2π3

4π3

2π−2π3

−4π3

−2π

2π3

Ω

P (ejΩ)

48

Page 49: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

Sampling a finite sequence gives rise to a shorter sequence.

n

xb[n]

0

n

xp[n]

0

n

x[n]

0

−jΩn −jΩn −jΩk/3 jΩ/3)Xb(ejΩ) = xb[n]e = xp[3n]e = xp[k]e = Xp(en n k

49

Page 50: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

But the shorter sequence has a wider frequency representation.

0 2π3

4π3

2π−2π3

−4π3

−2π

13

Ω

Xb(ejΩ) = Xp(ejΩ/3)

0

0 2π−2π

13

Ω

Xp(ejΩ)

2π−2π

1

Ω

X(ejΩ)

0

50

Page 51: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

51

Page 52: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

52

Page 53: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

53

Page 54: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

54

Page 55: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

55

Page 56: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

56

Page 57: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

57

Page 58: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

Insert zeros between samples to upsample the images.

n

xb[n]

0

n

xp[n]

0

n

x[n]

0

−jΩn −jΩn −jΩk/3 jΩ/3)Xb(ejΩ) = xb[n]e = xp[3n]e = xp[k]e = Xp(en n k

58

∑ ∑ ∑

Page 59: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

Then filter out the additional copies in frequency.

0 2π3

4π3

2π−2π3

−4π3

−2π

13

Ω

Xb(ejΩ) = Xp(ejΩ/3)

0

0 2π−2π

13

Ω

Xp(ejΩ)

2π−2π

1

Ω

X(ejΩ)

0

59

Page 60: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling: Progressive Refinement

60

Page 61: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling: Progressive Refinement

61

Page 62: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling: Progressive Refinement

62

Page 63: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling: Progressive Refinement

63

Page 64: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling: Progressive Refinement

64

Page 65: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Discrete-Time Sampling

65

Page 66: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Perceptual Coding

Quantizing in the Fourier domain: JPEG.

66

Page 67: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

Example: JPEG (“Joint Photographic Experts Group”) encodes im­

ages by a sequence of transformations:

• color encoding

• DCT (discrete cosine transform): a kind of Fourier series

• quantization to achieve perceptual compression (lossy)

• Huffman encoding: lossless information theoretic coding

We will focus on the DCT and quantization of its components.

• the image is broken into 8 × 8 pixel blocks

• each block is represented by its 8 × 8 DCT coefficients

• each DCT coefficient is quantized, using higher resolutions for

coefficients with greater perceptual importance

67

Page 68: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

Discrete cosine transform (DCT) is similar to a Fourier series, but

high-frequency artifacts are typically smaller.

Example: imagine coding the following 8 × 8 block.

For a two-dimensional transform, take the transforms of all of the

rows, assemble those results into an image and then take the trans­

forms of all of the columns of that image.

68

Page 69: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

Periodically extend a row and represent it with a Fourier series.

x[n] = x[n+ 8]

n0 8

There are 8 distinct Fourier series coefficients. 1 2π−jkΩ0n ak = x[n]e ; Ω0 = 8 8

n=<8>

69

Page 70: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

DCT is based on a different periodic representation, shown below.

y[n] = y[n+ 16]

n0 16

70

Page 71: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

Which signal has greater high frequency content?

x[n] = x[n+ 8]

n0 8

y[n] = y[n+ 16]

n0 16

71

Page 72: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

The first signal, x[n], has discontinuous amplitude. The second sig­

nal, y[n] is not discontinuous, but has discontinuous slope.

x[n] = x[n+ 8]

n0 8

y[n] = y[n+ 16]

n0 16

The magnitude of its Fourier series coefficients decreases faster with

k for the second than for the first.

72

Page 73: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

Which signal has greater high frequency content? x[n]

x[n] = x[n+ 8]

n0 8

y[n] = y[n+ 16]

n0 16

73

Page 74: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

Periodic extension of an 8 × 8 pixel block can lead to a discontinuous

function even when the “block” was taken from a smooth image.

original row

n0

8 pixel ”block”

n0

x[n] = x[n+ 8]

n0 8

74

Page 75: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

Periodic extension of the type done for JPEG generates a continuous

function from a smoothly varying image.

original row

n0

8 pixel ”block”

n0

y[n] = y[n+ 16]

n0 16

75

Page 76: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

Although periodic in N = 16, y[n] can be represented by just 8 distinct

DCT coefficients.

y[n] = y[n+ 16]

n0 16

bk = 7

n=0

y[n] cos

πk N

n + 1 2

This results because y[n] is symmetric about n = −12 , and this sym­

metry introduces redundancy in the Fourier series representation.

Notice also that the DCT of a real-valued signal is real-valued.

76

Page 77: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

The magnitudes of the higher order DCT coefficients are smaller

than those of the Fourier series.

−3−2−1 0 1 2 3 4 m−3−2−1

01234n Fourier series

m

|ak|

0 1 2 3 4 5 6 7 m01234567n DCT

m

bk

77

Page 78: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

Humans are less sensitive to small deviations in high frequency com­

ponents of an image than they are to small deviations at low frequen­

cies. Therefore, the DCT coefficients are quantized more coarsely

at high frequencies.

Divide coefficient b[m, n] by q[m, n] and round to nearest integer.

q[m, n] m →

16 11 10 16 24 40 51 61

12 12 14 19 26 58 60 55

14 13 16 24 40 57 69 56

n 14 17 22 29 51 87 80 62

↓ 18 22 37 56 68 109 103 77

24 35 55 64 81 104 113 92

49 64 78 87 103 121 120 101

72 92 95 98 112 100 103 99 78

Page 79: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

Which of the following tables of q[m, n] (top or bottom)

will result in higher “quality” images?

q[m, n] m → 16 11 10 16 24 40 51 61 12 12 14 19 26 58 60 55 14 13 16 24 40 57 69 56

n 14 17 22 29 51 87 80 62 ↓ 18 22 37 56 68 109 103 77

24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 100 103 99

q[m, n] m → 32 22 20 32 48 80 102 122 24 24 28 38 52 116 120 110 28 26 32 48 80 114 139 112

n 28 34 44 58 102 174 160 124 ↓ 36 44 74 112 136 218 206 154

48 70 110 128 162 208 226 194 98 128 156 174 206 256 240 202 144 184 190 196 224 200 206 198

79

Page 80: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

Check Yourself

Which of the following tables of q[m, n] (top or bottom)

will result in higher “quality” images? top

q[m, n] m → 16 11 10 16 24 40 51 61 12 12 14 19 26 58 60 55 14 13 16 24 40 57 69 56

n 14 17 22 29 51 87 80 62 ↓ 18 22 37 56 68 109 103 77

24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 100 103 99

q[m, n] m → 32 22 20 32 48 80 102 122 24 24 28 38 52 116 120 110 28 26 32 48 80 114 139 112

n 28 34 44 58 102 174 160 124 ↓ 36 44 74 112 136 218 206 154

48 70 110 128 162 208 226 194 98 128 156 174 206 256 240 202 144 184 190 196 224 200 206 198

80

Page 81: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG

Finally, encode the DCT coefficients for each block using “run­

length” encoding followed by an information theoretic (lossless)

“Huffman” scheme, in which frequently occuring patterns are

represented by short codes.

The “quality” of the image can be adjusted by changing the values

of q[m, n]. Large values of q[m, n] result in large “runs” of zeros,

which compress well.

81

Page 82: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

JPEG: Results

1%: 1666 bytes 10%: 2550 bytes 20%: 3595 bytes

40%: 5318 bytes 80%: 100%: 47k bytes

10994 bytes 82

Page 83: Lecture 22: Sampling and quantization - MIT OpenCourseWare · PDF fileTime (second) 0 0.5 1 Time (second) 0 0.5 1 Time (second) ­1 0 1 Input voltage ... We will focus on the DCT and

MIT OpenCourseWarehttp://ocw.mit.edu

6.003 Signals and SystemsFall 2011

For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.