PowerPoint Template

Download Report

Transcript PowerPoint Template

SAMPLING & QUANTIZATION
Dhany Arifianto
How might you measure waves on
a beach?
Or, even, sample the wave height
Is sampling okay?
Question: Is a sampled representation the
same thing?
– Yes, provided…
• Digital means discrete (like whole numbers)
and Analog means continuous (like physical
properties such as temperature, volume,
etc.).
• The term analog comes from early
computers (circa WWII) used to solve
differential equations with continuous
variables,
• as contrasted with discrete state machines
(like an elevator controller) built from openor-closed switches or on-off digital circuits
Definitions
(from whatis.com)
Analog
• Using physical representation
• Relating to a system, device that
represents data variation by a measurable
physical quality such as temperature,
volume, distance, weight, pressure …
• Which is continuous in time or space and
value
Definitions
Digital
• Representing data as numbers
–
–
–
–
–
Processing
Operating on
Storing
Transmitting
Displaying
• Data in the form of numerical digits, as in a
digital computer
• Representing a physical quantity
– such as sound, light, or electricity
• by means of samples
– taken at discrete times (or places)
– and given numerical values
• usually in the binary system
– as in a digital audio recording
– or in digital television
– or in digital photography
Analog vs. Digital
• Analog
– Media represented using real values
– Sound pressure in the air (example)
– Electronic representation of sound from a
microphone
• Digital
– Media represented using discrete values
• (integers, quantized numbers, floating point
representations)
• May be infinite, but for a fixed range finite.
Electronic capture of sounds
Analog pressure variations
N
S
Analog voltage variations
In Communications
• Analog is used to refer to systems with
signals that are continuous in value and
time
– such as AM and FM, where the electrical
signals are representations of the
information signals.
Amplitude Modulation (AM)
A
N
A
L
O
G
s(t)  Ac [1 k a m(t)]cos(2f c t)
Phase or Frequency Modulation (FM)
s(t)  Ac cos(2f c t  k m(t))
s(t)  Ac cos(2f c t  k f

t
m(

)
d

)
0
In Communications
• Digital is used to refer to discrete-state,
discrete-time signals that can take on only
specific values at specific times;
• such as
– sampled/quantized signals,
– pulse modulated signals,
• and to data communication signals in
general.
Digital Modulation: Discrete in Time and
Value
Parameters of Information Sources &
Systems
• Analog (continuous functions of time,
space, weight, …)
– voice, audio, image, video, temperature
• Bandwidth – frequency (harmonics) range
• Statistics – amplitude distribution, power,
spectrum (frequency content, harmonics)
• Digital (sets of numbers):
– ASCII characters, computer words, …
• Bit Rate – bps, kbps, Mbps, Gbps, Tbps,
Ebps, …
How does Information Become “Digital”?
Digital Representation
• Information that is naturally discrete,
such as state of a light switch (on-off),
integers, or text can be represented by
binary numbers in obvious ways.
• Text (as generated on a keyboard) is
often represented by 8-bit binary
numbers.
• Speech may be represented by a
pressure wave, which is continuous – in
time and value – and has to be sampled
and quantized to be represented digitally.
Discrete Information
• Some information, such as numerals and
characters is discrete and can be
represented “digitally” easily
• Take characters of the English Language
for example
• The American Standard Code for
Information Interchange (ASCII) is the
binary representation used in teletype
messaging and adopted as a universal
computer character representation.
“A” = 11000001
“a” = 11100001
“%” = 10100101
Formatting
10001101 = CR
10001010 = LF
Messaging
10000001 = SOH
10000010 = STX
10000011 = ETX
10000100 = EOT
Common Sense Digitization of Analog
Information
• All continuous signals can be represented
by a collection of numbers to any degree of
accuracy by
– sampling often enough and
– using enough quantization levels* to represent
the signal value at the sampling instants.
– * determined by the number of digits in the
representation
Analog-to-Digital Conversion
• Two stage process
• Sample
– Sampling Theorem
– Nyquist Rate
• Quantize
– Precision, SNR (% average error)
– Note: a digital representation of an analog
value always has error
The Sampling Theorem
• Shannon’s Sampling Theorem states that
– any bandlimited signal may be represented by
samples taken at a rate of twice its highest
frequency*, and
– may be reconstructed without error if the
appropriate interpolation functions are used**.
* Twice the highest frequency is called the Nyquist Rate.
** Physically unrealizable sinx/x or (sinc) functions.
This theorem is also known as Nyquist–Shannon–Kotelnikov
Whittaker–Shannon–Kotelnikov
Whittaker–Nyquist–Kotelnikov–Shannon
WKS
Cardinal Theorem of Interpolation Theory
The Sampling Theorem
Harry Nyquist, working at Bell Labs developed
what has become known as the Nyquist
Reconstruction Theorem:
Given a uniform sample rate of fs, the highest
frequency that can be unambiguously
represented is fs/2
– fs/2 is the Nyquist Frequency
CD Players use fs=44,100 samples/sec
– The Nyquist Frequency is 22,050 Hz
– Why don’t CD’s sample at 40KHz?
Sampling
Lets consider a sign wave to be sampled
(e.g. voice signal)
If you sample at 1 time per cycle, you
can think it is a constant
Sampling 1.5 times each cycle appears
as a low frequency sine signal
Nyquist Theorem: For Lossless
digitization, the sampling rate should be
at least twice the maximum frequency
responses
Representation of a CT Signal Using Impulse Functions
• The goal of this lecture is to convince you that bandlimited CT
signals, when sampled properly, can be represented as discrete-time
signals with NO loss of information. This remarkable result is known
as the Sampling Theorem.
x(t)
• Recall our expression for a pulse train:

 (t  nT)
