EECS 452 – Lecture 2

Today: Sampling and reconstruction review FIR and IIR filters C5515 eZDSP Direct digital synthesis

Reminders: HW 1 is due on tuesday. PPI is due on Thurs (email to hero by 5PM) Lab starts next week.

Last one out should close the lab door!!!! Please keep the lab clean and organized.

The numbers may be said to rule the whole world of quantity, and the four rules of arithmetic may be regarded as the complete equipment of the mathematician. — James C. Maxwell EECS 452 – Fall 2014 Lecture 2 – Page 1/45 Thurs – 9/4/2014 Sampling and reconstruction

Here, as last time, F denotes Herzian freq. and f denotes Digital freq. Sampling is the part of the Analog-to-Digital Converter (ADC) that converts cts time signal x(t) into discrete time signal x[n] = X(nTs). Fs = 1/Ts is the sampling rate (samples/sec). Reconstruction is the part of the Digital-to-Analog Converter (DAC) that converts discrete time signal x[n] = x(nTs) to cts time signal x(t). Fs = 1/Ts is the conversion rate. Sampling and reconstruction are commonly combined into a ADC/DAC device called the CODEC (Coder-Decoder). The C5515 and DE2 have audio CODECs on board. CODEC’s work well as long as x(t) does not have significant energy at frequencies above Fs/2 Hz R ∞ −j2πF t Can verify this condition using FT: X(F ) = −∞ x(t)e dt

EECS 452 – Fall 2014 Lecture 2 – Page 2/45 Thurs – 9/4/2014 Simply bandlimited waveforms

Lowpass signal: Negligible energy (X(F ) = 0) for all |F | > B. Single sided bandwidth is B Hz.

If sample x(t) at Fs > 2B samples/sec can exactly reconstruct. (Nyquist sampling theorem)

Bandpass signal: Negligible energy outside of a band, B = F2 − F1 not containing 0 Hz.

If sample at Fs > 2B can exactly reconstruct. (bandpass sampling theorema)

Note that for bandpass waveforms do not need Fs > 2F2!

asee http: www.eiscat.se:8080/usersguide/BPsampling.html

EECS 452 – Fall 2014 Lecture 2 – Page 3/45 Thurs – 9/4/2014 Sampling & reconstruction for a sinusoid

Analog waveform 1

0.5

0 Analog wave-

amplitude −0.5 form.

−1 0 0.2 0.4 0.6 0.8 1 −3 Time quantized waveform x 10 1

0.5 Uniformly

0 time sampled.

amplitude −0.5

−1 0 0.2 0.4 0.6 0.8 1 −3 Reconstructed time quantized waveformx 10 1 Reconstructed 0.5 (zero-order 0 hold).

amplitude −0.5

−1 0 0.2 0.4 0.6 0.8 1 time in seconds x 10−3

EECS 452 – Fall 2014 Lecture 2 – Page 4/45 Thurs – 9/4/2014 Cannot reliably reconstruct without knowing input frequency range

Samples from single period of sinusoid

There are many higher fre- quency sinusoids that could fit samples.

⇒ For unambiguous reconstruction need at least 2 samples per cycle

EECS 452 – Fall 2014 Lecture 2 – Page 5/45 Thurs – 9/4/2014 What happens when we sample?

Performing ideal sampling on an analog signal x(t) means the following:

∞ X xs(t) = x(t)p(t) = x(nTs)δ(t − nTs) n=−∞

P∞ where p(t) is the pulse train n=−∞ δ(t − nTs) with sample spacing Ts.

∞ −1 X k P (F ) = F{p(t)} = Ts δ(F − ) Ts k=−∞

Taking of xs(t) (“*” denotes convolution)

∞ X k 1 Xs(F ) = X(F ) ∗ P (F ) = X(F ) ∗ δ(F − ) Ts Ts k=−∞ ∞ 1 X k = X(F − ) Ts Ts k=−∞

EECS 452 – Fall 2014 Lecture 2 – Page 6/45 Thurs – 9/4/2014 Frequency domain view of aliasing

