SDA09 Handout6 Full

download SDA09 Handout6 Full

of 13

Transcript of SDA09 Handout6 Full

  • 8/4/2019 SDA09 Handout6 Full

    1/13

    DFT IDFT

    IB Paper 6: Signal and Data Analysis

    Handout 6: The Discrete Fourier Transform

    J Lasenby

    Signal Processing Group,Engineering Department,

    Cambridge, UK

    Lent 2009

    1 / 2 5

    DFT IDFT

    Digital Sampling and the DTFT (revisited)

    1.5

    1

    0.5

    0

    0.5

    1

    1.5

    T 2T 3T 4T 5T 6T 7T 8T 9T

    f(t)f(T) f(2T)

    f(3T)

    f(4T)

    Figure 1: Digital sampling of a continuous waveform

    2 / 2 5

  • 8/4/2019 SDA09 Handout6 Full

    2/13

    DFT IDFT

    Given the sampled values of some signal f(t), i.e.

    {f(), ...f(T), f(0), f(+T), f(2T), ..., f(+)}

    the discrete time Fourier transform (DTFT) shows how todetermine the frequency content:

    Fs() =

    n=

    f(nT)ejnT (1)

    As in slide 14, handout 5. (See below for examples of DTFT of acosine wave and DTFT of a double exponential).

    3 / 2 5

    DFT IDFT

    f(t)=cos(ct)

    FT

    DTFT

    DISCRETETIMESAMPLING

    f(nT)=cos(cnT)

    t

    t

    F()

    Fs()

    Fs()=1/T

    m

    F(m0)

    =+c=

    c

    0 2

    0

    02

    0 0

    Figure 2: FT and DTFT of a cosine wave with frequency c

    4 / 2 5

  • 8/4/2019 SDA09 Handout6 Full

    3/13

    DFT IDFT

    f(t)=exp(|t|) FT

    DTFT

    DISCRETETIMESAMPLING

    f(nT)=exp(|nT|)

    t

    n

    F()

    Fs()

    Fs()=1/T

    m

    F(m0)

    0 2

    0

    02

    0 0

    Figure 3: FT and DTFT of a double exponential

    5 / 2 5

    DFT IDFT

    This is fine in theory, but in practice there are two reasons why youcant compute the DTFT of a signal:

    We dont have access to all of the data points from to

    + (even if we did, the computing time would be infinite).

    Fs() is defined over the continuous range of frequenciesfrom to +. Hence it is impossible to calculate andstore Fs() for all frequency values.

    The discrete Fourier transform (DFT) is a way to bypass these

    practical difficulties:

    6 / 2 5

  • 8/4/2019 SDA09 Handout6 Full

    4/13

    DFT IDFT

    A finite set ofN samples:

    Suppose we have a finite number (N) of (evenly spaced) datapoints, say

    t = 0, T, 2T, 3T, ..., (N 1)T

    which we wish to transform to frequency space.We can write this set of samples of our original continuous signal as

    fs(t) =N1

    n=0

    f(t)(t nT) N1

    n=0

    f(nT)(t nT)

    so that fs(t) takes the function values at the N time steps 0 to(N 1)T and zero elsewhere. Now suppose we try to Fouriertransform this function i.e establish the DTFT.

    7 / 2 5

    DFT IDFT

    Fs() =

    N1

    n=0

    f(t)(t nT)

    ejtdt

    =N1

    n=0

    f(t)ejt(t nT)dt

    giving

    Fs() =N1

    n=0

    f(nT)ejnT

    which is simply the DTFT with the infinite limits replaced by finite

    ones.Provided we have enough of the original continuous signal withinthe time window 0, ...,N 1, the truncated DTFT will be similarto the full DTFT.

    8 / 2 5

  • 8/4/2019 SDA09 Handout6 Full

    5/13

    DFT IDFT

    However, what we would really like is an entirely discreteformulation i.e. given a finite set of sampled values we obtain anapproximation to its FT in the form of a finite set of frequencyvalues. The sensible way of achieving this would be to periodicallyextend our finite set of samples. We know that the FT of a

    periodic function takes discrete values

    F() =

    n=

    cnejn0t

    ejtdt =

    n=

    cn

    ej(n0)tdt

    = 2

    n=

    cn( n0)

    and that the FT of a sampled signal is repeated every interval ofthe sampling frequency. We therefore know that the FT of theperiodic extension of fs(t) will also be a periodic function definedat discrete frequency values.

    9 / 2 5

    DFT IDFT

    If we do repeat our set of samples at intervals along the time axisso that we have a periodic function, we can see from figure 4 thatthe period of this periodic function is T NT. Let us call thisperiodic function fs(t).

    Figure 4: Periodic repetition of the finite set of samples fs(t)

    Being periodic, fs(t) can be expanded as a Fourier series

    fs(t) =

    k=

    ckejk0t

    where

    ck =1

    T

    T0

    fs(t)ejk0tdt for 0 =

    2

    T

    2

    NT

    10/25

  • 8/4/2019 SDA09 Handout6 Full

    6/13

    DFT IDFT

    We can explicitly evaluate the ck as follows

    ck =1

    T

    T0

    fs(t)ejk0tdt

    =

    1

    TT

    0

    N1

    n=0 f(t)(t nT)ejk0t

    dt

    =1

    T

    N1

    n=0

    T0

    f(t)ejk0t(t nT)dt

    =1

    T

    N1

    n=0

    f(nT)ejk0nT =1

    T

    N1

    n=0

    f(nT)ej2knN (2)

    Comparing this with our equation on slide 8,

    Fs() = N1n=0 f(nT)e

    jnT we see that we can write:

    Tck = Fs(k0)

    11/25

    DFT IDFT

    But we saw in Handout 3 that D(n0) = Tcn was the function wechose for our Fourier Transform. Introducing standard notation, weabbreviate Fs(k0) as Fk and f(nT) as fn, so that we can writethe discrete values of the spectrum as

    Fk =N1

    n=0

    fnej2k n

    N (3)

    We know that the FT of a sampled signal repeats itself every

    interval of the sampling frequency therefore, the frequency valuesof interest to us in equation (3) will range over 0 to0 = 2/T 2N/NT = N0.

    12/25

  • 8/4/2019 SDA09 Handout6 Full

    7/13

    DFT IDFT

    Since Fs(0)[= Fs(N0)] will have the same value as Fs(0), i.e.

    Fs(N0) =

    N1

    n=0f(nT)ej2n

    N

    N =

    N1

    n=0f(nT) = Fs(0)

    we will only need to know values for k in the range from 0 to

    (N 1). Equation (3) is the DISCRETE FOURIERTRANSFORM or DFT of our original finite set of samples fs(t).

    We note that it is really the FT of the periodic extension of thefinite set, giving a FT which is itself discrete and periodic.

    13/25

    DFT IDFT

    =0 =(N1)0/N

    0 2

    0

    F0=F

    s(0)

    F1=F

    s(

    0/N)

    F2=F

    s(2

    0/N)

    Fs()

    Figure 5: Sampling in frequency

    14/25

  • 8/4/2019 SDA09 Handout6 Full

    8/13

    DFT IDFT

    Comments:

    This is now a quantity which any computer can in principle

    evaluate for any observed signal.

    Note that we can interpret component Fk as the frequencycontent of the signal at frequency k0/N or k0 .

    The DFT is periodic, i.e. Fk+N = Fk

    For real signals Fk = Fk (Easy to see this from equation).

    15/25

    DFT IDFT

    Inverse Discrete Fourier Transform

    The grid ofN frequency values chosen for the DFT is convenientin that the transform can be inverted from the N values ofFk.To derive the inverse DFT, first multiply the forward DFT by

    ej2km/N and then sum over m = 0 to N 1:

    N1

    m=0

    Fmej2km/N =

    N1

    m=0

    N1

    n=0

    fnej2m kn

    N (4)

    =N1

    n=0

    fn

    N1

    m=0

    ej2mknN (5)

    16/25

  • 8/4/2019 SDA09 Handout6 Full

    9/13

    DFT IDFT

    The inner summation over m is a Geometric Progression (GP),

    with factor = ej2knN .

    Hence we have:

    N1

    m=0

    ej2mknN =

    1 ej2(kn)

    1 ej2knN

    =

    0 ifk= n

    N ifk = n

    The second case above for k = n follows immediately because

    N1m=0 e

    j0 = N.Equation (5) now becomes

    N1

    m=0

    Fmej2km/N = Nfk (6)

    17/25

    DFT IDFT

    We therefore have an expression for the Inverse Discrete FourierTransform (IDFT):

    fk =1

    N

    N1

    n=0

    Fnej2kn/N (7)

    To summarise: the expressions for the DFT and the IDFT of asampled signal fn are:

    Fk =N1

    n=0

    fnej2nk

    N , 0 k N 1 (8)

    fn = 1N

    N1

    k=0

    Fkej2nkN , 0 n N 1 (9)

    18/25

  • 8/4/2019 SDA09 Handout6 Full

    10/13

    DFT IDFT

    Other considerations

    Fast algorithms - particularly elegant and fast methods exist

    for computing the DFT, known generically as the Fast FourierTransform, or FFT algorithms. The most well-known FFTalgorithms are only used when N is a power of 2. However,other classes exist, such as for N a power of 4.

    In our DFT derivation we periodically repeated the data in thetime domain and then took the FT of this sampled, periodic

    signal to produce another discrete, periodic signal.

    19/25

    DFT IDFT

    The effects of truncating a data sequence (ie taking a finiteset of samples) and performing this periodic repetition mightbe to introduce some discontinuities. This will lead to highfrequency components in the Fourier transform.

    One way of avoiding this is to apply a window to our datasequence. A variety of window shapes can be used whichbetter preserve the spectral information of the original(untruncated) signal and this is a large area of study known aswindowing or tapering.

    Because we know that multiplication in the time domain isequivalent to convolution in the frequency domain, we can

    quantify exactly what the effect on the spectrum is ofapplying this window function.

    20/25

  • 8/4/2019 SDA09 Handout6 Full

    11/13

    DFT IDFT

    Example:

    Let us now give an example of calculating a DFT. Consider thefour sample values

    {fn} = {1,2,1,0}

    Figure 6: Sampling in frequency

    21/25

    DFT IDFT

    We now want to calculate Fk for k = 0,1,2,3.

    F0 = {foej2(00)/4 + f1e

    j2(10)/4 + f2ej2(20)/4

    + f3ej2(30)/4} = {1 + 2 + 1 + 0} = 4

    F1 = {foej2(01)/4

    + f1ej2(11)/4

    + f2ej2(21)/4

    + f3ej2(31)/4} = {1 + 2ej/2 + 1ej+ 0} = 2j

    F2 = {foej2(02)/4 + f1e

    j2(12)/4 + f2ej2(22)/4

    + f3ej2(32)/4} = {1 + 2ej+ 1ej2+ 0}= 2 2 = 0

    F3 = {foej2(03)/4 + f1e

    j2(13)/4 + f2ej2(23)/4

    + f3ej2(33)/4} = {1 + 2ej3/2 + 1ej3+ 0}= 2j

    22/25

  • 8/4/2019 SDA09 Handout6 Full

    12/13

    DFT IDFT

    Therefore, the DFT is given by

    {Fk} = {4,2j, 0 , 2j}

    Check that Fk = FNk.

    23/25

    DFT IDFT

    The SpectrogramNow that we have the concept of a Fourier Transform of a finiteset of samples, we can understand the concept of the spectrogram.Figure 7 shows how we can form the DFT of a small section ofsignal at a given time and display the resulting frequency contentas a function of time.

    Figure 7: Spectrogram of section of flute music

    24/25

  • 8/4/2019 SDA09 Handout6 Full

    13/13

    DFT IDFT

    A continuously decreasing tone?

    Figure 8: Spectrogram of Shepard Tone

    A Shepard tone, named after Roger Shepard, is a sound consistingof a superposition of sine waves separated by octaves. This createsthe auditory illusion of a tone that continually ascends or descendsin pitch, yet which ultimately seems to get no higher or lower.

    J. Lasenby (2009) 25/25