Fourier series of periodic discrete-time signals ALGORITHM FOR SOLUTION: Fast Fourier Transform...

42
Fourier series of periodic discrete-time signals 1

Transcript of Fourier series of periodic discrete-time signals ALGORITHM FOR SOLUTION: Fast Fourier Transform...

Fourier series of periodic discrete-time signals

1

Discrete-time signal x(n):

Defined for integer time instants n:

{x(n)} = {. . . , x(−2), x(−1), x(0), x(1), x(2), . . .}

2

In analogy with continuous-time signals, discrete-

time signals can be expanded in terms of sinusoidal

components of form Ak cos(ωkn+ ϕk)

−2 0 2 4 6 8 10 12

−1

0

1

cos(2πfn+ ϕ), f = 0.1(Hz), ϕ = −2πf · 2(rad)

3

Consider a periodic discrete-time signal with period

N :

x(n) = x(n+N), all n

4

In analogy with continuous-time case the discrete

sinusoidal signals

cos(2πk

Nn), sin(

2πk

Nn), k = 0, 1, 2, . . .

have period N .

It follows that an N -periodic signal {x(n)} can be

expanded in terms of sinusoidal signals

cos(2πk

Nn), sin(

2πk

Nn), k = 0, 1, 2, . . .

5

Important difference compared to continuous-time case:

We have

cos(nω) = cos(nω + 2πnl)

= cos (n(ω + 2πl)), all integers l

=⇒Frequencies ω and ω + 2πl give the same discrete-

time sequence

NOTE: works only because time n is an integer!

6

Hence we need only include frequency components

cos(2π1

Nn), cos(2π

2

Nn), . . . , cos(2π

N − 1

Nn)

sin(2π1

Nn), sin(2π

2

Nn), . . . , sin(2π

N − 1

Nn)

and we obtain the Fourier series

x(n) = a0 +

N−1∑k=1

ak cos(k2π

Nn) +

N−1∑k=1

bk sin(k2π

Nn)

7

As before, we can express each frequency component

in terms of complex exponentials:

x(n) =N−1∑

k=−N+1

ckej2πkn/N

As time n is an integer we can eliminate the negative

exponentials:

ej2π(−m)n/N = ej2π(−m)n/N+j2πn = ej2π(N−m)n/N

=⇒

Terms with k = −m < 0 can be replaced by a term

with k = N −m > 0

8

NOTE:

As c−k = c∗k, we have

c−kej2π(−k)n/N = c∗ke

j2π(N−k)n/N

Fourier series of discrete-time periodic signal

An N -periodic discrete-time signal can be expanded

as

x(n) =

N−1∑k=0

dkej2πkn/N

where dN−k = d∗k

9

Here the complex-valued frequency components are

given by

dk =1

N

N−1∑n=0

x(n)e−j2πkn/N

Proof:

Multiply expression for x(n) with e−j2πmn/N and sum

over time n over one period:

1

N

N−1∑n=0

[e−j2πmn/N ×

(x(n) =

N−1∑k=0

dkej2πkn/N

)]10

Here the right-hand side becomes

1

N

N−1∑k=0

dk

N−1∑n=0

ej2π(k−m)n/N

which vanishes if m ̸= k, because

N−1∑n=0

ej2π(k−m)n/N =

