EE3054 Signals and Systems Lecture 1 FIR Filtering Introduction
Yao Wang Polytechnic University
Most of the slides included are extracted from lecture presentations prepared by McClellan and Schafer License Info for SPFirst Slides
This work released under a Creative Commons License with the following terms: Attribution The licensor permits others to copy, distribute, display, and perform the work. In return, licensees must give the original authors credit. Non-Commercial The licensor permits others to copy, distribute, display, and perform the work. In return, licensees may not use the work for commercial purposes—unless they get the licensor's permission. Share Alike The licensor permits others to distribute derivative works only under a license identical to the one that governs the licensor's work. Full Text of the License This (hidden) page should be kept with the presentation
1/22/2008 © 2003, JH McClellan & RW Schafer 2 What is a signal?
Speech waveform in time (1-D signal) Stock prices in time (1-D signal) Images (2-D signal) We will focus on 1-D signal in this class Continuous time signal x(t) Discrete time signal x[n] Discrete in nature Sampled from continuous time signal A Speech Signal:
1/22/2008 © 2003, JH McClellan & RW Schafer 4 What is a system?
Something that transforms an input signal to another signal Speech: Noise removal, echo cancellation, … Image: contrast enhancement, deblurring, … General mathematical description: y(t) = T ( x(t) ) y[n] = T ( x[n] ) 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” How to characterize signals?
In time domain directly In a transform domain: Represent a signal as sum of some basis signals Coefficients for different bases leads to a transform domain representation Fourier transform: Use sinusoidal signals as bases for both continuous and discrete time Z-transform: for discrete time only Laplace transform: for continuous time only How to characterize systems?
Impulse response Frequency response Helpful to look from a transformed domain representation Fourier transform: Impulse response -> frequency response Z-transform/Laplace transform: impulse response -> transfer function Topics Covered in This Course
Discrete time signals and systems Linear time invariant systems Convolution or filtering Impulse response Frequency response Z-transform analysis Discrete time Fourier transform Continuous time signals and systems Sampling of continuous time signals Using MATLAB for implementing signal and system operations and transforms LECTURE OBJECTIVES
INTRODUCE FILTERING IDEA Weighted Average Running Average FINITE IMPULSE RESPONSE FILTERS FIRFIR Filters Show how to compute the output y[n] from the input signal, x[n]
1/22/2008 © 2003, JH McClellan & RW Schafer 9 DIGITAL FILTERING
x(t)x[n] y[n] y(t) A-to-D COMPUTER D-to-A
CONCENTRATE on the COMPUTER PROCESSING ALGORITHMS SOFTWARE (MATLAB) HARDWARE: DSP chips, VLSI DSP: DIGITAL SIGNAL PROCESSING
1/22/2008 © 2003, JH McClellan & RW Schafer 10 DISCRETE-TIME SYSTEM
x[n] y[n] COMPUTER
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
1/22/2008 © 2003, JH McClellan & RW Schafer 11 D-T SYSTEM EXAMPLES
x[n] y[n] SYSTEM
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”
1/22/2008 © 2003, JH McClellan & RW Schafer 12 DISCRETE-TIME SIGNAL
x[n] is a LIST of NUMBERS INDEXED by “n”
STEM PLOT
1/22/2008 © 2003, JH McClellan & RW Schafer 13 3-PT AVERAGE SYSTEM ADD 3 CONSECUTIVE NUMBERS Do this for each “n” Make a TABLE = 1 + + + + y[n] 3 (x[n] x[n 1] x[n 2])
n=0
1/22/2008 © 2003, JH nMcClellan=1 & RW Schafer 14 INPUT SIGNAL
= 1 + + + + y[n] 3 (x[n] x[n 1] x[n 2])
OUTPUT SIGNAL
1/22/2008 © 2003, 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
= 1 + − + − y[n] 3 (x[n] x[n 1] x[n 2])
1/22/2008 © 2003, JH McClellan & RW Schafer 16 ANOTHER 3-pt AVERAGER
The output signals in previous examples are shifted from the input signals To align the output with the input, use both “PAST” and “FUTURE” VALUES of x[n] = 1 − + + + y[n] 3 (x[n 1] x[n] x[n 1])
Go through on the board PAST, PRESENT, FUTURE
“n”is TIME
1/22/2008 © 2003, JH McClellan & RW Schafer 18 3-pt AVG EXAMPLE π Input : x[n] = (1.02)n + cos(2 n /8 + π / 4) for 0 ≤ n ≤ 40
USE PAST VALUES
1/22/2008 © 2003, JH McClellan & RW Schafer 19 7-pt AVG EXAMPLE π Input : x[n] = (1.02)n + cos(2 n /8 + π / 4) for 0 ≤ n ≤ 40
CAUSAL: Use Previous
1/22/2008 © 2003, JH McClellan & RW Schafer 20 LONGER OUTPUT FILTERED STOCK SIGNAL
INPUT
OUTPUT
1/22/2008 © 2003, JH McClellan & RW Schafer 50-pt Averager21 GENERAL FIR FILTER FILTER COEFFICIENTS {bk} DEFINE THE FILTER M = − y[n] ∑bk x[n k] k=0 = − For example, bk {3, 1,2,1}
3 = − y[n] ∑bk x[n k] k=0 = 3x[n] − x[n −1] + 2x[n − 2] + x[n − 3]
1/22/2008 © 2003, JH McClellan & RW Schafer 22 Example
Given an input signal Compute the output of the previous filter
1/22/2008 © 2003, JH McClellan & RW Schafer 23 GENERAL FIR FILTER FILTER COEFFICIENTS {bk} M = − y[n] ∑bk x[n k] k=0 FILTER ORDER is M FILTER LENGTH is L = M+1 NUMBER of FILTER COEFFS is L
1/22/2008 © 2003, JH McClellan & RW Schafer 24 GENERAL FIR FILTER
SLIDE a WINDOW across x[n] M = − y[n] ∑bk x[n k] k=0
x[n-M] x[n] 1/22/2008 © 2003, JH McClellan & RW Schafer 25 More on signal ranges and lengths after filtering
Input signal from 0 to N-1, length=L1=N Filter from 0 to M, length = L2= M+1 Output signal? From 0 to N+M-1, length L3=N+M=L1+L2-1 Causal vs. Non-causal Filters?
So far we only considered the filters that range from 0 to M Output at n depends on input from n-M to n (past values only) These are called “Causal” filters More generally, the filter may range from M1 to M2 Output at n depends on input from n-M2 to n-M1 Ex. Centered averaging over 7 points, M1=-3, M2=3 Unit Impulse Signal
x[n] has only one NON-ZERO VALUE
1 n = 0 δ [n] = 0 n ≠ 0
UNIT-IMPULSE 1
n
1/22/2008 © 2003, JH McClellan & RW Schafer 28 UNIT IMPULSE SIGNAL δ[n]
n = 3 δ[n] is NON-ZERO δ [n − 3] When its argument is equal to ZERO
1/22/2008 © 2003, JH McClellan & RW Schafer 29 Any x[n] Can be Represented by Impuse Signals!
Use SHIFTED IMPULSES to write x[n] x[n] = 2δ [n] + 4δ [n −1] + 6δ [n − 2] + 4δ [n − 3] + 2δ [n − 4]
1/22/2008 © 2003, JH McClellan & RW Schafer 30 SUM of SHIFTED IMPULSES
This formula ALWAYS works
1/22/2008 © 2003, JH McClellan & RW Schafer 31 4-pt AVERAGER
CAUSAL SYSTEM: USE PAST VALUES y[n] = 1 (x[n] + x[n −1] + x[n − 2] + x[n − 3]) 4 δ INPUT = UNIT IMPULSEδ SIGNAL = δ[n] x[n] = δ [n] δ = 1 + 1 − + 1 − + 1 δ − y[n] 4 [n] 4 [n 1] 4 [n 2] 4 [n 3] OUTPUT is called “IMPULSE RESPONSE” = 1 1 1 1 h[n] { , 0, 0, 4 , 4 , 4 , 4 , 0, 0, }
1/22/2008 © 2003, JH McClellan & RW Schafer 32 4-pt Avg Impulse Response
= 1 + − + − + − y[n] 4 (x[n] x[n 1] x[n 2] x[n 3]) δ[n] “READS OUT” the FILTER COEFFICIENTS = 1 1 1 1 h[n] { , 0, 0, 4 , 4 , 4 , 4 , 0, 0, } “h” in h[n] denotes Impulse Response n=0 NON-ZERO n=–1 When window δ n=0 1 overlaps [n] n=1 n n=4 n=5 1/22/2008 © 2003, JH McClellan & RW Schafer 33 What is Impulse Response?
Impulse response is the output signal when the input is an impulse Finite Impulse Response (FIR) system: Systems for which the impulse response has finite duration For FIR system, impulse response = Filter coefficients h[k] = b_k Output = h[k]* input
1/22/2008 © 2003, JH McClellan & RW Schafer 34 FIR IMPULSE RESPONSE
Convolution = Filter Definition Filter Coeffs = Impulse Response
M M = − = − y[n] ∑bk x[n k] y[n] ∑h[k]x[n k] k=0 k=0 CONVOLUTION
1/22/2008 © 2003, JH McClellan & RW Schafer 35 MATH FORMULA for h[n]
Use SHIFTED IMPULSES to write h[n] h[n] = δ [n] −δ [n −1] + 2δ [n − 2] −δ [n − 3] +δ [n − 4]
2 h[n] 1
0 4 n = − − –1 bk {1, 1, 2, 1,1}
1/22/2008 © 2003, JH McClellan & RW Schafer 36 Convolution Sum
OutputOutput == ConvolutionConvolution ofof x[n]x[n] && h[n]h[n] NOTATION: y[n] = h[n]∗ x[n] Here is the FIR case: FINITE LIMITS
M y[n] = ∑h[k]x[n − k] k=0 FINITE LIMITS Same as bk
1/22/2008 © 2003, JH McClellan & RW Schafer 37 CONVOLUTION Example h[n] = δ [n] −δ [n −1] + 2δ [n − 2] −δ [n − 3] + δ [n − 4] x[n] = u[n] n −101234567 x[n]01111111... h[n]01−12−11000 h[0]x[n] 011111111 h[1]x[n −1] 00−1 −1 −1 −1 −1 −1 −1 h[2]x[n − 2] 000222222 h[3]x[n − 3] 00 0 0−1 −1 −1 −1 −1 h[4]x[n − 4] 000001111
1/22/2008 y[n]01021222...© 2003, JH McClellan & RW Schafer 38 Convolution via Synthetic Polynomial Multiplication
Another example
1/22/2008 © 2003, JH McClellan & RW Schafer 39 GENERAL FIR FILTER
SLIDE a Length-L WINDOW over x[n] When h[n] is not symmetric, needs to flip h(n) first!
x[n-M] x[n]
1/22/2008 © 2003, JH McClellan & RW Schafer 40 DCONVDEMO: MATLAB GUI
1/22/2008 © 2003, JH McClellan & RW Schafer 41 Go through the demo program for different types of signals
1/22/2008 © 2003, JH McClellan & RW Schafer 42 Length of filtered signals Alignment of input and output
1/22/2008 © 2003, JH McClellan & RW Schafer 43 POP QUIZ
FIR Filter is “FIRST DIFFERENCE” y[n] = x[n] - x[n-1] INPUT is “UNIT STEP” 1 n ≥ 0 u[n] = 0 n < 0
Find y[n] y[n] = u[n] − u[n −1] = δ [n]
1/22/2008 © 2003, JH McClellan & RW Schafer 44 READING ASSIGNMENTS
This Lecture: Chapter 1 Chapter 5, Sects. 5-1, 5-2 and 5-3 (partial)