EECS 452 – Fall 2014 Lecture 2 – Page 7/45 Thurs – 9/4/2014 Where does “the” alias land? What frequencies contain aliased components of a sampled signal?

Consider a sinusoidal signal x(t) at Fc Hz

ej2πFct + e−j2πFct x(t) = cos(2πF t) = c 2 with continuous Fourier transform (CTF) 1 1 X(F ) = δ(F + F ) + δ(F − F ) 2 c 2 c

If sample x(t) at frequency Fs, sampled signal has CTF

∞ ∞ X 1 X X (F ) = X(F −kF ) = δ(F +F −kF )+δ(F −F −kF ) s s 2 c s c s k=−∞ k=−∞

Conclude: frequency Fc will alias to the frequencies {Fc ± kFs}k6=0.

EECS 452 – Fall 2014 Lecture 2 – Page 8/45 Thurs – 9/4/2014 Relation between FT, DTFT, and DFT of xs

Consider the Fourier transform XWFT (F ) of xs(t) over the window t ∈ [0, (N − 1)Ts] (contains N samples)

N−1 Z (N−1)Ts −j2πF t X −j2πF nTs XWFT (F ) = xs(t)e dt = x[n]e 0 n=0

N−1 X −j2πfn XDTFT (f) = DTFT(x[n]) = x[n]e n=0

N−1 X −j2π k n XDFT (k) = DFT(x[n]) = x[n]e N n=0

→ XDTFT (f) = XWFT (fFs) by identifying F/Fs = f (Fs = 1/Ts).

k  k  → XDFT (k) = XDTFT N = XWFT N Fs . EECS 452 – Fall 2014 Lecture 2 – Page 9/45 Thurs – 9/4/2014 Units for Herzian, digital, and normalized digital frequency

Units typically used to describe baseband frequency range:

units range limits

F Hz Fs −Fs/2 ≤ F < Fs/2 f normalized Hz 1 −1/2 ≤ f < 1/2

ω normalized radians 2π −π ≤ ω < π

EECS 452 – Fall 2014 Lecture 2 – Page 10/45 Thurs – 9/4/2014 Comments on sampling

The frequency Fs/2 (Hz) is called the . Given a real valued lowpass spectrum with bandwidth, B the sample frequency equal to 2B is often called the Nyquist sample rate. In practice one should sample at a rate of at least two or three times the . Common sample rates:

standard telephone system 8 kHz wideband telecommunications 16 kHz home music CDs 44.1 kHz professional audio 48 kHz DVD-Audio 192 kHz instrumentation, RF, video extremely fast

EECS 452 – Fall 2014 Lecture 2 – Page 11/45 Thurs – 9/4/2014 The anti-alias filter

Anti-alias filter H is an analog LPF with bandwidth Fs/2 applied to x(t) before sampling.

Anti-alias filter eliminates frequencies that would otherwise be aliased into the baseband Fs/2 ≤ F ≤ Fs/2. Anti-alias filters need to have sharp transition band at their cutoff frequency Fs/2.

The samplers of the CODECs on the DE2 and C5515 boards have sophisticated built-in anti-alias filters. The cutoff frequencies change with the selected sample rate.

EECS 452 – Fall 2014 Lecture 2 – Page 12/45 Thurs – 9/4/2014 Reconstruction: using interpolation

Assume that bandwidth B signal x(t) has been sampled at Nyquist (Fs = 2B) giving samples x[n].

Interpolate the samples x[n] = x(nTs) using the cardinal series (FT of ideal low-pass filter (LPF) with BW B):

∞ X x(t) = x(nTs) · sinc(2πB(t − nTs)) n=−∞

I This is called the cardinal series expansion of x(t)

I This perfectly recovers the input signal x(t), per Nyquist sampling theorem

I Cardinal series reconstruction is not causal: output x(t) depends on all past and future samples x(nTs).

I A simpler sample and hold reconstruction is used in practice - but requires anti-imaging filter (will study this later)

EECS 452 – Fall 2014 Lecture 2 – Page 13/45 Thurs – 9/4/2014 Discrete time LTI filters The output y[n] of discrete time LTI filter with input x[n] is

