CS计算机代考程序代写 algorithm gui matlab DSP First, 2/e

DSP First, 2/e
Lecture 11
FIR Filtering Intro
LECTURE OBJECTIVES
§ INTRODUCE FILTERING IDEA § Weighted Average
§ Running Average
§ FINITE IMPULSE RESPONSE FILTERS
FIR Filters
the input signal, x[n]
§
§ Show how to compute the output y[n] from
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 3
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
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 2
DIGITAL FILTERING
x(t) x[n] y[n]
§ 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)
y(t)
A-to-D
COMPUTER
D-to-A
Aug 2016 © 2003-2016, JH McClellan & RW Schafer
4

The TMS32010, 1983
First PC plug-in board from Atlanta Signal Processors Inc.
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 5
Digital Cell Phone (ca. 2000)
Voice Band Audio Processor (VBAP)
Now, digital cameras and video streaming rely on DSP algorithms
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 7
Rockland Digital Filter, 1971
Cost was about the same as the price of a small house.
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 6
5G Cell Phone Architecture (ca. 2020)
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 8

DISCRETE-TIME SYSTEM
x[n] y[n]
§ 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
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 9
COMPUTER
DISCRETE-TIME SIGNAL
§ x[n] is a LIST of NUMBERS § INDEXED by “n”
Aug 2016 © 2003-2016, JH McClellan & RW Schafer
11
STEM PLOT
D-T SYSTEM EXAMPLES
x[n] y[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”
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 10
SYSTEM
3-PT AVERAGE SYSTEM
§ ADD 3 CONSECUTIVE NUMBERS § Do this for each “n”
Make a TABLE
y [ n ] = 13 ( x [ n ] + x [ n + 1 ] + x [ n + 2 ] )
n=0
Aug 2016
1
© 2003-2016, J
M
n
H
cClellan & RW Schafer 12
=

INPUT SIGNAL
y [ n ] = 13 ( x [ n ] + x [ n + 1 ] + x [ n + 2 ] )
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 13
OUTPUT SIGNAL
ANOTHER 3-pt AVERAGER
§ Uses “PAST” VALUES of x[n]
§ IMPORTANT IF “n” represents REAL TIME
§ WHEN x[n] & y[n] ARE STREAMS
y [ n ] = 13 ( x [ n ] + x [ n – 1 ] + x [ n – 2 ] )
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 15
PAST, PRESENT, FUTURE
§ SLIDE a WINDOW across x[n]
“n” is PRESENT TIME
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 14
Figure 5-3 Filter calculation at the present time (l = n) uses values within a sliding window. Gray shading indicates the past (l < n); orange shading, the future (l > n). Here, the sliding window encompasses values from both the future and the past.
CAUSAL 3-pt AVERAGER
y [ n ] = 13 ( x [ n ] + x [ n – 1 ] + x [ n – 2 ] )
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 16

GENERAL CAUSAL FIR FILTER
§ FILTER COEFFICIENTS {bk} § DEFINE THE FILTER
§ For example,
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 17
M y[n]=åb x[n-k]
k k=0
bk ={3,-1,2,1}
3 y[n]=åb x[n-k]
k k=0
= 3x[n] – x[n – 1] + 2 x[n – 2] + x[n – 3]
GENERAL CAUSAL FIR FILTER
§ SLIDE a WINDOW across x[n]
M
y[n]=åb x[n-k]=b x[n]+bx[n-1]+!+b x[n-M]
k01M k=0
x[n-M] x[n]
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
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 18
M y[n]=åb x[n-k]
k k=0
FILTERED STOCK SIGNAL
INPUT
Aug 2016 © 2003-2016, JH McClellan & RW Schafer
OUTPUT
50-pt Averager
20

Aug 2016 © 2003-2016, JH McClellan & RW Schafer 21
READING ASSIGNMENTS
§ This Lecture:
§ Chapter 5, Sections 5-4, 5-6, 5-7 & 5-8
§ Section 5-5 is covered, but not “in depth” § Convolution in Section 5-7 is important
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 24
DSP First, 2/e
Lecture 12
Linearity & Time-Invariance Convolution
LECTURE OBJECTIVES
§ GENERAL PROPERTIES of FILTERS
LTI SYSTEMS
L T
§
§
§ ==>
I
NVARIANCE
INEARITY
IME-
CONVOLUTION
§ BLOCK DIAGRAM REPRESENTATION
§ Components for Hardware
§Connect Simple Filters Together to Build More Complicated Systems
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 25

OVERVIEW
§IMPULSERESPONSE, h[n] § FIR case: same as {bk }
§ CONVOLUTION
§GENERAL: y[n]=h[n]*x[n]
§ GENERAL CLASS of SYSTEMS
§ LINEAR and TIME-INVARIANT
§ ALL LTI systems have h[n] & use convolution Aug 2016 © 2003-2016, JH McClellan & RW Schafer 26
BUILDING BLOCKS
x[n] +
§ BUILD UP COMPLICATED FILTERS
§ FROM SIMPLE MODULES
§ Ex: FILTER MODULE MIGHT BE 3-pt FIR
OUTPUT
y[n]
FILTER
INPUT
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 28
FILTER
+
FILTER
DIGITAL FILTERING
x(t) x[n] y[n] y(t) §CONCENTRATEontheFILTER (DSP)
§ DISCRETE-TIME SIGNALS
§ FUNCTIONS of n, the “time index” § INPUT x[n]
§ OUTPUT y[n]
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 27
A-to-D
FILTER
D-to-A
GENERAL FIR FILTER
§ FILTER COEFFICIENTS {bk} § DEFINE THE FILTER
§ For example,
M y[n]=åb x[n-k]
k k=0
bk ={3,-1,2,1}
3 y[n]=åb x[n-k]
k k=0
= 3x[n] – x[n – 1] + 2 x[n – 2] + x[n – 3]
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 29

MATLAB for FIR FILTER
§yy = conv(bb,xx)
§ VECTOR bb contains Filter Coefficients §DSP-First: yy=firfilt(bb,xx)
§FILTERCOEFFICIENTS {bk}
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 30
conv2()
for images
M y[n]=åb x[n-k]
k k=0
UNIT IMPULSE RESPONSE
§ FIR filter DIFFERENCE EQUATION is specified by the filter coefficients bk
§ EQUIVALENCE: can we describe the filter using a SIGNAL instead?
M y[n]=åb x[n-k]
k k=0
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 32
SPECIAL INPUT SIGNALS
§ x[n] = SINUSOID
§ x[n] has only one NON-ZERO VALUE
UNIT-IMPULSE
Later, sinusoid leads to the FREQUENCY RESPONSE
ì1 n=0 d [ n ] = ïí
ïî0 n10
1
n
Aug 2016 © 2003-2016, JH McClellan & RW Schafer
31
FIR IMPULSE RESPONSE
M y[n]=åb x[n-k]
k k=0
M
h[n] = åb d [n – k]
k k=0
§ Impulse response h[k]=bk is, in fact, a SIGNAL description of filter coefficients
§ Allows us to write CONVOLUTION sum
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 33

LTI: Convolution Sum
Output = Convolution of x[n] & h[n]
§
§NOTATION: y[n]=h[n]*x[n] § FIR case:
FINITE LIMITS
M
y[n] = åh[k]x[n – k]
k=0
Same as bk
Aug 2016 © 2003-2016, JH McClellan & RW Schafer
36
FINITE LIMITS
CONVOLUTION Example
h[n]=d[n]-d[n-1]+2d[n-2]-d[n-3]+d[n-4] x[n] = u[n]
n -1 0 1
x[n] h[n]
2 3 4 5 6 7 1 1 1 1 1 … 2 -1 1 0 0 0
M
y[n] = åh[k]x[n – k]
k=0
0 1 1
0 1 -1
0
00
000
000 000001111
Aug 2016
y[n]
0 1 0 2 1 2 2 2 …
11111111
h[0]x[n] h[1]x[n-1] h[2]x[n – 2] h[3]x[n – 3] h[4]x[n – 4]
-1 -1 -1 -1 -1 -1 -1
222222
0 -1 -1 -1 -1 -1
© 2003-2016, JH McClellan & RW Schafer 38
y[n] = h[n]* x[n] LTI: Convolution Sum
Delay the signal x[n] & then multiply by filter coefficients that come from h[n]
§
M
y[n] = åh[k]x[n – k]
k=0
= h[0]x[n] + h[1]x[n – 1] + h[2]x[n – 2] + !
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 37
GENERAL CAUSAL FIR FILTER
§ SLIDE a Length-L WINDOW across x[n]
M
y[n]=åb x[n-k]=b x[n]+bx[n-1]+!+b x[n-M]
k01M k=0
x[n-M] x[n]
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 39

DCONVDEMO: MATLAB GUI
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 40
HARDWARE ATOMS
§ Add, Multiply & Store
y[n] = b x[n]
y[n]= x[n-1]
y[n]= x1[n]+ x2[n]
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 44
M y[n]=åb x[n-k]
k k=0
HARDWARE STRUCTURES
x[n] FILTER y[n]
§ INTERNAL STRUCTURE of “FILTER”
§ WHAT COMPONENTS ARE NEEDED?
§ HOW DO WE “HOOK” THEM TOGETHER?
§ SIGNAL FLOW GRAPH NOTATION
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 43
M y[n]=åb x[n-k]
k k=0
FIR STRUCTURE
§ Direct Form
M y[n]=åb x[n-k]
k k=0
SIGNAL FLOW GRAPH
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 45

SYSTEM PROPERTIES
x[n] SYSTEM y[n] MATHEMATICAL DESCRIPTION
§
§ TIME
– LINEARITY
INVARIANCE
§
§ CAUSALITY
§ “No output prior to input”
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 46
TESTING Time-Invariance
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 48
TIME-INVARIANCE
§ IDEA:
§ “Time-Shifting the input will cause the same
time-shift in the output” § EQUIVALENTLY,
§ We can prove that
§ The time origin (n=0) is picked arbitrary
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 47
LINEAR SYSTEM
§ LINEARITY = Two Properties § SCALING
§ “Doubling x[n] will double y[n]” § SUPERPOSITION:
§ “Adding two inputs gives an output that is the sum of the individual outputs”
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 49

TESTING LINEARITY
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 50
FILTER STOCK PRICES
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 52
LTI SYSTEMS
y[n] = h[n]* x[n] §LTI: Linear&Time-Invariant
§ COMPLETELY CHARACTERIZED by: § IMPULSE RESPONSE h[n]
§ CONVOLUTION:
§The “rule” defining the system can ALWAYS be
re-written as convolution
§ FIR Example: h[n] is same as bk
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 51
CASCADE SYSTEMS
§ A second FIR filter compensates for Delay
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 53

STOCK PRICES FILTERED (2)
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 54
CASCADE EQUIVALENT
§ Find “overall” h[n] for a cascade ?
S1
S2
S2
S1
Aug 2016
© 2003-2016, JH McClellan & RW Schafer 56
CASCADE SYSTEMS
§ Does the order of S1 & S2 matter?
§ NO, LTI SYSTEMS can be rearranged !!! § WHAT ARE THE FILTER COEFFS? {bk}
Aug 2016
© 2003-2016, JH McClellan & RW Schafer
55
S1
S2
DSP First, 2/e
Lecture 13 Frequency Response
of FIR Filters

READING ASSIGNMENTS
§ Chapter 6
§ Sections 6-1 to 6-5
§ Sections 6-6, 6-7 & 6-8
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 67
DOMAINS: Time & Frequency
§Time-Domain: “n”=time § x[n] discrete-time signal §x(t) continuous-timesignal
§ Frequency Domain (sum of sinusoids) § Spectrum vs. f (Hz)
• ANALOG vs. DIGITAL
§ Spectrum vs. omega-hat
§ Move back and forth QUICKLY
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 69
LECTURE OBJECTIVES
§ SINUSOIDAL INPUT SIGNAL
§ DETERMINE the FIR FILTER OUTPUT
§FREQUENCYRESPONSEofFIR MAG
§ PLOTTING vs. Frequency § MAGNITUDE vs. Freq
PHASE
§PHASEvs.Freq H(ejwˆ)= H(ejwˆ)ejÐH(ejwˆ ) Aug 2016 © 2003-2016, JH McClellan & RW Schafer 68
DIGITAL “FILTERING”
x(t) x[n] y[n] y(t)
§ CONCENTRATE on the
§ SINUSOIDAL INPUT
§ INPUT x[n] = SUM of SINUSOIDS
§ Then, OUTPUT y[n] = SUM of SINUSOIDS
A-to-D

FILTER
D-to-A

SPECTRUM
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 72

FILTERING EXAMPLE
§ 7-point AVERAGER § Removes cosine
§ By making its amplitude (A) smaller § 3-point AVERAGER
§ Changes A slightly
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 73
y [n]=å6 (1)x[n-k] 77
k=0
y [n]=å2 (1)x[n-k] 33
k=0
7-pt FIR EXAMPLE (AVG)
Input:x[n]=(1.02)n +cos(2pn/8+p/4) for0£n£40
CAUSAL: Use Previous
Aug 2016 © 2003-2016, JH McClellan & RW Schafer
LONGER OUTPUT
76
3-pt AVG EXAMPLE
Input:x[n]=(1.02)n +cos(2pn/8+p/4) for0£n£40
USE PAST VALUES
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 75
SINUSOIDAL RESPONSE
§INPUT: x[n]=SINUSOID
§ OUTPUT: y[n] will also be a SINUSOID
§ Different Amplitude and Phase §SAME Frequency
§ AMPLITUDE & PHASE CHANGE
§ Called the
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 77
FREQUENCY RESPONSE

COMPLEX EXPONENTIAL
x[n]= Aejjejwˆn -¥ Sinusoid OUT
§ At the SAME Frequency
§ Only Magnitude and Phase change
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 103

Time & Frequency Relation
§ Get Frequency Response from h[n] § Here is the FIR case:
MM H(ejwˆ)=åbe-jwˆk = h[k]e-jwˆk
å k=0 k=0
k
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 104
IMPULSE RESPONSE
UNIT IMPULSE SYSTEM
§ What is the output of a unit impulse system?
x[n]
x[n]
h; =<[;] y[n] y[n] = x[n] wˆ © 2003-2016, JH McClellan & RW Schafer 106 Aug 2016 %&!# =1 wˆ BLOCK DIAGRAMS § Equivalent Representations x[n] h[n] y[n] x[n] H(ejwˆ)y[n] wˆ Aug 2016 © 2003-2016, JH McClellan & RW Schafer wˆ 105 UNIT-DELAY SYSTEM Find h[n] and H (e jwˆ ) for y[n] = x[n - 1] d[n-1] H ( e j wˆ ) x[n] y[n] Aug 2016 © 2003-2016, JH McClellan & RW Schafer 107 x[n] y[n] wˆ {bk}={0, 1} e - j wˆ wˆ FIRST DIFFERENCE SYSTEM Find h[n] and H (e jwˆ ) for the Difference Equation : y[n] = x[n] - x[n - 1] x[n] x[n] y[n] y[n] H ( e j wˆ ) d[n]-d[n-1] 1 - e - j wˆ Aug 2016 © 2003-2016, JH McClellan & RW Schafer 108 DELAY by 2 SYSTEM Findh[n]and H(ejwˆ )for y[n]= x[n-2] x[n] y[n] d[n-2] H ( e j wˆ ) e - j 2 wˆ k = 2 ONLY M H ( e j wˆ ) = å d [ k - 2 ] e - j wˆ k k=0 x[n] y[n] Aug 2016 © 2003-2016, JH McClellan & RW Schafer 110 wˆ wˆ Ex: DELAY by 2 SYSTEM Findh[n]and H(ejwˆ )for y[n]= x[n-2] x[n] h[n] y[n] bk ={0,0,1} h[n]=d[n-2] Aug 2016 x[n] H(ejwˆ)y[n] wˆ wˆ © 2003-2016, JH McClellan & RW Schafer 109 GENERAL DELAY PROPERTY Findh[n]and H(ejwˆ )for y[n]= x[n-nd ] h[n] = d [n - nd ] M H(ejwˆ)=åd[k-n ]e-jwˆk =e-jwˆnd d k=0 ONLY ONE non-ZERO TERM fork atk=nd Aug 2016 © 2003-2016, JH McClellan & RW Schafer 111 FREQ DOMAIN à TIME ?? §STARTwith H(ejwˆ)andfindh[n]orb x[n] h[n] y[n] x[n] H(ejwˆ)y[n] k h[n] = ? H(ejwˆ)=7e-j2wˆ cos(wˆ) Aug 2016 wˆ wˆ © 2003-2016, JH McClellan & RW Schafer 112 DSP First, 2/e Lecture 14 Digital Filtering of Analog Signals FREQ DOMAIN --> TIME
H(ejwˆ)=7e-j2wˆ cos(wˆ) EULER’sFormula =7e-j2wˆ(0.5ejwˆ +0.5e-jwˆ)
=(3.5e-jwˆ +3.5e-j3wˆ)
h[n] = 3.5d [n – 1] + 3.5d [n – 3]
bk ={0,3.5,0,3.5}
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 113
DIGITAL “FILTERING”
x(t) x[n] y[n] y(t) w wˆ wˆ
§ SPECTRUM of x(t) (SUM of SINUSOIDS)
§ SPECTRUM of x[n] (ALIASING a PROBLEM?)
§ SPECTRUM y[n] (FIR Gain or Nulls)
§ Then, OUTPUT y(t) = SUM of SINUSOIDS
A-to-D
H ( e j wˆ )
D-to-A
Question: how to characterize the effects of a digital filter on the analog signals? Answer: Frequency Scaling
Aug 2016 © 2003-2016, JH McClellan & RW Schafer 119
w
w

w

FREQUENCY SCALING
x(t) A-to-D x[n] H (e jwˆ ) y[n] D-to-A y(t)
w wˆ wˆ w
Example: Frequency Response of “Rectangular” (sum or averaging) filter
§ The frequency response for a “rectangular” filter provides insightful analysis about the relationship between the impulse response h[n] of a filter and its frequency response H.
§ In particular, the “width” of the impulse response impacts the “width” of the frequency response magnitude
§ TIME SAMPLING: t = nTs
§ IF NO ALIASING:
w
s
§FREQUENCYSCALING w=wT = ˆsf
Aug 2016
© 2003-2016, JH McClellan & RW Schafer 120
Aug 2016
􏰁􏰀􏰀􏰁
© 2003-2016, JH McClellan & RW Schafer 121
Example: Frequency Response of “Rectangular” (sum or averaging) filter
§ Recall that the Discrete-Time Fourier Transform (DTFT) for a rectangular signal x[n] is:
x[n]=ìí1 0£n