Digital Signal Processing
Markus Kuhn
Computer Laboratory
http://www.cl.cam.ac.uk/teaching/1011/DSP/
Lent 2011 – Part II
Signals
flow of information → measured quantity that varies with time (or position) → electrical signal received from a transducer → (microphone, thermometer, accelerometer, antenna, etc.)
electrical signal that controls a process → Continuous-time signals: voltage, current, temperature, speed, ... Discrete-time signals: daily minimum/maximum temperature, lap intervals in races, sampled continuous signals, ...
Electronics (unlike optics) can only deal easily with time-dependent signals, therefore spatial signals, such as images, are typically first converted into a time signal with a scanning process (TV, fax, etc.).
2 Signal processing Signals may have to be transformed in order to amplify or filter out embedded information → detect patterns → prepare the signal to survive a transmission channel → prevent interference with other signals sharing a medium → undo distortions contributed by a transmission channel → compensate for sensor deficiencies → find information encoded in a different domain → To do so, we also need methods to measure, characterise, model and simulate trans- → mission channels mathematical tools that split common channels and transfor- → mations into easily manipulated building blocks
3
Analog electronics
Passive networks (resistors, capacitors, R inductances, crystals, SAW filters), non-linear elements (diodes, ...), U L C U (roughly) linear operational amplifiers in out Advantages:
passive networks are highly linear • over a very large dynamic range Uin Uin
and large bandwidths out U
analog signal-processing circuits Uout • require little or no power 0 1/√LC ω (= 2πf) t
t analog circuits cause little addi- Uin Uout 1 dUout • − = Uoutdτ + C tional interference R L −∞ dt
4 Digital signal processing Analog/digital and digital/analog converter, CPU, DSP, ASIC, FPGA. Advantages: noise is easy to control after initial quantization → highly linear (within limited dynamic range) → complex algorithms fit into a single chip → flexibility, parameters can easily be varied in software → digital processing is insensitive to component tolerances, aging, → environmental conditions, electromagnetic interference But: discrete-time processing artifacts (aliasing) → can require significantly more power (battery, cooling) → digital clock and switching cause interference
→ 5
Typical DSP applications
communication systems astronomy → modulation/demodulation, channel → VLBI, speckle interferometry equalization, echo cancellation
consumer electronics experimental physics → perceptual coding of audio and video → sensor-data evaluation on DVDs, speech synthesis, speech recognition aviation music → radar, radio navigation → synthetic instruments, audio effects, noise reduction security → steganography, digital watermarking, medical diagnostics biometric identification, surveillance systems, signals intelligence, elec- magnetic-resonance and ultrasonic → tronic warfare imaging, computer tomography, ECG, EEG, MEG, AED, audiology engineering geophysics → control systems, feature extraction → seismology, oil exploration for pattern recognition 6 Syllabus Signals and systems. Discrete sequences and systems, their types and proper- ties. Linear time-invariant systems, convolution. Harmonic phasors are the eigen functions of linear time-invariant systems. Review of complex arithmetic. Some examples from electronics, optics and acoustics. Fourier transform. Harmonic phasors as orthogonal base functions. Forms of the Fourier transform, convolution theorem, Dirac delta function, impulse combs in the time and frequency domain. Discrete sequences and spectra. Periodic sampling of continuous signals, pe- riodic signals, aliasing, sampling and reconstruction of low-pass and band-pass signals, spectral inversion. Discrete Fourier transform. Continuous versus discrete Fourier transform, sym- metry, linearity, review of the FFT, real-valued FFT. Spectral estimation. Leakage and scalloping phenomena, windowing, zero padding.
MATLAB: Some of the most important exercises in this course require writing small programs, preferably in MATLAB (or a similar tool), which is available on PWF computers. A brief MATLAB introduction was given in Part IB “Unix Tools”. Review that before the first exercise and also read the “Getting Started” section in MATLAB’s built-in manual.
7
Finite and infinite impulse-response filters. Properties of filters, implementa- tion forms, window-based FIR design, use of frequency-inversion to obtain high- pass filters, use of modulation to obtain band-pass filters, FFT-based convolution, polynomial representation, z-transform, zeros and poles, use of analog IIR design techniques (Butterworth, Chebyshev I/II, elliptic filters). Random sequences and noise. Random variables, stationary processes, autocor- relation, crosscorrelation, deterministic crosscorrelation sequences, filtered random sequences, white noise, exponential averaging. Correlation coding. Random vectors, dependence versus correlation, covariance, decorrelation, matrix diagonalisation, eigen decomposition, Karhunen-Lo`eve trans- form, principal/independent component analysis. Relation to orthogonal transform coding using fixed basis vectors, such as DCT. Lossy versus lossless compression. What information is discarded by human senses and can be eliminated by encoders? Perceptual scales, masking, spatial resolution, colour coordinates, some demonstration experiments. Quantization, image and audio coding standards. A/ -law coding, delta cod- ing, JPEG photographic still-image compression, motion compensation, MPEG video encoding, MPEG audio encoding.
8 Objectives By the end of the course, you should be able to apply basic properties of time-invariant linear systems → understand sampling, aliasing, convolution, filtering, the pitfalls of → spectral estimation explain the above in time and frequency domain representations → use filter-design software → visualise and discuss digital filters in the z-domain → use the FFT for convolution, deconvolution, filtering → implement, apply and evaluate simple DSP applications in MATLAB → apply transforms that reduce correlation between several signal sources → understand and explain limits in human perception that are ex- → ploited by lossy compression techniques provide a good overview of the principles and characteristics of sev- → eral widely-used compression techniques and standards for audio- visual signals
9
Textbooks R.G. Lyons: Understanding digital signal processing. Prentice- → Hall, 2004. (£45) A.V. Oppenheim, R.W. Schafer: Discrete-time signal process- → ing. 2nd ed., Prentice-Hall, 1999. (£47) J. Stein: Digital signal processing – a computer science per- → spective. Wiley, 2000. (£74) S.W. Smith: Digital signal processing – a practical guide for → engineers and scientists. Newness, 2003. (£40) K. Steiglitz: A digital signal processing primer – with appli- → cations to digital audio and computer music. Addison-Wesley, 1996. (£40) Sanjit K. Mitra: Digital signal processing – a computer-based → approach. McGraw-Hill, 2002. (£38)
10 Sequences and systems
A discrete sequence xn n∞= is a sequence of numbers { } −∞
...,x 2,x 1,x0,x1,x2,... − − where xn denotes the n-th number in the sequence (n Z). A discrete sequence maps integer numbers onto real (or complex)∈ numbers. ∞ We normally abbreviate xn to xn , or to xn n if the running index is not obvious. { }n=−∞ { } { } The notation is not well standardized. Some authors write x[n] instead of xn, others x(n). Where a discrete sequence x samples a continuous function x(t) as { n} x = x(t n)= x(n/f ), n s s we call ts the sampling period and fs =1/ts the sampling frequency.
A discrete system T receives as input a sequence xn and transforms it into an output sequence y = T x : { } { n} { n} discrete ...,x ,x ,x ,x− ,...... ,y ,y ,y ,y− ,... 2 1 0 1 system T 2 1 0 1
11
Properties of sequences A sequence x is { n} ∞ absolutely summable x < ⇔ | n| ∞ n= −∞ ∞ square summable x 2 < ⇔ | n| ∞ n= −∞ periodic k > 0: n Z : x = x ⇔ ∃ ∀ ∈ n n+k A square-summable sequence is also called an energy signal, and ∞ 2 xn | | n=−∞ is its energy. This terminology reflects that if U is a voltage supplied to a load resistor R, then P = UI = U 2/R is the power consumed, and P (t)dt the energy. So even where we drop physical units (e.g., volts) for simplicit y in calculations, it is still customary to refer to the squared values of a sequence as power and to its sum or integral over time as energy. 12 A non-square-summable sequence is a power signal if its average power
k 1 2 lim xn k→∞ 1 + 2k | | n −k = exists. Special sequences Unit-step sequence: 0, n< 0 u = n 1, n 0 ≥ Impulse sequence:
1, n =0 δ = n 0, n =0 = un un 1 − −
13
Types of discrete systems A causal system cannot look into the future:
yn = f(xn,xn 1,xn 2,...) − − A memory-less system depends only on the current input value:
yn = f(xn) A delay system shifts a sequence in time:
yn = xn d − T is a time-invariant system if for any d
yn = T xn yn d = T xn d . { } { } ⇐⇒ { − } { − } T is a linear system if for any pair of sequences x and x′ { n} { n} T a x + b x′ = a T x + b T x′ . { n n} { n} { n} 14 Examples: The accumulator system n
yn = xk k= −∞ is a causal, linear, time-invariant system with memory, as are the back- ward difference system
yn = xn xn 1, − − the M-point moving average system M 1 1 − xn M+1 + + xn 1 + xn yn = xn k = − − M − M k=0 and the exponential averaging system
∞ k yn = α xn + (1 α) yn 1 = α (1 α) xn k. − − − − k=0 15
Examples for time-invariant non-linear memory-less systems:
y = x2 , y = log x , y = max min 256x , 255 , 0 n n n 2 n n { {⌊ n⌋ } } Examples for linear but not time-invariant systems:
xn, n 0 yn = ≥ = xn un 0, n< 0 yn = x n/4 ⌊ ⌋ y = x (eωjn) n n ℜ Examples for linear time-invariant non-causal systems: 1 yn = (xn 1 + xn+1) 2 − 9 sin(πkω) y = x [0.5+0.5 cos(πk/10)] n n+k πkω k= 9 −
16 Constant-coefficient difference equations Of particular practical interest are causal linear time-invariant systems of the form
xn b0 yn N −1 yn = b0 xn ak yn k z − − a1 k=1 − yn−1 z−1 a Block diagram representation − 2 yn−2 of sequence operations: ′ z−1 xn a − 3 ′ yn−3 xn xn + xn Addition:
Multiplication xn a axn by constant: The ak and bm are constant coefficients. xn xn−1 Delay: z−1
17 or
xn xn− xn− xn− −1 1 −1 2 −1 3 M z z z
yn = bm xn m b0 b1 b2 b3 − m=0 yn or the combination of both: −1 xn b0 a0 yn
z−1 z−1 b1 a1 N M − xn−1 yn−1 ak yn k = bm xn m − − z−1 z−1 k=0 m=0 b a 2 − 2 xn−2 yn−2
z−1 z−1 b a 3 − 3 xn−3 yn−3
The MATLAB function filter is an efficient implementation of the last variant. 18 Convolution
All linear time-invariant (LTI) systems can be represented in the form
∞ yn = ak xn k − k= −∞ where a is a suitably chosen sequence of coefficients. { k} This operation over sequences is called convolution and defined as
∞ pn qn = rn n Z : rn = pk qn k. { } ∗ { } { } ⇐⇒ ∀ ∈ − k= −∞ If y = a x is a representation of an LTI system T , with { n} { n} ∗ { n} yn = T xn , then we call the sequence an the impulse response {of T}, because{ } a = T δ . { } { n} { n}
19
Convolution examples
A B C D
E F A∗B A∗C
C∗A A∗E D∗E A∗F
20 Properties of convolution For arbitrary sequences p , q , r and scalars a, b: { n} { n} { n} Convolution is associative → ( p q ) r = p ( q r ) { n} ∗ { n} ∗ { n} { n} ∗ { n} ∗ { n} Convolution is commutative → p q = q p { n} ∗ { n} { n} ∗ { n} Convolution is linear → p a q + b r = a ( p q )+ b ( p r ) { n} ∗ { n n} { n} ∗ { n} { n} ∗ { n} The impulse sequence (slide 13) is neutral under convolution → p δ = δ p = p { n} ∗ { n} { n} ∗ { n} { n} Sequence shifting is equivalent to convolving with a shifted → impulse pn d = pn δn d { − } { } ∗ { − } 21
Can all LTI systems be represented by convolution?
Any sequence xn can be decomposed into a weighted sum of shifted impulse sequences:{ }
∞ xn = xk δn k { } { − } k= −∞ ( ) ( ) Let’s see what happens if we apply a linear ∗ time-invariant ∗∗ system T to such a decomposed sequence:
∞ ( ) ∞ T xn = T xk δn k =∗ xk T δn k { } { − } { − } k= k= −∞ −∞ ( ) ∞ ∞ =∗∗ xk δn k T δn = xk δn k T δn { − } ∗ { } { − } ∗ { } k= k= −∞ −∞ = x T δ q.e.d. { n} ∗ { n} The impulse response T δ fully characterizes an LTI system. ⇒ { n} 22 Exercise 1 What type of discrete system (linear/non-linear, time-invariant/ non-time-invariant, causal/non-causal, causal, memory-less, etc.) is:
3xn 1 + xn 2 (a) yn = xn (e) yn = − − | | xn 3 − n/14 (b) yn = xn 1 + 2xn xn+1 (f) yn = xn e − − − 8 (g) yn = xn un (c) yn = xn i − i=0 ∞ (h) yn = xi δi n+2 1 − (d) yn = 2 (x2n + x2n+1) i= −∞ Exercise 2 Prove that convolution is (a) commutative and (b) associative.
23
Exercise 3 A finite-length sequence is non-zero only at a finite number of positions. If m and n are the first and last non-zero positions, respectively, then we call n m +1 the length of that sequence. What maximum length − can the result of convolving two sequences of length k and l have?
Exercise 4 The length-3 sequence a = 3, a = 2, a = 1 is convolved 0 − 1 2 with a second sequence b of length 5. { n} (a) Write down this linear operation as a matrix multiplication involving a matrix A, a vector b R5, and a result vector c. ∈ (b) Use MATLAB to multiply your matrix by the vector b = (1, 0, 0, 2, 2) and compare the result with that of using the conv function. (c) Use the MATLAB facilities for solving systems of linear equations to undo the above convolution step.
Exercise 5 (a) Find a pair of sequences a and b , where each one { n} { n} contains at least three different values and where the convolution a b { n}∗{ n} results in an all-zero sequence. 1 (b) Does every LTI system T have an inverse LTI system T − such that 1 xn = T − T xn for all sequences xn ? Why? { } { } { } 24 Direct form I and II implementations
−1 −1 xn b0 a0 yn xn a0 b0 yn
z−1 z−1 z−1 b a a b 1 − 1 − 1 1 xn−1 yn−1
z−1 z−1 = z−1 b a a b 2 − 2 − 2 2 xn−2 yn−2
z−1 z−1 z−1 b a a b 3 − 3 − 3 3 xn−3 yn−3 The block diagram representation of the constant-coefficient difference equation on slide 18 is called the direct form I implementation. The number of delay elements can be halved by using the commuta- tivity of convolution to swap the two feedback loops, leading to the direct form II implementation of the same LTI system. These two forms are only equivalent with ideal arithmetic (no rounding errors and range limits). 25
Convolution: optics example If a projective lens is out of focus, the blurred image is equal to the original image convolved with the aperture shape (e.g., a filled circle):
= ∗
as Point-spread function h (disk, r = 2f ): image plane focal plane
1 , x2 + y2 r2 h(x, y)= r2π ≤ 0, x2 + y2 >r2 a Original image I, blurred image B = I h, i.e. ∗
B(x, y)= I(x x′,y y′) h(x′,y′) dx′dy′ s − − f 26 Convolution: electronics example
R Uin Uin Uin √2
U C U out in out U
Uout
0 t 0 1/RC ω (= 2πf)
Any passive network (R,L,C) convolves its input voltage Uin with an impulse response function h, leading to U = U h, that is out in ∗ ∞ U (t)= U (t τ) h(τ) dτ out in − −∞ In this example:
1 −t Uin Uout dUout e RC , t 0 − = C , h(t)= RC ≥ R dt 0, t< 0
27
Why are sine waves useful? 1) Adding together sine waves of equal frequency, but arbitrary ampli- tude and phase, results in another sine wave of the same frequency: A sin(ωt + ϕ )+ A sin(ωt + ϕ ) = A sin(ωt + ϕ) 1 1 2 2 with
A = A2 + A2 +2A A cos(ϕ ϕ ) 1 2 1 2 2 − 1 A sin ϕ + A sin ϕ tan ϕ = 1 1 2 2 A A sin(ϕ ) A1 cos ϕ1 + A2 cos ϕ2 A 2 2 2 Sine waves of any phase can be ϕ2 A A cos(ϕ ) formed from sin and cos alone: 1 2 2 ωt A sin(ϕ ) ϕ 1 1 ϕ1 A sin(ωt + ϕ)= A cos(ϕ ) 1 1 a sin(ωt)+ b cos(ωt) with a = A cos(ϕ), b = A sin(ϕ) and A = √a2 + b2, tan ϕ = b . a 28 Note: Convolution of a discrete sequence x with another sequence { n} yn is nothing but adding together scaled and delayed copies of xn . (Think{ } of y decomposed into a sum of impulses.) { } { n} If x is a sampled sine wave of frequency f, so is x y ! { n} { n} ∗ { n} = Sine-wave sequences form a family of discrete sequences that⇒ is closed under convolution with arbitrary sequences.
The same applies for continuous sine waves and convolution.
2) Sine waves are orthogonal to each other:
∞ sin(ω t + ϕ ) sin(ω t + ϕ )dt “=” 0 1 1 2 2 −∞ ω = ω ϕ ϕ = (2k + 1)π/2 (k Z) ⇐⇒ 1 2 ∨ 1 − 2 ∈ They can be used to form an orthogonal function basis for a transform. The term “orthogonal” is used here in the context of an (infinitely dimensional) vector space, where the “vectors” are functions of the form f : R R (or f : R C) and the scalar product is defined as f g = ∞ f(t) g(t)dt. → → −∞ 29
Why are exponential functions useful? Adding together two exponential functions with the same base z, but different scale factor and offset, results in another exponential function with the same base: A zt+ϕ1 + A zt+ϕ2 = A zt zϕ1 + A zt zϕ2 1 2 1 2 = (A zϕ1 + A zϕ2 ) zt = A zt 1 2 Likewise, if we convolve a sequence x of values { n} 3 2 1 2 3 ...,z− ,z− ,z− , 1,z,z ,z ,... x = zn with an arbitrary sequence h , we get y = zn h , n { n} { n} { } ∗ { n} ∞ ∞ ∞ n k n k n yn = xn k hk = z − hk = z z− hk = z H(z) − k= k= k= −∞ −∞ −∞ where H(z) is independent of n. Exponential sequences are closed under convolution with arbitrary sequences. The same applies in the continuous case. 30 Why are complex numbers so useful? 1) They give us all n solutions (“roots”) of equations involving poly- nomials up to degree n (the “ √ 1 = j ” story). − 2) They give us the “great unifying theory” that combines sine and exponential functions:
1 jωt jωt cos(ωt) = e +e− 2 1 jωt jωt sin(ωt) = e e− 2j − or 1 jωt+ϕ jωt ϕ cos(ωt + ϕ)= e +e− − 2 or cos(ωn + ϕ) = (ejωn+ϕ) = [(ejω)n ejϕ] ℜ ℜ sin(ωn + ϕ) = (ejωn+ϕ) = [(ejω)n ejϕ] ℑ ℑ Notation: (a + jb) := a and (a + jb) := b where j2 = 1 and a,b R. ℜ ℑ − ∈ 31
We can now represent sine waves as projections of a rotating complex vector. This allows us to represent sine-wave sequences as exponential sequences with basis ejω. A phase shift in such a sequence corresponds to a rotation of a complex vector. 3) Complex multiplication allows us to modify the amplitude and phase of a complex rotating vector using a single operation and value. Rotation of a 2D vector in (x,y)-form is notationally slightly messy, but fortunately j2 = 1 does exactly what is required here: −
x3 x2 y2 x1 = − (x3,y3) y3 y2 x2 y1 x x y y ( y2, x2) = 1 2 1 2 − x y +− x y 1 2 2 1 (x2,y2) (x1,y1) z1 = x1 + jy1, z2 = x2 + jy2 z z = x x y y + j(x y + x y ) 1 2 1 2 − 1 2 1 2 2 1
32 Complex phasors Amplitude and phase are two distinct characteristics of a sine function that are inconvenient to keep separate notationally. Complex functions (and discrete sequences) of the form A ej(ωt+ϕ) = A [cos(ωt + ϕ)+j sin(ωt + ϕ)] (where j2 = 1) are able to represent both amplitude and phase in one single algebraic− object. Thanks to complex multiplication, we can also incorporate in one single factor both a multiplicative change of amplitude and an additive change of phase of such a function. This makes discrete sequences of the form jωn xn =e eigensequences with respect to an LTI system T , because for each ω, there is a complex number (eigenvalue) H(ω) such that T x = H(ω) x { n} { n} In the notation of slide 30, where the argument of H is the base, we would write H(e jω). 33
Recall: Fourier transform We define the Fourier integral transform and its inverse as
∞ 2πjft g(t) (f) = G(f) = g(t) e− dt F{ } −∞
1 ∞ 2πjft − G(f) (t) = g(t) = G(f) e df F { } −∞ Many equivalent forms of the Fourier transform are used in the literature. There is no strong consensus on whether the forward transform uses e−2π jft and the backwards transform e2π jft, or vice versa. The above form uses the ordinary frequency f, whereas some authors prefer the angular frequency ω =2πf:
∞ h(t) (ω) = H(ω) = α h(t) e∓ jωt dt F{ } −∞
∞ −1 H(ω) (t) = h(t) = β H(ω) e± jωt dω F { } −∞
This substitution introduces factors α and β such that αβ = 1/(2π). Some authors set α = 1 and β = 1/(2π), to keep the convolution theorem free of a constant prefactor; others prefer the unitary form α = β =1/√2π, in the interest of symmetry. 34 Properties of the Fourier transform If x(t) X(f) and y(t) Y (f) •−◦ •−◦ are pairs of functions that are mapped onto each other by the Fourier transform, then so are the following pairs. Linearity: ax(t)+ by(t) aX(f)+ bY (f) •−◦ Time scaling: 1 f x(at) X •−◦ a a | | Frequency scaling:
1 t x X(af) a a •−◦ | |
35
Time shifting:
2πjf∆t x(t ∆t) X(f) e− − •−◦ Frequency shifting:
x(t) e2πj∆ft X(f ∆f) •−◦ − Parseval’s theorem (total energy):
∞ ∞ x(t) 2dt = X(f) 2df | | | | −∞ −∞
36 Fourier transform example: rect and sinc The Fourier transform of the “rectangular function”
1 if t < 1 | | 2 1 rect(t)= 1 if t = 1 2 | | 2 0 0 otherwise 1 0 1 − 2 2 is the “(normalized) sinc function”
1 2 π 2πjft sin f rect(t) (f)= e− dt = = sinc(f) F{ } 1 πf − 2 and vice versa sinc(t) (f) = rect(f). F{ } Some noteworthy properties of these functions: 1 ∞ sinc(t)dt =1= ∞ rect(t)dt • −∞ −∞ sinc(0) = 1 = rect(0) • 0 n Z 0 : sinc(n)=0 3 2 10 1 2 3 • ∀ ∈ \{ } − − − 37
Convolution theorem Continuous form:
(f g)(t) = f(t) g(t) F{ ∗ } F{ } F{ } f(t) g(t) = f(t) g(t) F{ } F{ }∗F{ } Discrete form:
x y = z X(ejω) Y (ejω) = Z(ejω) { n} ∗ { n} { n} ⇐⇒ Convolution in the time domain is equivalent to (complex) scalar mul- tiplication in the frequency domain. Convolution in the frequency domain corresponds to scalar multiplica- tion in the time domain.
Proof: z(r)= x(s)y(r s)ds z(r)e− jωrdr = x(s)y(r s)e− jωrdsdr = s − ⇐⇒ r r s − t:=r−s x(s) y(r s)e− jωrdrds = x(s)e− jωs y(r s)e− jω(r−s)drds = s r − s r − x(s)e− jωs y(t)e− jωtdtds = x(s)e− jωsds y(t)e− jωtdt. (Same for instead of .) s t s t 38 Dirac delta function The continuous equivalent of the impulse sequence δn is known as Dirac delta function δ(x). It is a generalized function,{ } defined such that
0, x =0 1 δ(x) = , x =0 ∞ ∞ δ(x)dx = 1 −∞ 0 x and can be thought of as the limit of function sequences such as 0, x 1/n δ(x)= lim | |≥ n n/2, x < 1/n →∞ | | or n n2x2 δ(x)= lim e− n π →∞ √ The delta function is mathematically speaking not a function, but a distribution, that is an expression that is only defined when integrated. 39
Some properties of the Dirac delta function:
∞ f(x)δ(x a)dx = f(a) − −∞ ∞ 2πjxa e± dx = δ(a) −∞ ∞ ∞ 2πjnxa 1 e± = δ(x n/a) a − n= n= −∞ | | −∞ 1 δ(ax) = δ(x) a | | Fourier transform:
∞ 2πjft 0 δ(t) (f) = δ(t) e− dt = e = 1 F{ } −∞
1 ∞ 2πjft − 1 (t) = 1 e df = δ(t) F { } −∞ 40 Sine and cosine in the frequency domain
1 2πjf t 1 2πjf t 1 2πjf t 1 2πjf t cos(2πf t)= e 0 + e− 0 sin(2πf t)= e 0 e− 0 0 2 2 0 2j − 2j 1 1 cos(2πf t) (f)= δ(f f )+ δ(f + f ) F{ 0 } 2 − 0 2 0 j j sin(2πf t) (f)= δ(f f )+ δ(f + f ) F{ 0 } −2 − 0 2 0
ℜ ℜ 1 1 2 2 1 ℑ 1 ℑ 2 j 2 j
f f f f f f − 0 0 − 0 0
As any x(t) R can be decomposed into sine and cosine functions, the spectrum of any real- valued signal∈ will show the symmetry X(e jω) = [X(e− jω)]∗, where ∗ denotes the complex conjugate (i.e., negated imaginary part). 41
Fourier transform symmetries We call a function x(t)
odd if x( t) = x(t) − − even if x( t) = x(t) − and ∗ is the complex conjugate, such that (a +jb)∗ =(a jb). − Then
x(t) is real X( f)=[X(f)]∗ ⇔ − x(t) is imaginary X( f)= [X(f)]∗ x(t) is even ⇔ X(f−) is even− x(t) is odd ⇔ X(f) is odd x(t) is real and even ⇔ X(f) is real and even x(t) is real and odd ⇔ X(f) is imaginary and odd x(t) is imaginary and even ⇔ X(f) is imaginary and even x(t) is imaginary and odd ⇔ X(f) is real and odd ⇔
42 Example: amplitude modulation Communication channels usually permit only the use of a given fre- quency interval, such as 300–3400 Hz for the analog phone network or 590–598 MHz for TV channel 36. Modulation with a carrier frequency fc shifts the spectrum of a signal x(t) into the desired band. Amplitude modulation (AM):
y(t)= A cos(2πtf ) x(t) c X(f) Y (f) = ∗
f 0 f ffc fc ffc 0 fc f − l l − − The spectrum of the baseband signal in the interval f Sampling using a Dirac comb The loss of information in the sampling process that converts a con- tinuous function x(t) into a discrete sequence x defined by { n} x = x(t n)= x(n/f ) n s s can be modelled through multiplying x(t) by a comb of Dirac impulses ∞ s(t)= t δ(t t n) s − s n= −∞ to obtain the sampled function xˆ(t)= x(t) s(t) The functionx ˆ(t) now contains exactly the same information as the discrete sequence xn , but is still in a form that can be analysed using the Fourier transform{ } on continuous functions. 44 The Fourier transform of a Dirac comb ∞ ∞ π s(t)= t δ(t t n) = e2 jnt/ts s − s n= n= −∞ −∞ is another Dirac comb ∞ S(f)= t δ(t t n) (f)= F s − s n= −∞ ∞ ∞ ∞ n t δ(t t n)e2πjftdt = δ f . s − s − t n= n= s −∞ −∞ −∞ s(t) S(f) 2t t 0t 2t t 2f f 0 f 2f f − s − s s s − s − s s s 45 Sampling and aliasing sample cos(2π tf) cos(2π t(k⋅ f ± f)) s 0 Sampled at frequency fs, the function cos(2πtf) cannot be distin- guished from cos[2πt(kf f)] for any k Z. s ± ∈ 46 Frequency-domain view of sampling x(t) s(t) xˆ(t) = ...... 0 t1/fs 0 1/fs t1/fs 0 1/fs t − − X(f) S(f) Xˆ(f) = ∗ ...... 0 ffs fs ffs 0 fs f − − Sampling a signal in the time domain corresponds in the frequency domain to convolving its spectrum with a Dirac comb. The resulting copies of the original signal spectrum in the spectrum of the sampled signal are called “images”. 47 Discrete-time Fourier transform The Fourier transform of a sampled signal ∞ xˆ(t)= t x δ(t t n) s n − s n= −∞ is ∞ f ∞ 2πjft 2πj n xˆ(t) (f)= Xˆ(f)= xˆ(t) e− dt = t x e− fs F{ } s n n= −∞ −∞ jω − jωn Some authors prefer the notation Xˆ(e )= xn e to highlight the periodicity of Xˆ and n its relationship with the z-transform (slide 99). The inverse transform is fs/2 ∞ 2πjft 2πj f m xˆ(t)= Xˆ(f) e df or xm = Xˆ(f) e fs df. fs/2 −∞ − 48 Nyquist limit and anti-aliasing filters If the (double-sided) bandwidth of a signal to be sampled is larger than the sampling frequency fs, the images of the signal that emerge during sampling may overlap with the original spectrum. Such an overlap will hinder reconstruction of the original continuous signal by removing the aliasing frequencies with a reconstruction filter. Therefore, it is advisable to limit the bandwidth of the input signal to the sampling frequency fs before sampling, using an anti-aliasing filter. In the common case of a real-valued base-band signal (with frequency content down to 0 Hz), all frequencies f that occur in the signal with non-zero power should be limited to the interval f /2 49 Nyquist limit and anti-aliasing filters Without anti-aliasing filter With anti-aliasing filter single-sided Nyquist X(f) bandwidth X(f) limit = fs/2 anti-aliasing filter 0 f f 0 f f − s s double-sided bandwidth Xˆ(f) Xˆ(f) reconstruction filter 2f f 0f 2f f 2f f 0f 2f f − s − s s s − s − s s s Anti-aliasing and reconstruction filters both suppress frequencies outside f fs 1 if f < 2 H(f)= | | = rect(tsf). 0 if f > fs | | 2 This leads, after an inverse Fourier transform, to the impulse response sin πtf 1 t h(t)= f s = sinc . s πtf t t s s s The original band-limited signal can be reconstructed by convolving this with the sampled signalx ˆ(t), which eliminates the periodicity of the frequency domain introduced by the sampling process: x(t)= h(t) xˆ(t) ∗ Note that sampling h(t) gives the impulse function: h(t) s(t)= δ(t). 51 Impulse response of ideal low-pass filter with cut-off frequency fs/2: 0 −3 −2.5 −2 −1.5 −1 −0.5 0 0.5 1 1.5 2 2.5 3 t⋅ f s 52 Reconstruction filter example sampled signal interpolation result scaled/shifted sin(x)/x pulses 1 2 3 4 5 53 Reconstruction filters The mathematically ideal form of a reconstruction filter for suppressing aliasing frequencies interpolates the sampled signal xn = x(ts n) back into the continuous waveform ∞ sin π(t t n) x(t)= x − s . n π(t t n) n= s −∞ − Choice of sampling frequency Due to causality and economic constraints, practical analog filters can only approx- imate such an ideal low-pass filter. Instead of a sharp transition between the “pass band” (< fs/2) and the “stop band” (> fs/2), they feature a “transition band” in which their signal attenuation gradually increases. The sampling frequency is therefore usually chosen somewhat higher than twice the highest frequency of interest in the continuous signal (e.g., 4 ). On the other hand, the higher the sampling frequency, the higher are CPU, po×wer and memory requirements. Therefore, the choice of sampling frequency is a tradeoff between signal quality, analog filter cost and digital subsystem expenses. 54 Exercise 6 Digital-to-analog converters cannot output Dirac pulses. In- stead, for each sample, they hold the output voltage (approximately) con- stant, until the next sample arrives. How can this behaviour be modeled mathematically as a linear time-invariant system, and how does it affect the spectrum of the output signal? Exercise 7 Many DSP systems use “oversampling” to lessen the require- ments on the design of an analog reconstruction filter. They use (a finite approximation of) the sinc-interpolation formula to multiply the sampling frequency fs of the initial sampled signal by a factor N before passing it to the digital-to-analog converter. While this requires more CPU operations and a faster D/A converter, the requirements on the subsequently applied analog reconstruction filter are much less stringent. Explain why, and draw schematic representations of the signal spectrum before and after all the relevant signal-processing steps. Exercise 8 Similarly, explain how oversampling can be applied to lessen the requirements on the design of an analog anti-aliasing filter. 55 Band-pass signal sampling Sampled signals can also be reconstructed if their spectral components remain entirely within the interval n fs/2 < f < (n + 1) fs/2 for some n N. (The baseband case discussed so| far| is just n = 0.) In this case,∈ the aliasing copies of the positive and the negative frequencies will interleave instead of overlap, and can therefore be removed again with a reconstruction filter with the impulse response sin πtfs/2 2n +1 sin πt(n + 1)fs sin πtnfs h(t)= fs cos 2πtfs =(n + 1)fs nfs . πtfs/2 4 πt(n + 1)fs − πtnfs X(f) anti-aliasing filterXˆ(f) reconstruction filter 5 5 − fs 0 fs f fs fs 0 fs fs f − 4 4 − 2 2 n =2 56 IQ sampling Consider signal x(t) R in which only frequencies f < f < f are ∈ l | | h of interest. This band has a centre frequency of fc =(fl + fh)/2 and a bandwidth B = fh fl. It can be sampled efficiently (at the lowest possible sampling frequency)− as follows: Shift its spectrum by f : → − c 2π jfct y(t)= x(t) e− Low-pass filter it with a cut-off frequency of B/2: → z(t)= B ∞y(τ) sinc((t τ)B) dτ Z(f)= Y (f) rect(f/B) − •−◦ −∞ Sample the result at sampling frequency B: → zn = z(n/B) 57 X(f) δ(f + fc) ∗ f 0 f f f 0 f f − c c − c c Y (f) anti-aliasing filter Zˆ(f) Z(f) sample −→ 2fc fc −B 0 B fc f 2fc fc 0 B fc f − − 2 2 − − Shifting the center frequency fc of the interval of interest to 0 Hz (DC) makes the spectrum asymmetric. This leads to a complex-valued time- domain representation ( f : Z(f) =[Z( f)]∗ = t : z(t) C R). ∃ − ⇒∃ ∈ \ 58 The real part (z(t)) is also known as “in-phase” signal (I) and the imaginary partℜ (z(t)) as “quadrature” signal (Q). ℑ sample Q ⊗◦ x(t) 90 y(t) z(t) zn − sample I ⊗ Q cos(2πfct) Consider: sin(x) = cos(x 1 π) • − 2 cos(x) cos(x)= 1 + 1 cos 2x • 2 2 sin(x) sin(x)= 1 1 cos 2x I • 2 − 2 sin(x) cos(x)= 0+ 1 sin2x • 2 cos(x) cos(x ϕ)= 1 cos(ϕ)+ 1 cos(2x ϕ) • − 2 2 − sin(x) cos(x ϕ)= 1 sin(ϕ)+ 1 sin(2x ϕ) • − 2 2 − 59 [z(t)] ℑ Recall products of sine and cosine: cos(x) cos(y)= 1 cos(x y)+ 1 cos(x + y) • 2 − 2 sin(x) sin(y)= 1 cos(x y) 1 cos(x + y) • 2 − − 2 sin(x) cos(y)= 1 sin(x y)+ 1 sin(x + y) • 2 − 2 [z(t)] ℜ Examples: Amplitude-modulated signal: 1 x(t)= s(t) cos(2πtf + ϕ) z(t)= s(t) ejϕ c −→ 2 Noncoherent demodulation: s(t)=2 z(t) (s(t) > 0 required) | | Coherent demodulation: s(t)=2 [z(t) e− jϕ] (ϕ required) ℜ Frequency-modulated signal: t 1 j t s(τ)dτ+jϕ x(t) = cos 2πtf + s(τ)dτ + ϕ z(t)= e 0 c −→ 2 0 t t d d j s(τ)dτ j s(τ)dτ Demodulation: s(t)=2 z(t) = e R0 e jϕ = js(t) e R0 (if s(t) > 0) dt dt dz(t) ∗ 2 or alternatively s(t)= dt z (t)/ z(t) ℑ | | 60 Digital modulation schemes ASK BPSK QPSK 10 00 01 0 1 11 01 8PSK101 16QAM FSK 1 111 100 00 0 110 000 01 11 010 001 10 011 00 01 11 10 61 Exercise 9 Reconstructing a sampled baseband signal: Generate a one second long Gaussian noise sequence r (using • { n} MATLAB function randn) with a sampling rate of 300 Hz. Use the fir1(50, 45/150) function to design a finite impulse re- • sponse low-pass filter with a cut-off frequency of 45 Hz. Use the filtfilt function in order to apply that filter to the generated noise signal, resulting in the filtered noise signal x . { n} Then sample x at 100 Hz by setting all but every third sample • { n} value to zero, resulting in sequence y . { n} Generate another low-pass filter with a cut-off frequency of 50 Hz • and apply it to y , in order to interpolate the reconstructed filtered { n} noise signal z . Multiply the result by three, to compensate the { n} energy lost during sampling. Plot x , y , and z . Finally compare x and z . • { n} { n} { n} { n} { n} Why should the first filter have a lower cut-off frequency than the second? 62 Exercise 10 Reconstructing a sampled band-pass signal: Generate a 1 s noise sequence r , as in exercise 9, but this time • { n} use a sampling frequency of 3 kHz. Apply to that a band-pass filter that attenuates frequencies outside • the interval 31–44 Hz, which the MATLAB Signal Processing Toolbox function cheby2(3, 30, [31 44]/1500) will design for you. Then sample the resulting signal at 30 Hz by setting all but every • 100-th sample value to zero. Generate with cheby2(3, 20, [30 45]/1500) another band-pass • filter for the interval 30–45 Hz and apply it to the above 30-Hz- sampled signal, to reconstruct the original signal. (You’ll have to multiply it by 100, to compensate the energy lost during sampling.) Plot all the produced sequences and compare the original band-pass • signal and that reconstructed after being sampled at 30 Hz. Why does the reconstructed waveform differ much more from the original if you reduce the cut-off frequencies of both band-pass filters by 5 Hz? 63 Spectrum of a periodic signal A signal x(t) that is periodic with frequency fp can be factored into a single periodx ˙(t) convolved with an impulse comb p(t). This corre- sponds in the frequency domain to the multiplication of the spectrum of the single period with a comb of impulses spaced fp apart. x(t) x˙(t) p(t) = ∗ ...... 1/fp 0 1/fp t t1/fp 0 1/fp t − − X(f) X˙ (f) P (f) = ...... fp 0 fp f ffp 0 fp f − − 64 Spectrum of a sampled signal A signal x(t) that is sampled with frequency fs has a spectrum that is periodic with a period of fs. x(t) s(t) xˆ(t) = ...... 0 t1/fs 0 1/fs t1/fs 0 1/fs t − − X(f) S(f) Xˆ(f) = ∗ ...... 0 ffs fs ffs 0 fs f − − 65 Continuous vs discrete Fourier transform Sampling a continuous signal makes its spectrum periodic • A periodic signal has a sampled spectrum • We sample a signal x(t) with fs, gettingx ˆ(t). We take n consecutive samples ofx ˆ(t) and repeat these periodically, getting a new signalx ¨(t) with period n/fs. Its spectrum X¨(f) is sampled (i.e., has non-zero value) at frequency intervals fs/n and repeats itself with a period fs. Now bothx ¨(t) and its spectrum X¨(f) are finite vectors of length n. x¨(t) X¨(f) ...... −1 −1 n/fs f 0 f n/fs t fs fs/n 0 fs/n fs f − s s − − 66 Discrete Fourier Transform (DFT) n 1 n 1 − − 2π j ik 1 2π j ik X = x e− n x = X e n k i k n i i=0 i=0 The n-point DFT multiplies a vector with an n n matrix × 1 1 1 1 1 − π 1 − π 2 − π 3 − π n−1 1 e 2 j n e 2 j n e 2 j n e 2 j n − π 2 − π 4 − π 6 − π 2(n−1) 1 e 2 j n e 2 j n e 2 j n e 2 j n n− Fn = −2π j 3 −2π j 6 −2π j 9 −2π j 3( 1) 1 e n e n e n e n ...... ...... − π n−1 − π 2(n−1) − π 3(n−1) − π (n−1)(n−1) 2 j n 2 j n 2 j n 2 j n 1 e e e e x0 X0 X0 x0 x1 X1 X1 x1 1 ∗ x2 X2 X2 x2 Fn = , Fn = . . n . . . . . . xn− Xn− Xn− xn− 1 1 1 1 67 Discrete Fourier Transform visualized x0 X0 x1 X1 x2 X2 x3 X3 = x4 X4 x5 X5 x6 X6 x7 X7 The n-point DFT of a signal x sampled at frequency f contains in { i} s the elements X0 to Xn/2 of the resulting frequency-domain vector the frequency components 0, fs/n, 2fs/n, 3fs/n, ..., fs/2, and contains in Xn 1 downto Xn/2 the corresponding negative frequencies. Note − that for a real-valued input vector, both X0 and Xn/2 will be real, too. Why is there no phase information recovered at fs/2? 68 Inverse DFT visualized X0 x0 X1 x1 X2 x2 1 X3 x3 = 8 X4 x4 X5 x5 X6 x6 X7 x7 69 Fast Fourier Transform (FFT) n 1 n 1 − 2πj ik x − = x e− n Fn{ i}i=0 k i i=0 n n 2 1 2 1 − ik − ik 2πj 2πj k 2πj = x e− n/2 + e− n x e− n/2 2i 2i+1 i=0 i=0 n 1 π k n 1 n 2 − 2 j n n 2 − n x2i i=0 + e− x2i+1 i=0 , k< F 2 { } k F 2 { } k 2 = n k n 2 1 2πj 2 1 n n x2i − + e− n n x2i+1 − , k 2 i=0 n 2 i=0 n 2 F { } k 2 F { } k 2 ≥ − − The DFT over n-element vectors can be reduced to two DFTs over n/2-element vectors plus n multiplications and n additions, leading to log2 n rounds and n log2 n additions and multiplications overall, com- pared to n2 for the equivalent matrix multiplication. A high-performance FFT implementation in C with many processor-specific optimizations and support for non-power-of-2 sizes is available at http://www.fftw.org/. 70 Efficient real-valued FFT The symmetry properties of the Fourier transform applied to the discrete n 1 n 1 Fourier transform X − = x − have the form { i}i=0 Fn{ i}i=0 i : xi = (xi) i : Xn i = Xi∗ ∀ ℜ ⇐⇒ ∀ − i : xi = j (xi) i : Xn i = Xi∗ ∀ ℑ ⇐⇒ ∀ − − These two symmetries, combined with the linearity of the DFT, allows us to calculate two real-valued n-point DFTs n 1 n 1 n 1 n 1 X′ − = x′ − X′′ − = x′′ − { i}i=0 Fn{ i}i=0 { i }i=0 Fn{ i }i=0 simultaneously in a single complex-valued n-point DFT, by composing its input as x = x′ + j x′′ i i i and decomposing its output as 1 1 Xi′ = (Xi + Xn∗ i) Xi′′ = (Xi Xn∗ i) 2 − 2 − − To optimize the calculation of a single real-valued FFT, use this trick to calculate the two half-size real-value FFTs that occur in the first round. 71 Fast complex multiplication Calculating the product of two complex numbers as (a +jb) (c +jd)=(ac bd)+ j(ad + bc) − involves four (real-valued) multiplications and two additions. The alternative calculation α = a(c + d) (a +jb) (c +jd)=(α β)+ j(α + γ) with β = d(a + b) − γ = c(b a) − provides the same result with three multiplications and five additions. The latter may perform faster on CPUs where multiplications take three or more times longer than additions. This trick is most helpful on simpler microcontrollers. Specialized signal-processing CPUs (DSPs) feature 1-clock-cycle multipliers. High-end desktop processors use pipelined multipliers that stall where operations depend on each other. 72 FFT-based convolution m 1 n 1 Calculating the convolution of two finite sequences xi i=0− and yi i=0− of lengths m and n via { } { } min m 1,i { − } zi = xj yi j, 0 i