{N, if k −m = 0,±N,±2N, . . .

0, otherwise

Hence

1

N

N−1∑k=0

dk

N−1∑n=0

ej2π(k−m)n/N = dm

11

and1

N

N−1∑n=0

x(n)e−j2πmn/N = dm

giving the result

12

EXAMPLE: Periodic discrete-time square wave with period

N = 4:

x(0) = 1

x(1) = 1

x(2) = 0

x(3) = 1-5 -4 -3 -2 -1 0 1 2 3 4 5

· · · · · ·

x(n)

n

and x(n) = x(n− 4), all n

Frequency components: 0, 2π4 ,2π·24 , 2π·34

(Next frequency 2π·44 = 2π is equivalent to frequency

component 0)

13

Fourier series:

dk =1

4

3∑n=0

x(n)e−j2πkn/4

=1

4

[1 · e−j2πk·0/4 + 1 · e−j2πk·1/4 + 0 + 1 · e−j2πk·3/4

]=

1

4

[1 + e−jπk/2 + e−jπk·3/2

]=

1

4[1 + 2 cos (πk/2)]

=⇒d0 =

3

4, d1 =

1

4, d2 = −1

4, d3 =

1

4

0 2ππ/2π

3π/2

dk

14

Hence

x(n) =3∑

k=0

dkej2πkn/4

=3

4+

1

4ej2π1·n/4 − 1

4ej2π2·n/4 +

1

4ej2π3·n/4

=3

4+

1

4[cos (πn/2) + j sin (πn/2)]

−1

4[cos (πn) + j sin (πn)] +

1

4[cos (3πn/2) + j sin (3πn/2)]

Note that as x(n) is real the imaginary components should

vanish

15

Here we have:

- sin(πn) = 0

- cos(πn) = (−1)n

In addition, frequency components 3π/2 and π/2 are related,

because

- sin(3πn/2)=sin(3πn/2−2πn)=sin(−πn/2)=− sin(πn/2),

and

- cos(3πn/2)=cos(3πn/2− 2πn)=cos(−πn/2)=cos(πn/2)

=⇒

x(n) =3

4+

1

2cos

(2π

4n

)− 1

4(−1)n

16

NOTE:

In above example the Fourier series coefficients dk were real.

Reason: Recall that

ak cos(2πkn/N)+bk sin(2πkn/N) = ckej2πkn/N+c∗ke

−j2πkn/N

where

ck =1

2(ak − jbk) , c

∗k =

1

2(ak + jbk)

As x(n) is even, x(−n) = x(n), the sine-terms vanish so that

bk = 0 and hence ck and dk are real.

17

Next example illustrates a signal which is not even.

Consider the periodic signal

x̃(0) = 1

x̃(1) = 1

x̃(2) = 1

x̃(3) = 0

and x̃(n) = x̃(n− 4), all n

We see that x̃(n) = x(n− 1), all n.

18

Hence

x̃(n) = x(n− 1)

=3∑

k=0

dkej2πk(n−1)/4

=3∑

k=0

dke−j2πk/4ej2πkn/4

=

3∑k=0

d̃kej2πkn/4

where

d̃k = dke−j2πk/4

19

or

d̃0 = d0ej·0 =

3

4

d̃1 = d1e−jπ/2 =

1

4· (−j)

d̃2 = d2e−jπ = −1

4· (−1)

d̃3 = d3e−j3π/2 =

1

4· j

20

Fourier series of non-periodic discrete-timesignals

In analogy with the continuous-time case a non-periodic

discrete-time signal consists of a continuum of frequencies

(rather than a discrete set of frequencies)

But recall that

cos(nω) = cos(nω + 2πnl)

= cos (n(ω + 2πl)), all integers l

=⇒Only frequencies up to 2π make sense

21

Hence a discrete-time signal {x(n)} can be expanded as

x(n) =1

∫ 2π

0

X(ω)ejωndω

where it can be shown that the Fourier transform X(ω) is given

by

X(ω) =

∞∑n=−∞

x(n)e−jωn

22

THE DISCRETE FOURIER TRANSFORM (DFT)

Next let’s introduce the standard definition of the discrete

Fourier transform of a sequence

{x(0), x(1), . . . , x(N − 1)}

of finite length N .

We do not make any assumptions about the signal (periodicity

etc) outside the range 0 ≤ n ≤ N − 1.

23

Facts:

- from N signal values x(0), x(1), . . . , x(N − 1) at most N

independent frequency components can be computed

- frequency components ≥ 2π are redundant (identical with

frequencies < 2π

- lower bound on frequency resolution is 2π/N (= frequency

corresponding to period length equal to sequence length N)

Hence it makes sense to determine the frequency components

at the N equidistant frequencies

0,1

N2π,

2

N2π, . . . ,

N − 1

N2π

i.e., the same frequencies contained in an N -periodic signal

24

DISCRETE FOURIER TRANSFORM (DFT):

The DFT {X(k)}N−1k=0 of a sequence {x(k)}N−1

k=0 is

defined as

X(k) =

N−1∑n=0

x(n)e−j2π kNn, k = 0, 1, . . . , N−1 (DFT)

and the inverse DFT (IDFT) is given by

x(n) =1

N

N−1∑k=0

X(k)ej2πkNn, n = 0, 1, . . . , N − 1

Observe similarity with Fourier transform of periodic

signal

25

EXAMPLE

Show that the Discrete Fourier Transform of the

sequence

{x(n)} = {1, 0, 0, 1}

is given by

{X(k)} = {2, 1 + j, 0, 1− j}

26

PROPERTIES OF DFT

• Symmetry property.

For a real sequence {x(n)}, the DFT satisfies

X(N − k) = X(k)∗ (complex conjugate)

i.e.,

Re[X(N − k)] =Re[X(k)]

Im[X(N − k)] =−Im[X(k)], k = 1, . . . , N − 1

27

Follows from the fact that in the definition of X(N − k),

x(n)e−j2πN−kN n = x(n)ej2π

kNn−j2π

= x(n)ej2πkNn

=(x(n)e−j2π k

Nn)∗

• DC component.

For k = 0 we have

X(0)=

N−1∑n=0

x(n)e−j2π 0Nn

=x(0) + x(1) + · · ·+ x(N − 1)

Hence X(0) is real if x(n) are real and the

28

contribution of X(0) to x(n) is

1

NX(0)e0 =

1

NX(0)

i.e., a constant component (usually called the DC

component).

• Oscillating component.For even values of N , we have for k = N/2

X(N/2) =

N−1∑n=0

x(n)e−j2πN/2N n =

N−1∑n=0

x(n)e−jπn

= x(0)− x(1) + · · · − x(N − 1)

Hence X(N/2) is real if x(n) are real and the

29

contribution of X(N/2) to x(n) is

1

NX(N/2)ej2π

N/2N n =

1

NX(N/2) (−1)n

i.e., an oscillating component.

• Parseval’s relation.

The energy of the signal {x(n)} defined as

Px =

N−1∑n=0

x(n)2

can be computed in the frequency domain using

30

Parseval’s relation,

Px =N−1∑n=0

x(n)2 =1

N

N−1∑k=0

|X(k)|2

It follows that 1N |X(k)|2 can be interpreted as the

contribution to the total energy of the signal from

frequency component 2πk/N .

Note: important in signal compression!

• DFT of a δ function.

The δ function,

δ(n) =

{1, n = 0

0, n ̸= 0

31

has DFT X(k) = 1, k = 0, 1, . . . , N − 1.

Hence it consists of equal amounts of all

frequencies!

32

DIRECT COMPUTATION OF DFT SUM ISNOT ADVISABLE IN PRACTICE:

- HIGH COMPUTATIONAL BURDEN:

Computation of sequence X(k) requires N 2

complex additions and multiplications (a lot for

long sequences)

- Numerical round-off errors add up when evaluation

long sum

33

EFFICIENT ALGORITHM FOR SOLUTION:Fast Fourier Transform (FFT)

- FFT: N log2N complex additions and

(N/2) log2N complex multiplications (compare

N 2 using direct evaluation)

- Each element X(k) is obtained by only log2N

complex additions (compare with N using direct

evaluation) ⇒ significantly smaller round-off errors

MATLAB routines:

- X=fft(x) (Fourier transform)

- x=ifft(X) (inverse Fourier transform)

34

FFT uses the fact that the discrete Fourier transformX(k) of a sequence {x(0), x(1), . . . , x(N − 1)} withN even can be determined as

X(k) = X11(k) +W kNX12(k), k = 0, 1, . . . , N/2− 1

X(k +N/2) = X11(k)−W kNX12(k), k = 0, 1, . . . , N/2− 1

where WN = e−j2π/N ,

{X11(k)} is the Fourier transform of the ’even

subsequence’ {x(0), x(2), . . . , x(N − 2)}, andX12(k)} is the Fourier transform of the ’odd

subsequence’ {x(1), x(3), . . . , x(N − 1)}.

35

Example (N = 8):

X(k) =7∑

n=0

x(n)e−j2πkn/8

= x(0) + x(2)e−j2πk2/8

+ x(4)e−j2πk4/8

+ x(6)e−j2πk6/8

+x(1)e−j2πk/8

+ x(3)e−j2πk3/8

+ x(5)e−j2πk5/8

+ x(7)e−j2πk7/8

= x(0) + x(2)e−j2πk/4

+ x(4)e−j2πk2/4

+ x(6)e−j2πk3/4

+e−j2πk/8

(x(1) + x(3)e

−j2πk/4+ x(5)e

−j2πk2/4+ x(7)e

−j2πk3/4)

=

3∑n=0

x(2n)e−j2πkn/4

+ e−j2πk/8

3∑n=0

x(2n + 1)e−j2πkn/4

= X11(k) + Wk8 X12(k), k = 0, 1, 2, 3

where W8 = e−j2π/8, and

{X11(k)} = DFT ({x(0), x(2), x(4), x(6)})

{X12(k)} = DFT ({x(1), x(3), x(5), x(7)})

36

X11(k), X12(k) are defined for k = 0, 1, 2, 3. The latter half of X(k) is obtained from

X(k + 4) =

7∑n=0

x(n)e−j2π(k+4)n/8

= x(0) + x(2)e−j2π(k+4)2/8

+ x(4)e−j2π(k+4)4/8

+ x(6)e−j2π(k+4)6/8

+x(1)e−j2π(k+4)/8

+ x(3)e−j2π(k+4)3/8

+ x(5)e−j2π(k+4)5/8

+ x(7)e−j2π(k+4)7/8

= x(0) + x(2)e−j2π(k/4+1)

+ x(4)e−j2π(2k/4+2)

+ x(6)e−j2π(3k/4+3)

+e−j2π(k/8+1/2)

(x(1) + x(3)e

−j2π(k/4+1)+ x(5)e

−j2π(2k/4+2)+ x(7)e

−j2π(3k/4+3))

= x(0) + x(2)e−j2πk/4

+ x(4)e−j2π2k/4

+ x(6)e−j2π3k/4

+e−j2πk/8

e−jπ

(x(1) + x(3)e

−j2πk/4+ x(5)e

−j2π2k/4+ x(7)e

−j2π3k/4)

=

3∑n=0

x(2n)e−j2πkn/4 − e

−j2πk/83∑

n=0

x(2n + 1)e−j2πkn/4

= X11(k) − Wk8 X12(k), k = 0, 1, 2, 3

where we have used e−jπ = cos(−π) + j sin(−π) = −1.

37

The operation

X(k) = X11(k) + WkNX12(k), k = 0, 1, . . . , N/2 − 1

X(k + N/2) = X11(k) − WkNX12(k), k = 0, 1, . . . , N/2 − 1

is known as the Butterly operation:

&%'$

����

���3

QQQQ

QQQs �

���

���3

QQQQ

QQQs

X11(k)

X12(k)

X(k)

X(k + N/2)

+

−WkN

The Discrete Fourier Transform is thus constructed by combining the transform two shorter

sequences of lengths N/2, N/4, . . . , 2, 1, starting with sequences of length 1.

38

Total number of operations:

- sequence of length N = 2B can be decomposed B = log2 N times.

- each stage requires N/2 Butterfly operations.

- Butterfly operations takes 2 complex additions and 1 complex multiplication.

=⇒Total number of complex additions = N log2 N

Total number of complex multiplications = (N/2) log2 N

39

INTERPRETATION OF FOURIER TRANSFORMCOMPONENTS

0

X(0)

X(1)

1

· · ·

X(k)

k

· · ·

X(N/2)

N/2

· · ·

X(N-k)=X(k)∗

N-k

· · ·X(N-1)=X(1)∗

N-1 N

Normalized frequency 0 1N

kN

12

N−kN

N−1N 1 (Hz)

Actual frequency

Sampling frequency fs = 1/Ts0 1

Nfs

kN

fs12fs

N−kN

fsN−1N

fs fs (Hz)

Matlab indexing X(1) X(2) X(k+1) X(N/2+1) X(N-k+1) X(N)

40

To observe:

• The frequency component X(k) corresponds to the frequency 2πk/N (radians/s)

or k/N (Hz) when the sampling frequency is normalized to 1 sample/s. If the

actual sampling frequency is fs (samples/s or Hz), X(k) corresponds to the frequency

(k/N)fs Hz.

• Highest frequency of which information can be obtained = half of sampling frequency

= fs/2

• Frequency resolution = fs/N , i.e., increasing sequence length N gives increased

resolution

• Magnitude and phase information from:

N/2 + 1 frequency components 0, 1/N, . . . , 1/2 (for even N),

(N + 1)/2 frequency components 0, 1/N, . . . , 12(N − 1)/N (for odd N)

• X(0) is real-valued; describes DC component (zero frequency)

1

NX(0) · cos(2π · 0 · n) =

1

NX(0)

41

• X(N/2) is real-valued; describes oscillating component (normalized frequency 1/2)

1

NX(N/2) · cos(2π · (1/2) · n) = (−1)

n 1

NX(N/2)

• Frequency components X(1), . . . , X(N/2 − 1) usually complex-valued.

- X(1) describes sinusoidal component with period N samples

- X(2) describes sinusoidal component with period N/2 samples, etc.

42