Week 5 – Nyquist-ShannonESE 250 – S’12 Kod & DeHon 1
ESE250:Digital Audio Basics
Week 5 Feb. 9, 2012
Nyquist-Shannon Theorem
ESE 250 – S’12 Kod & DeHon
2
Course Map
Numbers correspond to course weeks
2,5 6
11
13
12
Today
Week 5 – Nyquist-Shannon
Where are we ?• Week 2 Received signal is sampled &
quantized q = PCM[ r ]
• Week 3 Quantized Signal is Coded c =code[ q ]
• Week 4 Sampled signal first
transformed into frequency domain
Q = DFT[ q ]• Week 5
signal oversampled & low pass filtered
Q = LPF[ DFT(q+n) ]• Week 6
Transformed signal analyzed Using human psychoaoustic
models• Week 7
Acoustically Interesting signal is “perceptually coded”
C = MP3[ Q]
OverSample
DFT LPF
DecodeProduce
r(t)
p(t)
q + n
CPerceptual
CodingStore /
Transmit
Q + N Q
Week 4
Week 6
Week 5 Week 3
[Painter & Spanias. Proc.IEEE, 88(4):451–512, 2000]
Week 5 – Nyquist-ShannonESE 250 – S’12 Kod & DeHon 3
ESE 250 – S’12 Kod & DeHon
Reconstruction• Acquisition Side
we’ve convinced ourselves to sample, then process, then store and transmit discretely sampled values
• On the other end? how should the stored sound be produced? ? send strings of sampled spl levels
o off to the sound cardo at what rate?
? Interpolateo with what family of interpolants?
• Week 4: harmonic reconstruction Gets better with more terms But need more samples to compute them and error seems unpredictable
• This week: general reconstruction introduce further assumptions about signal
o to guarantee exact finite reconstructiono with appropriate basis functions
introduce another processing step to achieve those assumptions
Generic Digital Signal Processor
Sampler(t)q
Codec
Store/Transmit Decode Produce p(t)
Week 5 – Nyquist-Shannon 4
Week 5 – Nyquist-ShannonESE 250 – S’12 Kod & DeHon 5
Shannon’s TheoremM. Unser. Proc. IEEE, 88(4):569–587, 2000
Questions:• are the real
functions countable after all?
• what is “frequency content”?
1 5 1 0 5 5 1 0 1 5
0 . 5
0 . 5
1 . 0
b0(t)
• Hypothesis given a (sufficiently “nice”) real function, r(t) whose frequency content does not exceed
M = 2 fM
• Conclusion There is a set of “sampling” basis functions (we’ll not discuss)
BS = { …, b-2(t), b-1(t), b0(t), b1(t), b2(t), … } which can exactly reconstruct the function
r(t) = … + r-2 b-2(t) + r-1 b-1(t) + r0 b0(t) + r1 b1(t) + r2 b2(t) + … from samples
rk = r(k TM) taken at sampling intervals
TM = /M = 1 / (2 fM ) called the “Nyquist” rate
ESE 250 – S’12 Kod & DeHon
Trial Application to Our Setting
• Psychoacoustic measurements introduced in next (week 6) lecture show human audition is bandlimited at frequency A = 2 fA for fA = 22 kHz
• Naïve Processing Strategy sample received signal, r(t) at intervals TA = /A = 1 /2 fA = [ 44 ¢ 103 ]-1 sec reconstruct exactly as needed
r(t) = … + r-2 b-2(t) + r-1 b-1(t) + r0 b0(t) + r1 b1(t) + r2 b2(t) + … from samples r = {… , r-2 , r-1 , r0 , r1 , r2 , … } where rk = r(k TA)
• Why bother with DFT at all??Week 5 – Nyquist-Shannon 6
ESE 250 – S’12 Kod & DeHon
Poking the Trial Balloon• In reality we receive a “mixed” signal
r(t) = q(t) + n(t) q(t)
o signal component of auditory interesto has bandwidth fA = 22 kHz
n(t)o noise (uninteresting information)o has (typically) high frequency content
impurities associated with transmission and recording background sounds
• We only get to sample the received signal, r(t), not the desired signal, q(t) !!
Week 5 – Nyquist-Shannon 7
ESE 250 – S’12 Kod & DeHon
• In class experiment: assume a nominal band limit at frequency N = 2 fN for fN = 5/4 Hz [samples/sec] Question: what is the Nyquist sample rate?
o TN = 1/(2 fN) = 2/5 sec [sample/sec]-1
• In this experiment, assume that q(t) ´ 0
o signal component of auditory interesto satisfies bandwidth requirement of fN = 5/4 Hz
n(t) = Cos[9/5 N t]o noise (uninteresting information)o has “high” frequency contento i.e., it is above (by 9/5) the presumed Nyquist rate
• Class will sample r(t) = q(t) + n(t) over “window” -T0/2 < t < T0/2 for T0 = 4 [sec] at the presumed Nyquist rate Questions:
o what is the number of Nyquist samples? nS ¢ TN = T0 Number of samples: nS = 2 fN T0 = 10
o what are the Nyquist sample times? t 2 {-2,-(8/5),-(6/5),-(4/5),-(2/5),0,2/5,4/5,6/5,8/5,2}
2 1 1 2
1 .0
0 .5
0 .5
1 .0
q(t)
2 1 1 2
1 .0
0 .5
0 .5
1 .0n(t)
2 1 1 2
1 .0
0 .5
0 .5
1 .0
r(t) = q(t) + n(t)
Bursting the Trial Balloon
Week 5 – Nyquist-Shannon 8
ESE 250 – S’12 Kod & DeHon
2 1 1 2
1 .0
0 .5
0 .5
1 .0
1 .5
2 .0
Bursting the Trial Balloon• Class will sample r(t) = q(t) + n(t)
over “window”
-T0/2 < t < T0/2 for T0 = 4 at the presumed Nyquist rate
o Number of samples:
nS = 2 fN T0 = 10o Sample instants:
t 2 {-2,-(8/5),-(6/5),-(4/5),-(2/5),0,2/5,4/5,6/5,8/5,2}
• and get an “aliased” version of the noise! r(t) looks like a sampled version of n(t) = Cos[1/5 N t]
(D ebug) Out[730]=
2. 1.6 1.2 0.8 0.4 0 0.4 0.8 1.2 1.6 2. 1. 0.81 0.31 0.31 0.81 1. 0.81 0.31 0.31 0.81 1.
2 1 1 2
1 .0
0 .5
0 .5
1 .0
1 .5
2 .0
Week 5 – Nyquist-Shannon 9
ESE 250 – S’12 Kod & DeHon
Aliasing• Widely familiar phenomenon
Wikipedia aliasing article “wagon wheel” effect Wikipedia Nyquist-Shannon Theorem
• “Folding:” another general manifestation of aliasing premise: r(t) = q(t) + n(t)
o we expect q(t) with bandwidth less than N = 2 fN o but turns out that n(t) is some “ superharmonic residue”
n(t) = cos[ mN(1+ ) t ] where 0 < <1
outcome: sample at “Nyquist rate” TN = 1/(2 fN)o rk = r( k TN) = q(k TN) + n(k TN)o where the noise
n( k TN) = cos[mN(1+ ) k TN ] = cos[mk(1+ ) ] = cos[ mk] ¢ cos[mk ] - sin[ mk] ¢ sin[mk ] = 1 ¢ cos[mk ] - 0 ¢ sin[mk ] = cos[ N k TN]
o “folds over” to act as if it were a low-band tone of frequency fN
Week 5 – Nyquist-Shannon 10
ESE 250 – S’12 Kod & DeHon
Anti-Aliasing• Given the “mixed” signal
r(t) = q(t) + n(t) q(t) – auditory signal with bandwidth fA = 22 kHz n(t) – high frequency noise
• We require some “anti-aliasing” pre-process that “smooths away” the noise which will otherwise appear in the samples
o r = {… , r-2 , r-1 , r0 , r1 , r2 , … }o where rk = r(k TA)
o and TA = /A = 1 /2 fA = [ 44 ¢ 103 ]-1 sec
• Question: how to do this?Week 5 – Nyquist-Shannon 11
Week 5 – Nyquist-ShannonESE 250 – S’12 Kod & DeHon 12
Interlude: Visual Aliasing • Wolfram: Drawing a Line on Digital Display• Berkeley Course Demo• Typography
ESE 250 – S’12 Kod & DeHon
Back to Shannon (new today)• Hypothesis
given a (sufficiently “nice”) real function, r(t) whose frequency content does not exceed
M = 2 fM
• Conclusion There is a set of “sampling” basis functions (we’ll not show)
BS = { …, b-2(t), b-1(t), b0(t), b1(t), b2(t), … } which can exactly reconstruct the function
r(t) = … + r-2 b-2(t) + r-1 b-1(t) + r0 b0(t) + r1 b1(t) + r2 b2(t) + … from samples
rk = r(k TM) taken at sampling intervals
TM = /M = 1 /(2 fM ) called the “Nyquist” rate
M. Unser. Proc. IEEE, 88(4):569–587, 2000
Questions:• are the real functions
countable after all?• what is “frequency content”? • what are the “basis
functions” ?Week 5 – Nyquist-Shannon 13
Week 5 – Nyquist-ShannonESE 250 – S’12 Kod & DeHon 14
Fourier’s Theorem (review)• Hypothesis
given a (sufficiently “nice”) real function, r(t) which is periodic with period T0
r(t) = r(t + T0)
• Conclusion the set of “harmonic” basis functions
BH = { …, h-2(t), h-1(t), h0(t), h1(t), h2(t), … }
at frequency 0 = 2 f0 for f0 = 1/T0
defined by hk(t) = cos k 0 t (k>0)
hk(t) = 1 (k>0)
hk(t) = sin k 0 t (k<0) can exactly reconstruct the function
r(t) = … + R-2 h-2(t) + R-1 h-1(t) + R0 h0(t) + R1 h1(t) + R2 h2(t) + …
M. Unser. Proc. IEEE, 88(4):569–587, 2000
Question:• are the real functions
countable after all?
ESE 250 – S’12 Kod & DeHon
Clipping a Non-Periodic Function
• If we are willing to restrict attention to a specific
observation window
-T0/2 · t · T0/2• Then
Fourier’s Theorem yields
exact reconstruction of the periodic
extension of any function
Answer:• apparently, “periodic” (or, more practically, finite time)• real functions • are countable after all!
- T0/2 T0/2 T0-T0
- T0/2 T0/2 T0-T0
Week 5 – Nyquist-Shannon 15
ESE 250 – S’12 Kod & DeHon
Fourier + Shannon• Fourier: period T0 ) exact
harmonic reconstruction at frequency 0 = 2 f0 for f0 = 1/T0
r(t) = … + R-2 h-2(t) + R-1 h-1(t) + R0 h0(t) + R1 h1(t) + R2 h2(t) + …
• Shannon: bandwidth M ) exact “sampled” reconstruction at frequency M = 2 fM for fM = 1/(2TM
) r(t) = … + r-2 b-2(t) + r-1 b-1(t) + r-0 b0(t) +
r1 b1(t) + r2 b2(t) + …
clipped frequencyforces finite harmonic series
clipped timeforces finite samples
Week 5 – Nyquist-Shannon 16
ESE 250 – S’12 Kod & DeHon
• Fourier + Shannon: period T0 & bandwidth M = 2 fM ) finite exact harmonic reconstruction with nM = Round[T0 / TM] samples at “Maximal Rate” TM = 1 /(2 fM )
• Algebra: k 0 > M
) R-k sin k 0 t ´ Rk cos k 0 t ´ 0 (otherwise high frequency)
) R-k = Rk = 0 (sin & cos never identically zero)
k > nM ) r (t) = R-nM
h-nM (t) + … + R-2 h-2(t) + R-1 h-1(t) + R0 h0(t) + R1 h1(t) + R2 h2(t) + … + RnM hnM (t)
• Now we’re ready to solve the anti-aliasing problem
Fourier + Shannon ) Finite Series
Week 5 – Nyquist-Shannon 17
ESE 250 – S’12 Kod & DeHon
• Now postulate: New signal, q(t), satisfying
o period T0o psychoacoustic bandwidth A = 2 fA for fA = 22 kHzo bounded by maximal bandwidth A < M
sampled with o nA = Round[T0 / TA] sampleso at “Auditory Nyquist Rate” TA = 1 /(2 fA )
• Fourier + Shannon: period T0 & bandwidth A
) finite exact harmonic reconstructionq(t) = Q-nA
h-nA (t) + … + Q-2 h-2(t) + Q-1 h-1(t) + Q0 h0(t) + Q1 h1(t) + Q2 h2(t) + … + QnA hnA (t)
vector representation:o Q = (Q-nA
, … , Q-2 , Q-1 , Q0 , Q1 , Q2 , … , QnA)
• Shannon + Fourier bandwidth A & period T0
) finite exact “sampled” reconstructiono q(t) = q-nA
b-nA (t) + … + q-2 b-2(t) + q-1 b-1(t) + q-0 b0(t) + q1 b1(t) + q2 b2(t) + … + qnA bnA (t)
vector representation:o q = (q-nA
, … , q-2 , q-1 , q0 , q1 , q2 , … , qnA)
Question: • what is the relationship • between the
representations frequency domain, Q time domain, q
Answer: Q = DFT(q)
Psychoacoustics meets Nyquist
Week 5 – Nyquist-Shannon 18
ESE 250 – S’12 Kod & DeHon
Q+N = DFT(q) + DFT(n) = DFT(q+n)• Assume we receive mixed signal
r(t) = q(t) + n(t) q(t)
o signal component of interesto has period T0 & bandwidth A
n(t)o noise (uninteresting information)o has (for now) only high frequency content, , i.e., satisfies: A < · M
• Problem: how to remove noise?• Frequency Domain approach
Take the received time-sampled representation, r = q + n r = (r-nM
, … , r-2 , r-1 , r0 , r1 , r2 , … , rnM)
= (q-nM + n-nM
, … , q-2 + n-2, q-1 + n-1 , q0 + n0, q1 + n1, q2 + n2, … , qnM + n-nM
) Compute frequency domain representation
o R = DFT(r) = DFT(q+n) = DFT(q)+ DFT(n) = Q + No R = (R-nM
, … , R-2 , R-1 , R0 , R1 , R2 , … , RnM)
= (Q-nM + N-nM
, … , Q-2 + N-2, Q-1 + N-1 , Q0 + N0, Q1 + N1, Q2 + N2, … , QnM + N-nM
) Recall the meaning of this representation: for hk(t) = trig[k 0 t] and trig 2 {cos, sin} we have
r(t) = (Q-nM + N-nM
) h-nM (t) + … + (Q-nA + N-nA
) h-nA (t) + … + (Q-nM
+ N-nM ) h-2(t) + (Q-nM
+ N-nM ) h-1(t) + (Q-nM
+ N-nM ) h0(t) + (Q-nM
+ N-nM ) h1(t) + (Q-nM
+ N-nM ) h2(t) + …
+ (Q-nA + N-nA
) hnA (t) + … + (Q-nM + N-nM
) hnM (t) Now apply assumptions about frequency content!
Week 5 – Nyquist-Shannon 19
R = DFT(r) , r = DFT-1(R) • Compute frequency domain representation
R = (R-nM , … , R-2 , R-1 , R0 , R1 , R2 , … , RnM
)
= (Q-nM + N-nM
, … , Q-2 + N-2, Q-1 + N-1 , Q0 + N0, Q1 + N1, Q2 + N2, … , QnM + N-nM
)
• Now introduce assumptions about frequency content: k > nA = A / 0 ) Qk = 0
k < nA = A / 0 ) Nk = 0
• Interpret in entries of R
= (Q-nM + N-nM
, … , Q-2 + N-2, Q-1 + N-1 , Q0 + N0, Q1 + N1, Q2 + N2, … , QnM + N-nM
)
= (0 + N-nM, … , QnA
+ N-nA, … , Q-2 + 0, Q-1 + 0 , Q0 + 0, Q1 + 0, Q2 + 0, … ,
QnA + N-nM
, … , 0 + N-nM
)
= (0,…, 0, QnA … , Q-2 , Q-1 , Q0 , Q1 , Q2, …, QnA,,
, 0,…, 0 )
+ (N-nM,… , N-nA
, 0 , … , 0 , 0 , 0 , 0 , 0 , … , 0 , NnA
,…, NnM )
• Implement Algorithmically Zero out the “higher integer” entries of S = ZEROnA (R)
Obtain the inverse transform, s = DFT-1(S)
• Conclude that s = qWeek 5 – Nyquist-Shannon 20ESE 250 – S’12 Kod & DeHon
Visualizing a Low Frequency Subspace• Low Frequency Signal
Corrupted by High frequency noise
Week 5 – Nyquist-ShannonESE 250 – S’12 Kod & DeHon 21
3 2 1 1 2 3
2
1
1
2
t 6 .28t 0 .69
t 4 .9
h0(t)
h1(t)
h-1(t)
ESE 250 – S’12 Kod & DeHon
Oversampled Pre-Filter• Anti-aliasing
requires“oversampling”o nM = Round[T0 / TM] samples o at “Maximal Rate” TM = 1 /(2 fM )o Where fM represents our best
estimate ofo the highest noise frequency
but how should we modelo “noise”o and its likely bandwidth?
• Analog pre-processing physical electro-mechanical
world o traditionally piezo-electric
microphoneo increasingly MEMS
Has its own limited bandwidth• Electronics need merely
sample up to the microphone “cut off”
frequency
Low-Pass Filter
Filter Transformr Q q
ADXL001 Accelerometer
Pre-Samplingr Low-Pass
Week 5 – Nyquist-Shannon 22
Week 5 – Nyquist-ShannonESE 250 – S’12 Kod & DeHon 24
ESE250:Digital Audio Basics
Week 5 Feb. 9, 2012
Nyquist-Shannon Theorem