33
DSP First, 2/e Lecture Chapter 5 FIR Filtering Intro Modified TLH

DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

DSP First, 2/e

Lecture Chapter 5

FIR Filtering Intro

Modified TLH

Page 2: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 2

READING ASSIGNMENTS

This Lecture:

Chapter 5, Sects. 5-1, 5-2, 5-3 & 5-4 (partial)

Other Reading:

Next Lecture: Ch. 5, Sects 5-4, 5-6, 5-7 & 5-8

CONVOLUTION

Page 3: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

TOPICS

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 3

• RUNNING (MOVING) AVERAGE FILTER

• CAUSAL Filter >= 0

• Finite Impulse Response Description

• Unit Impulse Signal and Filter Response

• Compare 3-point and 7-point Averge

Page 4: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 4

LECTURE OBJECTIVES

INTRODUCE FILTERING IDEA

Weighted Average

Running Average

FINITE IMPULSE RESPONSE FILTERS

FIR Filters

Show how to compute the output y[n] from

the input signal, x[n]

Page 5: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 5

DIGITAL FILTERING

Characterized SIGNALS (Fourier series)

Converted to DIGITAL (sampling)

Today: How to PROCESS them (DSP)?

CONCENTRATE on the COMPUTER

ALGORITHMS, SOFTWARE (MATLAB) and

HARDWARE (DSP chips, VLSI)

COMPUTER D-to-AA-to-Dx(t) y(t)y[n]x[n]

Page 6: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 6

DISCRETE-TIME SYSTEM

OPERATE on x[n] to get y[n]

WANT a GENERAL CLASS of SYSTEMS

ANALYZE the SYSTEM

TOOLS: TIME-DOMAIN

& FREQUENCY-DOMAIN

SYNTHESIZE the SYSTEM

COMPUTERy[n]x[n]

Page 7: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 7

D-T SYSTEM EXAMPLES

EXAMPLES:

POINTWISE OPERATORS

SQUARING: y[n] = (x[n])2

RUNNING AVERAGE

RULE: “the output at time n is the average of three

consecutive input values”

SYSTEMy[n]x[n]

Page 8: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 8

x[n] 6

44

2

-1

-3 -2

-1

0 1 2 3 4 5

Consider the points

Page 9: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 9

From ECE 2601 Chapter 5

Causal is From The Past

Page 10: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4

>> n= -3:5;

>> x = [0 0 -1 2 4 6 4 0 0]

>> % We will learn about the filter function later

>> y = filter(1/3*[1 1 1],1,x);

>> stem(n,y,'filled')

• The action of the moving average filter has resulted in the

output being smoother than the input

• Since only past and present values of the input are being

used to calculate the present output, this filtering operation

can operate in real-time

y[n]

4

4.67

3.33

1.67

1.33

-1

0.33

-3 -2 -0.33 0 1 2 3 4 5

n

Page 11: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 11

DISCRETE-TIME SIGNAL

x[n] is a LIST of NUMBERS

INDEXED by “n”

STEM PLOT

Page 12: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 12

3-PT AVERAGE SYSTEM

ADD 3 CONSECUTIVE NUMBERS

Do this for each “n”

Make a TABLE

n=0

