Sampling Theory 101 - University of California,...

60
Sampling Theory 101 Oliver Kreylos [email protected] Center for Image Processing and Integrated Computing (CIPIC) Department of Computer Science University of California, Davis CIPIC Seminar 11/06/02 – p.1

Transcript of Sampling Theory 101 - University of California,...

Sampling Theory 101Oliver Kreylos

[email protected]

Center for Image Processing and Integrated Computing (CIPIC)

Department of Computer Science

University of California, Davis

CIPIC Seminar 11/06/02 – p.1

Outline

• Things that typically go wrong• Mathematical model of sampling• How to do things better

CIPIC Seminar 11/06/02 – p.2

Things That Typically Go Wrong

CIPIC Seminar 11/06/02 – p.3

Where Does Sampling Occur?

Almost all data we are dealing with is discrete• Evaluation of sampled functions at arbitrary

sites• Volume rendering• Isosurface extraction• Ray tracing• . . .

CIPIC Seminar 11/06/02 – p.4

What Went Wrong Here?

Typical ray tracing example:

CIPIC Seminar 11/06/02 – p.5

Sampling and Reconstruction

CIPIC Seminar 11/06/02 – p.6

Sampling and Reconstruction

CIPIC Seminar 11/06/02 – p.6

Sampling and Reconstruction

CIPIC Seminar 11/06/02 – p.6

Sampling and Reconstruction

• Undersampling?• Sampling “below Nyquist rate”?• Quick solution: Double sampling rate

CIPIC Seminar 11/06/02 – p.6

Sampling and Reconstruction

CIPIC Seminar 11/06/02 – p.6

Sampling and Reconstruction

• Things get better, but are still bad• Isn’t sampling above the Nyquist rate

supposed to solve all problems?

CIPIC Seminar 11/06/02 – p.6

Sampling Theory

To understand what went wrong on the last slide,

we need a mathematical model of sampling.

CIPIC Seminar 11/06/02 – p.7

Mathematical Model of Sampling

CIPIC Seminar 11/06/02 – p.8

Choice of Domain

• Process of sampling and reconstruction isbest understood in frequency domain

• Use Fourier transform to switch between timeand frequency domains

• Function in time domain: signal• Function in frequency domain: spectrum

CIPIC Seminar 11/06/02 – p.9

Fourier Transform I

• Many functions f :R → R can be written assums of sine waves

f(x) =∑

ω

aω sin(ωx + θω)

• ω = 2π · frequency is angular velocity,• aω is amplitude, and• θω is phase shift

CIPIC Seminar 11/06/02 – p.10

Fourier Transform II

• Moving to complex numbers simplifiesnotation:

cos(ωx) + i sin(ωx) = eiωx

(Euler identity )

• One complex coefficient cωeiωx encodes bothamplitude and phase shift

• Moving to integral enlarges class ofrepresentable functions

CIPIC Seminar 11/06/02 – p.11

Fourier Transform III

• Now, for almost all f :

f(x) =

∫F (ω)eiωx dω

• F (ω) is the spectrum of f(x), and the aboveoperator is the inverse Fourier transform

• Its inverse, the Fourier transform, is

F (ω) =

∫f(x)e−iωx dx

CIPIC Seminar 11/06/02 – p.12

Some Signals and Their Spectra

Single sine wave f(x) = sin(ωx):

CIPIC Seminar 11/06/02 – p.13

Some Signals and Their Spectra

Sum of two sine wavesf(x) = sin(ωx) + 0.5 sin(2ωx):

CIPIC Seminar 11/06/02 – p.13

Some Signals and Their Spectra

Box function:

CIPIC Seminar 11/06/02 – p.13

Some Signals and Their Spectra

Wider box function:

CIPIC Seminar 11/06/02 – p.13

Some Signals and Their Spectra

Triangle function:

CIPIC Seminar 11/06/02 – p.13

Some Signals and Their Spectra

Comb function:

CIPIC Seminar 11/06/02 – p.13

Some Signals and Their Spectra

Wider comb function:

CIPIC Seminar 11/06/02 – p.13

Convolution I

• The convolution operator is a generalizedformula to express weighted averaging of aninput signal f and a weight function or filterkernel g:

(f ∗ g)(x) =

∫f(t) · g(x − t) dt

• One important application of convolution isreconstructing sampled signals

CIPIC Seminar 11/06/02 – p.14

Convolution II

(f ∗ g)(x0) =

∫f(t) · g(x0 − t) dt

x

f

x

g

x0x

f

x0

x

f

x0

x

f

x0

x

f*g

x0

CIPIC Seminar 11/06/02 – p.15

Convolution III

Linear interpolation can be interpreted asconvolution:

x

f

x

g

x

f

x

f

CIPIC Seminar 11/06/02 – p.16

Function Reconstruction

Constant interpolation:

CIPIC Seminar 11/06/02 – p.17

Function Reconstruction

Linear interpolation:

CIPIC Seminar 11/06/02 – p.17

Function Reconstruction

Catmull-Rom interpolation:

CIPIC Seminar 11/06/02 – p.17

Function Reconstruction

Cubic B-spline approximation:

CIPIC Seminar 11/06/02 – p.17