∞ ∞ X X y[n] = h[n] ∗ x[n] = h[n − k]x[k] = h[k]x[n − k] . k=−∞ k=−∞ Take DTFT to obtain equivalent frequency domain relation:

Y (f) = H(f)X(f), f ∈ [−1/2, 1/2]

where Y (f),X(f),H(f) are DTFTs of y[n], x[n], h[n]

I h[n] is the impulse response: h[n] = y[n] when x[n] = δ[n] ( 1, n = 0 δ[n] = 0, n 6= 0

I H(f) is the transfer function of LTI

I Often LTI I/O relation is expressed in z-transform domain

Y (z) = H(z)X(z), z ∈ C

EECS 452 – Fall 2014 Lecture 2 – Page 14/45 Thurs – 9/4/2014 The z-transform The z-transform of a discrete set of values, x[n], −∞ < n < ∞, is defined as ∞ X −n XZ (z) = Z(x[n]) = x[n]z n=−∞ where z is complex valued. The z transform only exists for those values of z where the series converges. z can be written in polar form as z = rejθ. r is the magnitude of z and θ is the angle of z. When r = 1, |z| = 1 is the unit circle in the z-plane.

When x[n] = 0 for n < 0, X(z) reduces to single-sided z-transform

∞ X −n XZ (z) = Z(x[n]) = x[n]z n=0

Note: often simply written without the subscript as X(z)

EECS 452 – Fall 2014 Lecture 2 – Page 15/45 Thurs – 9/4/2014 Elementary properties of z-transform

∞ X −n XZ (z) = Z{x[n]} = x[n]z n=−∞

I If X(z),Y (z) are z-transforms of x[n], y[n]

Z{ax[n] + by[n]} = aX(z) + bY (z)

I If X(z) is z-transform of x[n] then

Z{x[n − k]} = z−kZ{x[n]}

I If XZ (z) and XDTFT (f) the z-transform and DTFT of x[n]

j2πf XDTFT (f) = XZ (e )

EECS 452 – Fall 2014 Lecture 2 – Page 16/45 Thurs – 9/4/2014 FIR digital filters

Finite impulse response (FIR) digital filters produce output y[n] sam- ples as linear combination of the most recent input samples x[n]

M X y[n] = b0x[n]+b1x[n−1]+b2x[n−2]+···+bM x[n−M] = bkx[n−k] k=0

M is called the order of the FIR filter. Note that output depends on the M + 1 most recent input samples FIR filters are sometimes called ”moving window summation filters”

EECS 452 – Fall 2014 Lecture 2 – Page 17/45 Thurs – 9/4/2014 Impulse response of FIR filter

M X y[n] = bkx[n − k] (1) k=0

Recall: impulse response h[n] is filter output when input x[n] = δ[n]

( 1, n = 0 δ[n] = 0, n 6= 0

From (1) we obtain ( b , n = 0,...,M h[n] = n 0, n < 0, n > M

as the impulse response of the FIR filter.

EECS 452 – Fall 2014 Lecture 2 – Page 18/45 Thurs – 9/4/2014

FIR (Direct Form) block diagram 0

Time domain input-output relation: - 1

y[n] = b0x[n] + b1x[n − 1] + ··· + bM x[n − M]

in z-domain - 1 −1 −M

Y (z) = (b0 + b1z + ··· + bM z )X(z) 2 Transfer function (z-domain)

Y (z) H(z) = = b + b z−1 + b z−2 + ··· + b z−M

X(z) 0 1 2 M

¡

−1

Polynomial over z ∈ C: has M zeros - 1 z−1 corresponds to the ”unit delay operator”, X(z)z−1 is the z-transform of x[n − 1].

EECS 452 – Fall 2014 Lecture 2 – Page 19/45 Thurs – 9/4/2014 FIR frequency transfer function

Z-domain transfer function of M-th order FIR filter with M coefficients {bn}n=0

M M X X Y (z) H (z) = h[n]z−n = b z−n = z n X(z) n=0 n=0 To get (digital) frequency domain transfer function you evaluate j2πf Hz(z) on the unit circle z = e , f ∈ [−1/2, 1/2]

M j2πf  X −j2πfn H(f) = Hz e = h[n]e n=0 or, less compactly,

H(f) = h[0] + h[1]e−j2πf + ··· + h[M]e−j2πfM .

EECS 452 – Fall 2014 Lecture 2 – Page 20/45 Thurs – 9/4/2014 IIR (Infinite Impulse Response) Filter

b0 By contrast, in an infinite impulse response x t y (IIR) filter, output depends on not only cur- vn,1 vd,1 rent and previous M input samples, but also z-1 z-1 the previous N filter outputs. wn,1 -a wd,1 b1 1

vn,2 vd,2 y[n] = b0x[n] + b1x[n − 1] + ... z-1 z-1 + b x[n − M] M wn,2 -a wd,2 b2 2 − a1y[n − 1] − · · · − aN y[n − N]

Transfer function bM-1 -aN-1

Y (z) vn,M vd,N H(z) = X(z) z-1 z-1 wn,M wd,N b + b z−1 + ... + b z−M bM -aN = 0 1 M −1 −N 1 + a1z + ... + aN z A ratio of polynomials: has N poles and M zeros as function of z−1 ∈ C.

EECS 452 – Fall 2014 Lecture 2 – Page 21/45 Thurs – 9/4/2014 Different types of filter transfer functions

öeEÑFö äçïé~ëë öeEÑFö ÜáÖÜé~ëë

M Ñ M Ñ

Ä~åÇ=êÉàÉÅí öeEÑFö öeEÑFö Ä~åÇé~ëë EåçíÅÜF

M Ñ M Ñ

EECS 452 – Fall 2014 Lecture 2 – Page 22/45 Thurs – 9/4/2014 Lowpass filter design template

íê~åëáíáçå Ä~åÇ âÉÉé=çìí NH œ é NH œé ^éZOMäçÖ NM Ç_ ¢N=J œ £ N é~ëëÄ~åÇ ^é é

NJ œé ^ëZ OMäçÖ NM EœëF Ç_

Fö âÉÉé=çìí Ñ E e ö ^ âÉÉé=çìí ë

œë ëíçéÄ~åÇ

M Ñé~ëë Ñëíçé ÑëLO ÑêÉèìÉåÅó

EECS 452 – Fall 2014 Lecture 2 – Page 23/45 Thurs – 9/4/2014 Equiripple LPF FIR filter design example

I Low pass filter.

I Fs=48000 Hz.

I Bandpass ripple: ±0.1 dB.

I Transition region 3000 Hz to 4000 Hz.

I Minimum stop band attenuation: 80 dB.

EECS 452 – Fall 2014 Lecture 2 – Page 24/45 Thurs – 9/4/2014 Matlab’s fdatool’s solution

EECS 452 – Fall 2014 Lecture 2 – Page 25/45 Thurs – 9/4/2014 fdatool’s magnitude, phase and group delay

EECS 452 – Fall 2014 Lecture 2 – Page 26/45 Thurs – 9/4/2014 What is group delay? A digital filter transfer function has a magnitude and a phase

H(f) = |H(f)| ejθ(f) .

The filter’s group delay at frequency f is defined as

1 dθ(f) τ(f) = − 2π df

Linear phase filters: θ(f) = −2πfτ, where τ is independent of frequency

I have group delay is the same at all frequencies

I shift each frequency component of input by same amount of delay

I have group delay proportional to the negative slope of the phase θ(f) The group delay of a digital filter is often expressed in seconds

 1 dθ(f)  τ = − T 2π df s

(Recall: f = F/Fs = FTs).

EECS 452 – Fall 2014 Lecture 2 – Page 27/45 Thurs – 9/4/2014 Why is group delay important?

Constant group delay is important in digital communications.

A system not having constant group delay distorts digital pulse waveforms. This smears them together and makes it difficult to make bit decisions.

Many communication systems have a special circuit that can adaptively equalize channel phase response to obtain a constant group delay. To do so it must measure it. This leads to the use of a training waveform.

FIR filters can be designed to give yield constant group delay as measured from input x(t) to output y(t) of the DSP+CODEC system.

EECS 452 – Fall 2014 Lecture 2 – Page 28/45 Thurs – 9/4/2014 C55xx implementation using TI’s DSP Library dsplib: TI’s implementations of DSP functions for the C55xx ”These routines are typically used in computationally intensive real-time applications where optimal execution speed is critical. By using these routines you can achieve execution speeds considerable faster than equivalent code written in standard ANSI C language.”

Functional categories of dsplib routines Fast-Fourier Transforms (FFT) Filtering and convolution Adaptive filtering Correlation Math Trigonometric Miscellaneous Matrix

(TMS320C55xx DSP Library Programmers Reference (spru422))

EECS 452 – Fall 2014 Lecture 2 – Page 29/45 Thurs – 9/4/2014 TI’s DSPlib FIR

ILU ),5)LOWHU

)XQFWLRQ XVKRUW RIODJ  ILU '$7$ [ '$7$ K '$7$ U '$7$ GEXIIHU XVKRUW Q[ XVKRUWQK

$UJXPHQWV [>Q[@ 3RLQWHUWRLQSXWYHFWRURIQ[UHDOHOHPHQWV K>QK@ - 3RLQWHUWRFRHIILFLHQWYHFWRURIVL]HQKLQQRUPDORUGHU )RUH[DPSOHLIQK WKHQK>QK@ ^KKKKK K`ZKHUHKUHVLGHVDWWKHORZHVWPHPRU\DGGUHVVLQ WKHDUUD\

U>Q[@ 3RLQWHUWRRXWSXWYHFWRURIQ[UHDOHOHPHQWV,QSODFH FRPSXWDWLRQ U [ LVDOORZHG

GEXIIHU>QK@ 3RLQWHUWRGHOD\EXIIHURIOHQJWKQK QK - ,QWKHFDVHRIPXOWLSOHEXIIHULQJVFKHPHVWKLVDUUD\ VKRXOGEHLQLWLDOL]HGWRIRUWKHILUVWILOWHUEORFNRQO\%H WZHHQFRQVHFXWLYHEORFNVWKHGHOD\EXIIHUSUHVHUYHV WKHSUHYLRXVHOHPHQWVQHHGHG - 7KHILUVWHOHPHQWLQWKLVDUUD\LVVSHFLDOLQWKDWLWFRQ WDLQVWKHDUUD\LQGH[ïRIWKHROGHVWLQSXWHQWU\LQWKH GHOD\ EXIIHU 7KLV LV QHHGHG IRU PXOWLSOHEXIIHULQJ VFKHPHVDQGVKRXOGEHLQLWLDOL]HGWR OLNHDOOWKHRWK HUDUUD\HQWULHV IRUWKHILUVWEORFNRQO\ Q[ 1XPEHURILQSXWVDPSOHV QK 7KHQXPEHURIFRHIILFLHQWVRIWKHILOWHU)RUH[DPSOHLI WKHILOWHUFRHIILFLHQWVDUH^KKKKKK`WKHQQK 0XVWEHDPLQLPXPYDOXHRI)RUVPDOOHUILOWHUV ]HURSDGWKHFRHIILFLHQWVWRPHHWWKHPLQLPXPYDOXH

RIODJ 2YHUIORZHUURUIODJ UHWXUQHGYDOXH - ,IRIODJ DELWGDWDRYHUIORZRFFXUUHGLQDQLQWHU PHGLDWHRUILQDOUHVXOW - ,IRIODJ DELWRYHUIORZKDVQRWRFFXUUHG

EECS 452 – Fall 2014 Lecture 2 – Page 30/45 Thurs – 9/4/2014 TI’s DSPlib conventions

$UJXPHQW 'HVFULSWLRQ [\ DUJXPHQWUHIOHFWLQJLQSXWGDWDYHFWRU

U DUJXPHQWUHIOHFWLQJRXWSXWGDWDYHFWRU

Q[Q\QU DUJXPHQWVUHIOHFWLQJWKHVL]HRIYHFWRUV[\DQGUUHVSHFWLYHO\,Q IXQFWLRQVZKHUHQ[ QU QURQO\Q[KDVEHHQXVHG

K $UJXPHQWUHIOHFWLQJILOWHUFRHIILFLHQWYHFWRU ILOWHUURXWLQHVRQO\

QK $UJXPHQWUHIOHFWLQJWKHVL]HRIYHFWRUK

'$7$ GDWDW\SHGHILQLWLRQHTXDWLQJDVKRUWDELWYDOXHUHSUHVHQWLQJD 4QXPEHU8VDJHRI'$7$LQVWHDGRIVKRUWLVUHFRPPHQGHGWR LQFUHDVHIXWXUHSRUWDELOLW\DFURVVGHYLFHV

/'$7$ GDWDW\SHGHILQLWLRQHTXDWLQJDORQJDELWYDOXHUHSUHVHQWLQJD 4QXPEHU8VDJHRI/'$7$LQVWHDGRIORQJLVUHFRPPHQGHGWR LQFUHDVHIXWXUHSRUWDELOLW\DFURVVGHYLFHV

XVKRUW 8QVLJQHGVKRUW ELW 

EECS 452 – Fall 2014 Lecture 2 – Page 31/45 Thurs – 9/4/2014 dbuffer is a circular buffer

http://www.ti.com/lit/an/spra645a/spra645a.pdf

Conventional buffer (shift old samples) Circular buffer (shift pointer)

Circular buffer is more power and computation efficient for FIR filtering

M X y[n] = bnx[n − k] k=0

EECS 452 – Fall 2014 Lecture 2 – Page 32/45 Thurs – 9/4/2014 TI’s FIR notes

,PSOHPHQWDWLRQ1RWHV 7KHILUVWHOHPHQWLQWKHGEXIIHUDUUD\ LQGH[  LVWKHHQWU\LQGH[IRUWKHLQSXW KLVWRU\,WLVWUHDWHGDVDQXQVLJQHGELWYDOXHE\WKHIXQFWLRQHYHQWKRXJK LWKDVEHHQGHFODUHGDVVLJQHGLQ&7KHYDOXHRIWKHHQWU\LQGH[LVHTXDOWR WKHLQGH[ïRIWKHROGHVWLQSXWHQWU\LQWKHDUUD\7KHUHPDLQLQJHOHPHQWV PDNHXSWKHLQSXWKLVWRU\)LJXUHïVKRZVWKHDUUD\LQPHPRU\ZLWKDQ HQWU\LQGH[RI7KHQHZHVWHQWU\LQWKHGEXIIHULVGHQRWHGE\[ Mï ZKLFK LQWKLVFDVHZRXOGRFFXS\LQGH[ LQWKHDUUD\7KHQH[WQHZHVWHQWU\LV [ Mï DQGVRRQ,WLVDVVXPHGWKDWDOO[ HQWULHVZHUHSODFHGLQWRWKHDUUD\ E\WKHSUHYLRXVLQYRFDWLRQRIWKHIXQFWLRQLQDPXOWLSOHEXIIHULQJVFKHPH

7KHGEXIIHUDUUD\DFWXDOO\FRQWDLQVRQHPRUHKLVWRU\YDOXHWKDQLVQHHGHGWR LPSOHPHQWWKLVILOWHU7KHYDOXH[ MïQK GRHVQRWHQWHULQWRWKHFDOFXODWLRQVIRU IRUWKHRXWSXWU M +RZHYHUWKLVYDOXHLVUHTXLUHGLQRWKHU'63/,%ILOWHUIXQF WLRQVWKDWXWLOL]HWKHGXDO0$&XQLWVRQWKH&[VXFKDV),5,QFOXGLQJWKLV H[WUD ORFDWLRQ HQVXUHV FRPSDWLELOLW\ DFURVV DOO ILOWHU IXQFWLRQV LQ WKH &[ '63/,%

)LJXUHï)LJXUHïDQG)LJXUHïVKRZWKHGEXIIHU[DQGUDUUD\V DVWKH\DSSHDULQPHPRU\

)LJXUHï GEXIIHU$UUD\LQ0HPRU\DW7LPHM

HQWU\LQGH[  ORZHVWPHPRU\DGGUHVV [ MïQKï [ MïQKï [ MïQKï ROGHVW[  HQWU\ [ MïQK QHZHVW[  HQWU\ [ Mï [ Mï [ Mï • • •

[ MïQKï [ MïQKï [ MïQKï KLJKHVWPHPRU\DGGUHVV

EECS 452 – Fall 2014 Lecture 2 – Page 33/45 Thurs – 9/4/2014 TI’s FIR notes (cont.)

)LJXUHï [$UUD\LQ0HPRU\

ROGHVW[  HQWU\ [  ORZHVWPHPRU\DGGUHVV [  • • •

[ Q[ï QHZHVW[  HQWU\ [ Q[ï KLJKHVWPHPRU\DGGUHVV

)LJXUHï U$UUD\LQ0HPRU\

ROGHVW[  HQWU\ U  ORZHVWPHPRU\DGGUHVV U  • • • U Q[ï QHZHVW[  HQWU\ U Q[ï KLJKHVWPHPRU\DGGUHVV

([DPSOH 6HHH[DPSOHVILUVXEGLUHFWRU\ %HQFKPDUNV SUHOLPLQDU\ &\FOHV‚ &RUH Q[  QK 2YHUKHDG  &RGHVL]H  LQE\WHV

EECS 452 – Fall 2014 Lecture 2 – Page 34/45 Thurs – 9/4/2014 C5515 eZDSP

EECS 452 – Fall 2014 Lecture 2 – Page 35/45 Thurs – 9/4/2014 C5515 eZDSP Description

The C5515 is a member of TI’s TMS320C5000 fixed-point Digital Signal Processor (DSP) product family and is designed for low-power applications. It is based on the TMS320C55x DSP generation CPU processor core.

TI’s list of C5515 DSP applications include: Wireless Audio Devices Echo Cancellation Headphones Portable Medical Devices Voice Applications Industrial Controls Fingerprint Biometrics Software Defined Radio http://processors.wiki.ti.com/index.php/C5515 In this lecture we focus on the CODEC.

EECS 452 – Fall 2014 Lecture 2 – Page 36/45 Thurs – 9/4/2014 Direct Digital Synthesis (DDS) basic idea

A method for digitally creating sine waves of arbitrary frequency by reading samples out of memory.

I We store a sine table in ROM (read-only memory).

I These values are samples from a single period.

I The number of values we can store/access is determined by the size of the address we use. B I Say we use a B-bit address, so we can store 2 values.

I The number of values determines the resolution of the table.

I These values are frequency-less.

I Now let’s read out these values at a certain speed.

I Say x values per second.

I The output (after D/A processing) now form a waveform of frequency ???

I DDS idea: as long as we can arbitrarily control the speed at which we read/drive out these values, we can generate waveforms of arbitrary frequency.

EECS 452 – Fall 2014 Lecture 2 – Page 37/45 Thurs – 9/4/2014 DDS: read out samples using a counter

Let’s use a binary counter, say BA bits.

I Driven by a fs Hz clock: counter increments once per tick.

I Use the counter value to address the sine table, also BA bits.

I So what is the output frequency?

~å~äçÖ çìíéìí _^ _a

Ñë olj ÅçìåíÉê ï~îÉÑçêã aL^ í~ÄäÉ

I When the counter wraps around, we start reading from the beginning of the sine table, i.e., the next period.

I The time it takes to finish one period is simply the time it takes to BA count to maximum: 2 /fs seconds.

BA I Output frequency: fs/2 .

EECS 452 – Fall 2014 Lecture 2 – Page 38/45 Thurs – 9/4/2014 DDS: increasing the sinusoidal frequency

What if we want to increase the sinusoidal frequency without increasing fs?

I We can try to make the counter increment by n at a time, instead of 1. (We will see this can be done in a minute.) B This way it wraps around in 2 A seconds, an n-fold increase in I n·fs output frequency!

I However, if we are using a BA-bit sine table then we are skipping a lot of samples!

I We only address 1 in every n samples of the sine table: lower resolution and less D/A quality.

I But if this is what we do we can store fewer samples using a smaller table.

EECS 452 – Fall 2014 Lecture 2 – Page 39/45 Thurs – 9/4/2014 DDS: decreasing the sinusoidal frequency

What if we want to increase the sinusoidal period without decreasing fs? Q. Can you make the counter count slower without changing fs? A. Yes

I Keep the sine table BA-bit.

I Increase the counter to BFTV > BA bit.

I With the same clock, the counter now counts slower: it takes BFTV 2 /fs seconds to wrap around.

I Use the highest BA bits of the counter value to address the sine table. B −B I So it takes 2 FTV A ticks to move to the next sample, if the counter increments by 1 per tick.

I Example: BFTV = 8, BA = 4. We have 16 samples in the table. The counter counts to 255 before wrapping around. It takes 16 counter increments to increase the table address by 1.

BFTV BFTV −BA I The output frequency: fs/2 , a 2 -fold decrease!

EECS 452 – Fall 2014 Lecture 2 – Page 40/45 Thurs – 9/4/2014 The DDS design that achieves both

Replace the counter with an accumulator and adder. Now can use steps larger than 1 in the increment. Frequency tuning value (FTV) is the step size of increment. Use more bits in the accumulator than in the ROM address. This gives finer frequency resolution since output frequency can only be integer multiples of fs . 2BFTV

~å~äçÖ cqs çìíéìí _cqs _cqs _cqs _^ _a

Ñë ÑêÉèìÉåÅó ~ÇÇÉê éÜ~ëÉ ëáåÉ aL^ íìåáåÖ ~ÅÅìãä~íçê í~ÄäÉ î~äìÉ

Filter at D/A output not shown. fs What is the output frequency? fo = FTV . 2BFTV

EECS 452 – Fall 2014 Lecture 2 – Page 41/45 Thurs – 9/4/2014 Results illustrated

Difference under different FTV values.

14 With BFTV = 8,BA = BD = 4, and fs = 2 Hz. Assume output ranges from [−1, 1]V.

EECS 452 – Fall 2014 Lecture 2 – Page 42/45 Thurs – 9/4/2014 DDS discussion

Synthesized waveform is an approximation to an analog one. Need to balance step size, clock rate, ROM size and number of bits.

I Output frequency:

I It has nothing to do with BA, as long as BA ≤ BFTV .

I It is only determined by how fast we accumulate/count the integers, and how fast we wrap around.

I BA does determine the resolution of the table, and the quality of D/A output.

I Hypothetically, what if BA > BFTV ?

I Then we have not reached the end of the table (a single period) when counting wraps around.

I We will always be missing a segment of the period.

I Output waveform distorted, though frequency as desired.

I One solution is to use the higher BFTV bits of BA. The lowest frequency you can generate: fs . I 2BFTV

EECS 452 – Fall 2014 Lecture 2 – Page 43/45 Thurs – 9/4/2014 DDS example We can implement a direct digital sinewave synthesizer on the C5515 using the codec’s sample clock. A number of values are possible, let’s use fs = 48 kHz. An unsigned long (32 bits) can be used as the accumulator, ac0.A table of 256 samples of single period of a sinewave will be used in place of the ROM. The output frequency will be 48000 f = FTV Hz. o 232

For a desired fo the value of FTV can be found

232f FTV = o . 48000

For fo = 1000 Hz we have FTV= 89, 478, 485.333 ··· . If we round FTV to the closest integer, then the error in fo will be 1 48000 ≈ 3.7 × 10−6 Hz. 3 232 About 4 parts in 109. Good enough for most applications and probably much better than the crystal being used to generate the 48 kHz.

EECS 452 – Fall 2014 Lecture 2 – Page 44/45 Thurs – 9/4/2014 Summary of what we covered today

I Sampling and reconstruction

I Fourier spectrum of sampled cts time signals

I Relation between windowed FT, DTFT, DFT

I Anti-aliasing filter

I FIR and IIR digital filters

I z-transform, frequency response, transfer function

I matlab’s fdatool for filter design, phase shift and group delay

I TI’s DSPlib FIR filter implementation

I Direct Digital Synthesis (DDS)

I Next: Finite precision arithmetic

EECS 452 – Fall 2014 Lecture 2 – Page 45/45 Thurs – 9/4/2014