p(t) 
…
…
t
-2T
n 
-T
0
T
• A sampled version of a CT signal, x(t), is:

x s (t)  x(t) p(t) 


n 
n 
 x(t) t  nT   x(nT) t  nT
This is known as idealized sampling.
• We can derive the complex Fourier series of a pulse train:


p(t) 
c e
jk 0 t
k
where  0  2 /T
k 
1 T /2
1 T /2
1  jk 0 t
1
 jk 0 t
 jk 0 t
ck 
p(t)e
dt


(t)e
dt

e



 t 0 T
T T / 2
T T / 2
T

p(t) 
1 jk 0 t
 Te
k 
2T
Sampling
Sampling simply
taking
readings at
fixed points
in time
Uniform
sampling –
sampling at
regular
intervals
Impulse Sampling
Fourier Transform of a Sampled Signal
• The Fourier series of our sampled signal, xs(t) is:

1
x s (t)  p(t)x(t)   x(t)e jk 0 t
T
k 

• Recalling the Fourier transform properties of linearity (the
transform of a sum is the sum of the transforms) and modulation
(multiplication by a complex exponential produces a shift in the
frequency domain), we can write an expression for the Fourier
transform of our sampled signal:
  1
 1 
j
jk 0 t
 Fx(t)e jk 0 t 
X s e   Fp(t)x(t)  F x(t)e
k  T
 T k 
1 
  X(e j( k 0 ) )
T k 
X(e j )  0 for   B
• If our original signal, x(t), is bandlimited:


Sampling of Narrowband Signals
• What is the lowest sample frequency
we can use for the narrowband signal
shown to the right?
• Recalling that the process of
sampling shifts the spectrum of the
signal, we can derive a generalization
of the Sampling Theorem in terms of
the physical bandwidth occupied by
the signal.
• A general guideline is 2
, where B = B2 – B1.
B

f
4
B
s
• A more rigorous equation depends on B1 and B2:
f s  2B
r
f  B /2
where r c
r
B
and
f c  (B1  B2 ) /2

r  r (greatestint egergreaterthanor equal to r)
• Sampling can also be thought of as a modulation
operation, since it shifts a signal’s spectrum in
frequency.
Signal Reconstruction
j
• Note that if  s  2B, the replicas of X e  do not overlap in the
frequency domain. We can recover the original signal exactly.


• The sampling frequency,
, is referred to as the Nyquist
2
B
s
sampling frequency.
• There are two practical problems associated with this approach:
 The lowpass filter is not physically realizable. Why?
 The input signal is typically not bandlimited. Explain.
Signal Interpolation

• The frequency response of the lowpass, or interpolation, filter is:
T, B    B
j
H(e )  
0, elsewhere
• The impulse response of this filter is given by:
BT sinBt /   BT
h(t) 

sinc(Bt/?)    t  
 Bt /  