The Convolution Theorem

• The Convolution Theorem relates convolutionand Fourier transform:

(f ∗ g) ↔ F · G

• Convolutions can be computed by goingthrough the frequency domain:

(f ∗ g) = IFT(FT(f) · FT(g))

CIPIC Seminar 11/06/02 – p.18

Sampling in Time Domain

• Sampling a function f means multiplying itwith a comb function c with tap distance d (orsample frequency ω = 2π/d):

s = f · c

• Reconstructing a sampled function meansconvolving it with a suitable filter kernel

f ′ = s ∗ k

• What happens to the function’s spectrum inthe process?

CIPIC Seminar 11/06/02 – p.19

Sampling in Frequency Domain

• The spectrum of s is the convolution of Fand C, the spectra of f and c

• C is a comb function with tap distance 2π/d

• S consists of shifted copies of F , each 2π/dapart

CIPIC Seminar 11/06/02 – p.20

Sampling Process - Time Domain

CIPIC Seminar 11/06/02 – p.21

Sampling Process - Frequency Domain

CIPIC Seminar 11/06/02 – p.22

Sampling in Frequency Domain

• If the sampling frequency is ω, the replicatedcopies of f ’s spectrum are ω apart

• If the highest-frequency component in f is ωf ,f ’s spectrum covers the interval [−ωf , ωf ]

• If ωf ≥ ω/2, then the replicated spectraoverlap!

• This means, information is lost

CIPIC Seminar 11/06/02 – p.23

The Sampling Theorem

• “If f is a frequency-limited function withmaximum frequency ωf , then f must besampled with a sampling frequency largerthan 2ωf in order to be able to exactlyreconstruct f from its samples.”

• This theorem is sometimes called Shannon’sTheorem

• 2ωf is sometimes called Nyquist rate

CIPIC Seminar 11/06/02 – p.24

Reconstruction

• The only difference between F and S is that Sis made of shifted copies of F

• If those extra, higher-frequency, spectra couldbe removed from S, f would “magically”reappear

• Reconstructing f means low-pass-filtering s!

CIPIC Seminar 11/06/02 – p.25

Reconstruction Process - Frequency Domain

CIPIC Seminar 11/06/02 – p.26

Reconstruction Process - Time Domain

CIPIC Seminar 11/06/02 – p.27

Reconstruction Problem

• Practical problem: The optimal reconstructionfilter, the sinc function, has infinite support

• Evaluating it in the time domain involvescomputing a weighted average of infinitelymany samples

• Practical reconstruction filters must have finitesupport

• But: A perfect low-pass filter with finitesupport does not exist!

CIPIC Seminar 11/06/02 – p.28

The Quest For Better Filters

CIPIC Seminar 11/06/02 – p.29

Commonly Used Filters

Constant filter:

CIPIC Seminar 11/06/02 – p.30

Commonly Used Filters

Linear filter:

CIPIC Seminar 11/06/02 – p.30

Commonly Used Filters

Catmull-Rom filter:

CIPIC Seminar 11/06/02 – p.30

Commonly Used Filters

B-Spline filter:

CIPIC Seminar 11/06/02 – p.30

Sampling Theory Filters

Truncated sinc filter:

CIPIC Seminar 11/06/02 – p.31

Sampling Theory Filters

Lanczos filter:

CIPIC Seminar 11/06/02 – p.31

Sampling Theory Filters

Full sinc filter:

CIPIC Seminar 11/06/02 – p.31

Sampling Theory Applications

CIPIC Seminar 11/06/02 – p.32

Function Reconstruction

• Sampling theory filters (Lanczos etc.) can beused to reconstruct n-dimensional functionssampled on regular grids

• Oversampling improves reconstruction qualitywith “bad” filters, but at a high cost

CIPIC Seminar 11/06/02 – p.33

Function Resampling

• When resampling a sampled function to adifferent grid (shifted and/or scaled), it isimportant to use a good reconstruction filter

• When downsampling a function, it isimportant to use a good low-pass filter to cutoff frequencies above half the new samplingfrequency

CIPIC Seminar 11/06/02 – p.34

Volume Rendering

• Basic question: How many samples to takeper cell?

d

• Sampling theory says “1,” but integrationalong ray might demand more

CIPIC Seminar 11/06/02 – p.35

Volume Rendering

• Basic question: How many samples to takeper cell?

d

• Sampling theory says “1,” but integrationalong ray might demand more

CIPIC Seminar 11/06/02 – p.35

Ray Tracing

• In ray tracing, the function to be sampled istypically not frequency-limited

• Practical solution: Shoot multiple rays perpixel (oversampling) and sample down toimage resolution

• Using a good low-pass filter is important

CIPIC Seminar 11/06/02 – p.36

Ray Tracing

CIPIC Seminar 11/06/02 – p.36

Conclusions

CIPIC Seminar 11/06/02 – p.37

Conclusions

• Knowing the mathematical background ofsampling and reconstruction helps tounderstand common problems and devisesolutions

• Ad-hoc solutions usually do not work well• This stuff should be taught in class!

CIPIC Seminar 11/06/02 – p.38

The End

CIPIC Seminar 11/06/02 – p.39