n=1

])2[]1[][(][31 nxnxnxny

Page 13: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 13

INPUT SIGNAL

OUTPUT SIGNAL

])2[]1[][(][31 nxnxnxny

Page 14: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 14

SLIDE a WINDOW across x[n]

PAST, PRESENT, FUTURE

Figure 5-3 Filter calculation at the present time (ℓ = n) uses values within a sliding window. Gray shading indicates the past (ℓ < n); orange shading, the future (ℓ > n). Here, the sliding window encompasses values from both the future and the past.

“n” is PRESENT TIME

Page 15: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 15

ANOTHER 3-pt AVERAGER

Uses “PAST” VALUES of x[n]

IMPORTANT IF “n” represents REAL TIME

WHEN x[n] & y[n] ARE STREAMS

])2[]1[][(][31 nxnxnxny

Page 16: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 16

CAUSAL 3-pt AVERAGER

])2[]1[][(][31 nxnxnxny

Page 17: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Finite Impulse Response

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 17

• Each output value y[n] is the some of a FINITE

number of weighted values of the input sequence x[n]

• The FIR filter can be represented in various ways:

• By a difference Equation Page 150

• By the Impulse Response Page 158

• By the Convolution Sum Page 162

Page 18: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 18

GENERAL CAUSAL FIR FILTER

FILTER COEFFICIENTS {bk}

DEFINE THE FILTER

For example,

M

k

k knxbny0

][][

]3[]2[2]1[][3

][][3

0

nxnxnxnx

knxbnyk

k

}1,2,1,3{ kb

NOTE: Index k = 0, 1,2,…

DIFFERENCE EQUATION

Page 19: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 19

GENERAL CAUSAL FIR FILTER

FILTER COEFFICIENTS {bk}

FILTER ORDER is M

FILTER “LENGTH” is L = M+1

NUMBER of FILTER COEFFS is L

M

k

k knxbny0

][][

Page 20: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 20

SLIDE a WINDOW across x[n]

x[n]x[n-M]

][]1[][][][ 10

0

Mnxbnxbnxbknxbny M

M

k

k

GENERAL CAUSAL FIR FILTER

Page 21: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 21

FILTERED STOCK SIGNAL

OUTPUT

INPUT

50-pt Averager

Page 22: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 22

00

01][

n

nn

SPECIAL INPUT SIGNALS

x[n] = SINUSOID

x[n] has only one NON-ZERO VALUE

1

n

UNIT-IMPULSE

FREQUENCY RESPONSE (LATER)

Test Signal

Page 23: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 23

UNIT IMPULSE SIGNAL [n]

[n] is NON-ZERO

When its argument

is equal to ZERO

]3[ n3n

Page 24: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 24

Sequence Representation

2]0[]0[ xnx

]3[]2[

]1[][]1[][

nn

nnnnx

4]1[]1[ xnx

6]2[]2[ xnx 4]3[]3[ xnx

Example:

2 4

6 4

0

Page 25: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

UNIT IMPULSE RESPONSE

FIR filter description usually given in terms

of coefficients bk

Can we describe the filter using a SIGNAL

instead?

What happens if input is a unit impulse?

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 25

M

k

k knxbny0

][][

Page 26: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 26

Example: 4-pt AVERAGER

CAUSAL SYSTEM: USE PAST VALUES

])3[]2[]1[][(][41 nxnxnxnxny

INPUT = UNIT IMPULSE SIGNAL = [n]

]3[]2[]1[][][

][][

41

41

41

41

nnnnny

nnx

OUTPUT is called “IMPULSE RESPONSE”

Denoted h[n]=y[n] when x[n]=[n]

Page 27: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 27

Unit Impulse Response

000000000

00000000

00000000

00000000

00000][

000001000][

543210123

41

41

41

41

41

41

41ny

nx

n

]3[]2[]1[][][41

41

41

41 nxnxnxnxny

][

]3[]2[]1[][][

][][

41

41

41

41

nh

nnnnny

nnx

Page 28: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 28

SUM of Shifted Impulses

]4[0]3[]2[]1[][][41

41

41

41 nnnnnnh

]4[]4[

]3[]3[

]2[]2[

]1[]1[

][]0[

nh

nh

nh

nh

nh

000000000

00000000

00000000

00000000

00000000

00000][

765432101

41

41

41

41

41

41

41

41nh

n

Page 29: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 30

FIR IMPULSE RESPONSE

M

k

k knxbny0

][][

M

k

k knbnh0

][][

Page 30: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 31

]4[]3[]2[2]1[][][ nnnnnnh

3 Ways to Represent the

FIR filter

Use SHIFTED IMPULSES to write h[n]

1

n

–1

2

0 4

][nh

}1,1,2,1,1{ kb

1

2: Plot the values

3: List the values

True for any signal, x[n]

Page 31: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 32

FILTERING EXAMPLE

7-point AVERAGER

Removes cosine

By making its amplitude (A) smaller

3-point AVERAGER

Changes A slightly

y7[n]17 x[n k]

k0

6

y3[n]13 x[n k]

k0

2

Page 32: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 33

3-pt AVG EXAMPLE

USE PAST VALUES

400for)4/8/2cos()02.1(][ :Input nnnx n

Page 33: DSP First, 2/e...The Running (Moving) Average Filter ECE 2610 Signals and Systems 5–4 >> n= -3:5; >> x = [0 0 -1 2 4 6 4 0 0] >> % We will learn about the filter function later

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 34

7-pt FIR EXAMPLE (AVG)

CAUSAL: Use Previous

LONGER OUTPUT

400for)4/8/2cos()02.1(][ :Input nnnx n