• The output of the interpolating filter is given by the convolution
integral:


y(t)  h(t) * x s (t) 
 x ( )h(t   )d
s

 
 

   x(nT) t  nTh(t   )d    x(nT) t  nTh t   d

 n 
 n 




  x(nT) t  nTht   d
n  
• Using the
sifting property of the impulse:
 
y(t) 
  x(nT) t  nTht   d
n  



 x(nT)ht  nT
n 
Signal Interpolation (Cont.)
• Inserting our expression for the
impulse response:

BT
B
y
(
t
)

x
(
nT
)
sinc
((
t

nT
))

n



• This has an interesting graphical
interpretation shown to the right.
• This formula describes a way to
perfectly reconstruct a signal from
its samples.
• Applications include digital to
analog conversion, and changing
the sample frequency (or period)
from one value to another, a process
we call resampling (up/down).
• But remember that this is still a
noncausal system so in practical
systems we must approximate this
equation. Such implementations
are studied more extensively in an
introductory DSP class.
Reconstruction
Sampling
Analog
signal
Sample
and
Hold
Sampled
signal
Real values at fixed points in time
Uses a “sample-and-hold”
Values are called “samples”
Sample
Analog Devices AD585
Sample and Hold Amplifier

Sound in the Real World

f (t)  c h sinht  h 
h 1
Recall: All sounds can be
expressed as a combination of
sinusoids
String instruments generate
harmonics
C8 on piano = 4186 Hz
6th Harmonic is 25,116 Hz
Above the Nyquist Frequency!!
Many instruments
generate content above
20 KHz
A short section of a
speech waveform
(highest frequency
component is 3KHz)
Reconstructed
speech waveform
with 1 KHz sampling
rate (note the
resulting waveform
does not resemble
original waveform)
Undersampling & Oversampling

Undersampling
 Sampling at an inadequate frequency rate
 Aliased into new form - Aliasing
 Loses information in the original signal

Oversampling
 Sampling at a rate higher than minimum rate
 More values to digitize and process
 Increases the amount of storage and transmission
 COST $$
Aliasing
• Recall that a time-limited signal cannot be bandlimited. Since all
signals are more or less time-limited, they cannot be bandlimited.
Therefore, we must lowpass filter most signals before sampling. This
is called an anti-aliasing filter and are typically built into an analog to
digital (A/D) converter.
• If the signal is not bandlimited distortion will occur when the signal
is sampled. We refer to this distortion as aliasing:
• How was the sample frequency for CDs and MP3s selected?
Antialiasing Filters
We have to filter (remove) any content above
the Nyquist Frequency
Analog
signal
Antialiasing
Filter
Sample
and
Hold
Not digital devices!!!
Sampled
signal
Analog filtering
• Filtering is the relative modification of
amplitudes of different frequencies
Flat response
High (treble) boost
Low (bass) cut
2
1
0
0
10k
20k
30k
Antialiasing filters
• What we want is a brick wall filter, that passes
everything below 20 KHz and cuts everything
above
2
1
0
0
10k
20k
30k
Reality vs. Ideal
• But, we can’t build a brick wall filter
We can
specify:
Maximum
ripple
Pass band
Cut band
Minimum cut
Transition
band
Real analog filters
• We pay for transition/pass ratio
Costs:
Component
count
Drift
Noise
Non-linearity
Phase distortion
Other junk…
pass
tr
Undersampling and Oversampling of a Signal
Sampling is a Universal Engineering Concept
• Note that the concept
of sampling is applied
to many electronic
systems:
 electronics: CD
players, switched
capacitor filters,
power systems
 biological systems:
EKG, EEG, blood
pressure
 information systems:
the stock market.
• Sampling can be
applied in space (e.g.,
images) as well as
time, as shown to the
right.
• Full-motion video signals are sampled spatially (e.g., 1280x1024
pixels at 100 pixels/inch) , temporally (e.g., 30 frames/sec), and with
respect to color (e.g., RGB at 8 bits/color). How were these settings
arrived at?
Downsampling and Upsampling
• Simple sample rate conversions, such as converting from 16 kHz to
8 kHz, can be achieved using digital filters and zero-stuffing:
Oversampling
• Sampling and digital signal processing can be combined to create
higher performance samplers 
• For example, CD players use an oversampling approach that involves
sampling the signal at a very high rate and then downsampling it to
avoid the need to build high precision converter and filters.
Summary
• All signals can be represented by a
collection of numbers to any degree of
accuracy by sampling often enough and
using enough quantization levels to
represent the signal value at the sampling
instant.
Summary
• Shannon’s Sampling Theorem states that
any strictly bandlimited function may be
presented by sampling at a rate that is at
least twice as fast as the highest frequency
in the signal, and that it may be recovered
without distortion by passing the (impulse)
samples through an ideal low-pass filter
with a bandwidth equal to that of the signal.
Quantization
• For processing, storage or
communication, samples with infinite
precision must be quantized
• Such that a range, or interval, of values
is represented by a single, finite
precision, number
• For example, by a finite binary number.
Quantization
7
7
7
7
7
6
5
5
4
3
3
2
2
1
1
1
-2
-3
-3
time
-2
-3
-4
Reconstitution
7
7
7
7
7
6
5
5
4
3
3
2
2
1
1
1
-2
-3
-3
time
-2
-3
-4
-2
Quantum Boundary
Actual Value
Reconstruction Value -3
ERROR
-3
Quantum Boundary
-4
Quantization (linear vs. logarithmic)
Logarithmic Quantization
Linear Quantization

The 127 quantization levels are
spread evenly over the voice
signal’s dynamic range
 This gives loud voice signals the
same degree of resolution (same
step size) as soft voice signals
 Encoding an analog signal in this
manner, while conceptually
simplistic, does not give optimized
fidelity in the reconstruction of
human voice

Most of the energy in human voice is
concentrated in the lower end of
voice’s dynamic range (no shouting –
just from boss)
 Quantization levels distributed
according to a logarithmic, instead of
linear, function gives finer resolution,
or smaller quantization steps, at lower
signal amplitudes
 PCM in North America uses a
logarithmic function called μ-law
Quantization Error (for nerds and audiophiles)
• The quantization error depends on the
number of distinct quantization intervals
used.
• If N binary digits are used, the number of
distinct intervals is 2N.
• The signal-to-quantization-error ratio is
about (6N + 1.8) dB.
Binary Representation
• Once information is discretized, or sampled,
a number can be assigned to represent the
value of each sample.
• The number can be expressed as a binary
number, e.g., 2009 is
1024 + 512 + 256 + 128 +64 + 32 + 8 + 4 + 1
1x 210 + 1x 29 + 1x 28 + 1x 27 + 1x 26 +1x 25 +1x 23 + 1x 22 + 1x 20
11111101101
Example: CD Audio
Human hearing band: 20-20000 Hz
Passband: 0-20000 Hz
Transition band: 0.10 * 20000 = 2000
10% transition band
Band is 20000-22000 Hz
Minimum possible sample
rate:
2 * 22000 = 44000
samples/second
They actually use 44,100
samples/second
Any ideas why?
Example: Professional Audio
Human hearing band: 20-20000 Hz
Passband: 0-20000 Hz
Transition band: 0.20 * 20000 = 4000
20% transition band
Band is 20000-24000 Hz
Minimum possible sample rate:
2 * 24000 = 48000 samples/second
Most modern
equipment has moved
to 96,000
samples/second and a
passband of 040000Hz
Why 44,100 for CDs?
44,100 is evenly divisible by:
–
–
–
–
60 (American/Japanese television field rate)
50 (European television field rate)
30 (American/Japanese television frame rate)
25 (European television frame rate)
The exact frame rate in the US/Japan is
actually 29.97, which is not divisible, but
there are lots of funky numbers in the
television signal…
Choosing a sample rate for analog sampling
1.
2.
3.
4.
Select a passband
Choose a transition band ratio
Design an antialiasing filter
Select a sample rate such that fs/2 is above
the transition band
Generally you’ll use standard sample rates
Remember, each sample is a data point !
Those rules are applicable in DAC/ADC
design(for signal processing, control, etc.)
Converting Digital to Analog
Digital Signal
Assume: Unsigned 8 bit value, analog range 1
volt
Analog
1/2 V
Voltage Adder
1/4 V
1/8 V
1/16 V
1/32 V
1/64 V
1/128 V
1/256 V
Converting Analog to Digital
Binary search for correct value
a
a>b?
Result
Successive
Approximation
(Binary search)
D/A
Conversion
b