MIT OpenCourseWare http://ocw.mit.edu MAS.160 / MAS.510 / MAS.511 Signals, Systems and Information for Media Technology Fall 2007 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Causal FIR filter x [ n] Causal FIR filter y[ n ] Q:What is the definition of an FIR filter? Causal FIR filter x [ n] Causal FIR filter y[ n ] Q:What is the definition of an FIR filter? A: The output y at each sample n is a weighted sum of the present input, x[n], and past inputs, x[n-1], x[n-2],…, x[n-M]. Causal FIR filter x [ n] Causal FIR filter y[ n ] Q:What is the formula for an FIR filter? Causal FIR filter x [ n] Causal FIR filter y[ n ] Q:What is the formula for an FIR filter? y [ n ] = b0 x [ n ] + b1 x [ n 1] + K + bM x [ n M ] M y [ n ] = � bk x [ n k ] k= 0 � n x[n ] x n =� n 0 [ ] [ ] Causal FIR filter 2 b0 = 1,b1 = 3,b2 = 1 1 0 1 0 y[n] = ? 1 0 h[n] = ? 2 0 y[1 ] = ? 3 0 1 0.9 0.8 0.7 x[n] 0.6 0.5 TextEnd 0.4 0.3 0.2 0.1 0 -2 -1 0 1 2 n 3 4 5 y[n] = ? �y[n]� � n x[n] � � 0 � x n = � n � 0 [ ] [ ] Causal FIR filter h[n] = y[n] x[ n ]=� [ n ] 2 � 0 � b = 1,b = 3,b = 1 1 0 1 2 0 � � b 1 � � 0 1 �b 3 � 1 0 � � y[n] = 1x[n] + 3x[n 1] +1x[n 2] 1 b � � 2 0 h[n] = y[n] = 1� [n] + 3� [n 1] +1� [ n 2] � 0 �� 3 0 h[n] = bn 0 1 2 h[1] = 1� [1] + 3� [11] + 1� [1 2] h[1] = 1� [1] + 3� [0] +1� [1] 0.9 0.8 h[1] = 1(0) + 3(1) +1(0) 0.7 x[n] 0.6 0.5 TextEnd h[1] = 3 0.4 0.3 0.2 3 h[1]=b1 2.5 2 y[n] 1 1.5 TextEnd h[0]=b0 h[2]=b2 1 0.5 0.1 0 -2 -1 0 1 2 n 3 4 5 0 -2 -1 0 1 2 n 3 4 5 x [ n] Causal FIR filter b0 ,b1 ,b2 h[n] M y [ n ] = � bk x [ n k ] y[ n ] weighted sum of delayed inputs k= 0 h[n] = bn M y[n] = � h[k]x [n k ] k=0 y[n] = h[n]* x[n] Convolution of impulse response and input � n 0 1 2 3 4 5 x [n ] x[n] = sin( 2� � 0.33n)u[n] 0 0.88 0.84 0.06 0.90 0.81 1 0.8 0.6 0.4 x[n] 0.2 0 TextEnd -0.2 -0.4 -0.6 -0.8 -1 0 0.5 1 1.5 2 2.5 n 3 3.5 4 4.5 5 Causal FIR filter b0 = 1,b1 = 3,b2 = 1 h[n] = [1, 3, 1] y[ 3 ] = ? y[n] = ? � n 0 1 2 3 4 5 x [n ] x[n] = sin( 2� � 0.33n)u[n] Causal FIR filter 0 b0 = 1,b1 = 3,b2 = 1 0.88 h[n] = [1, 3, 1] 0.84 M M bk x [ n k ] = � h[k]x[ n k ] 0.06 y[n] = k � =0 k = 0 0.90 y[n] = 1x[n] + 3x[ n 1 ] + 1x[n 2] 0.81 y[ 3 ] = 1x[ 3 ] + 3x[ 3 1] + 1x[ 3 2 ] y[ 3 ] = 1x[ 3] + 3x [2] + 1x[1] y[n ] 0 0.88 1.78 1.72 0.13 1.84 � n 0 1 2 3 4 5 2 y[ 3 ] = 1(0.06 ) + 3(0.84 ) + 1( 0.88 ) 1.5 1 0.8 0.6 0.5 y[n] y[ 3] = 1.72 1 0 TextEnd 0.4 -0.5 x[n] 0.2 0 TextEnd -1 -0.2 -0.4 -1.5 -0.6 -0.8 -1 -2 0 0.5 1 1.5 2 2.5 n 3 3.5 4 4.5 5 0 0.5 1 1.5 2 2.5 n 3 3.5 4 4.5 5 Graphical Convolution y[n] = h[n]* x[n] = x[n]* h[n] M � k=0 k=�� sum y[n] = � h[k]x [n k ] = � x[k]h[n � k ] multiply flip shift 1 1 0.5 x[n] 0.5 x[n] 0 TextEnd 0 TextEnd -0.5 -0.5 -1 -2 -1 0 1 2 3 4 5 -1 -2 n -1 0 1 h[1]=b1 2.5 4 5 2 3 4 5 b1=3 TextEnd 1 h[0]=b0 h[-n] 2 h[2]= b2 0.5 0 -2 -1 0 1 2 3 4 5 1 b2=1 TextEnd 0 -2 n b0=1 -1 0 1 n 1 y[n] = x [n 2]h[n (n 2)]+ x[n 1]h[n (n 1)]+ x[n]h[n n] 0.5 y[n] h[-n] 3 3 flip 2 1.5 2 n 3 0 TextEnd y[n] = h[0]x [n] + h[1]x[n 1] + h[2]x [n 2 ] -0.5 -1 -2 -1 0 1 2 n 3 4 5 Graphical Convolution sum 0 y[n] = � x[k]h[n k ] k= M multiply flip shift n=0 1 0.5 x[n] 0 0 0 TextEnd 0 -0.5 -1 -2 -1 0 1 2 3 4 5 2 3 4 5 2 3 4 5 n 3 h[-n] flip/ shift by n b1=3 2 1 b0=1 TextEnd multiply b2=1 0 -2 -1 0 sum 1 n 1 y[n] 0.5 0 0 TextEnd -0.5 -1 -2 -1 0 1 n y[0] = x [2]h[2]+ x [1]h[1]+ x[0]h[0] = (0)1+ (0) 3+ (0)1 = 0 Graphical Convolution sum 0 y[n] = � x[k]h[n k ] k= M flip multiply shift n=1 1 0.88 x[n] 0.5 0 0 TextEnd 0 -0.5 -1 -2 -1 0 1 2 3 4 5 2 3 4 5 2 3 4 5 n 3 h[-n] 2 b1=3 TextEnd 1 b0=1 multiply b2=1 0 -2 -1 0 1 sum n 2 0.88 1 y[n] flip/ shift by n 0 TextEnd -1 -2 -2 -1 0 1 n y[1] = x [1]h[2]+ x [0]h[1]+ x[1]h[0] = (0)1+ (0) 3+ (0.88)1 = 0.88 Graphical Convolution sum 0 y[n] = � x[k]h[n k ] k= M flip multiply shift n=2 1 0.88 x[n] 0.5 0 0 TextEnd -0.5 -0.84 -1 -2 -1 0 1 2 3 4 5 n 3 h[-n] 2 b1=3 TextEnd 1 b0=1 multiply b2=1 0 -2 -1 0 1 2 n 2 sum 3 4 5 3 4 5 1.78 1 y[n] flip/ shift by n 0 TextEnd -1 -2 -2 -1 y[ 2 ] = x [ 0 ( 0 1 2 n )]h[2]+ x[1]h[1]+ x[2]h[0] = (0)1+ (0.88) 3+ (0.84 )1 = 1.78 Graphical Convolution sum 0 y[n] = � x[k]h[n k ] k= M flip multiply shift n=3 1 0.88 x[n] 0.5 -0.06 0 TextEnd -0.5 -0.84 -1 -2 -1 0 1 2 3 4 5 n 3 h[-n] 2 b0=1 b2=1 TextEnd 1 0 -2 -1 0 1 2 multiply 3 4 5 4 5 n 2 sum 1 y[n] flip/ shift by n b1=3 0 TextEnd -1 -2 -2 -1.71 -1 0 1 2 n 3 y[ 3] = x [1]h[2]+ x[2]h[1]+ x[3]h[0] = (0.88)1+ (0.84 ) 3+ (0.06)1 = 1.72 Graphical Convolution 0 y[n] = � x[k]h[n k ] k= M y[n] = x[k]* h[k] 1 x[n] 0.5 0 TextEnd -0.5 -1 -2 -1 0 1 2 3 4 5 2 3 4 5 2 3 4 5 n 3 b1 h[n] 2 b0 b2 TextEnd 1 0 -2 -1 0 1 n 2 y[n] 1 0 TextEnd -1 -2 -2 -1 0 1 n Graphical convolution by decomposition 1. Remember impulse response x[n] = �[n] causal FIR filter h[n] = b0� [n] + b1� [n 1] + b2� [n 2] b0 ,b1 ,b2 h[n] 1 3 h[1]=b1 0.9 2.5 0.8 0.7 2 0.5 TextEnd y[n] x[n] 0.6 1.5 TextEnd h[0]=b0 0.4 h[2]=b2 1 0.3 0.2 0.5 0.1 0 -2 -1 0 1 2 n 3 4 5 0 -2 -1 0 1 2 n 3 4 5 Graphical convolution by decomposition 2. Decompose input into sum of scaled delayed impulses Input Input as impulses x[n] = 0.88� [n 1] 0.84� [n 2] 0.06� [n 3] x[n] = sin(2 � � 0.33n)u[n] + 0.90� [n 4 ] 0.81� [n 5] x[1] 2 0 1 TextEnd -2 -2 2 0.8 x[2] 0.6 0 -1 0 1 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 2 3 4 5 n TextEnd 0.4 -2 -2 2 x[3] 0 TextEnd -0.2 x[4] -0.6 -0.8 -1 -2 0 -1 0 1 2 n 3 4 0 0 0 1 n -1 0 1 n TextEnd -2 -2 2 5 -1 TextEnd -2 -2 2 -0.4 x[5] x[n] 0.2 -1 0 1 n TextEnd -2 -2 -1 0 1 n Graphical convolution by decomposition 3. find impulse responses to each impulse Input as impulses Impulse responses h[n] = b0� [n] + b1� [n 1] + b2� [n 2] x[3] x[4] x[5] 2 x1[n 2] = 0.84�[n 2] -1 x[1]h[n-1] 3 4 5 0 1 2 4 5 x1[n 3] = 0.06�[n 3] n -1 0 1 2 3 4 TextEnd -1 0 1 2 3 4 TextEnd -2 -2 -1 0 1 2 n FIR 3 4 5 2 0 -2 2 0 -2 -2 5 n 0 -2 -2 5 n 2 -2 x[2]h[n-2] 3 TextEnd -2 -2 2 0 1 n -2 -2 2 0 0 TextEnd -2 -2 2 0 -1 x[3]h[n-3] x[2] -2 -2 2 0 x1[n 1] = 0.88�[n 1] TextEnd x[4]h[n-4] 0 2 0 -2 -2 x[5]h[n-5] x[1] 2 2 0 -2 -2 y1[n] = 0.88(h[n 1]) TextEnd -1 0 1 2 y2 [n] = 0.84 (h[n 2]) 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 n TextEnd -1 0 1 2 y3 [n] = 0.06(h[n 3]) n TextEnd -1 0 1 2 y4 [n] = 0.06(h[n 4]) n TextEnd -1 0 1 2 y5 [n] = 0.81(h[n 5]) TextEnd -1 0 1 n 2 n Graphical convolution by decomposition 3. sum impulse responses to get total response Input as impulses Impulse responses 3 4 5 x[2]h[n-2] n -1 0 1 2 3 4 5 n -1 0 1 2 3 4 -1 0 1 2 3 4 TextEnd -2 -2 -1 0 1 FIR 2 3 4 TextEnd -1 1 2 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 n 0 -2 TextEnd -1 0 1 2 n 2 0 -2 TextEnd -1 0 1 2 n 2 0 -2 TextEnd -2 5 0 2 -2 5 n 0 -2 -2 5 n 2 -2 x[3]h[n-3] x[3] x[4] x[5] 2 TextEnd -2 -2 2 0 1 TextEnd -2 -2 2 0 0 TextEnd -2 -2 2 0 -1 x[4]h[n-4] x[2] -2 -2 2 0 x[1]h[n-1] TextEnd x[5]h[n-5] 0 -1 0 1 2 n 2 0 -2 -2 TextEnd -1 0 1 2 n n sum total response 2 y[n] x[1] 2 0 TextEnd -2 -2 -1 0 1 2 3 n 4 5 6 7 Graphical convolution by decomposition x[n] 1 Input 0 TextEnd -1 -2 -1 0 1 2 3 4 5 n Impulse response h[n] 2 0 TextEnd -2 -2 -1 0 1 2 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 3 4 5 6 7 Impulse responses x[1]h[n-1] n 2 0 -2 TextEnd x[2]h[n-2] -2 -1 x[3]h[n-3] 2 0 -2 TextEnd -1 0 1 2 n 2 0 -2 TextEnd -2 x[4]h[n-4] 1 n -2 -1 0 1 2 n 2 0 -2 TextEnd -2 x[5]h[n-5] 0 2 -1 0 1 2 n 2 0 -2 -2 TextEnd -1 0 1 2 n total response y[n] 2 0 TextEnd -2 -2 -1 0 1 2 n Synthetic polynomial multiplication n -2 -1 0 1 2 3 4 5 x[n] 0 0 0 0.88 -0.84 -0.06 0.90 -0.81 h[n] 1 3 1 =============================================== 0 0 0 0.88 2.64 0.88 -0.84 -2.52 -0.84 -0.06 -0.18 -0.06 0.9 2.7 -0.81 =============================================== y[n] 0 0 0 0.88 1.80 -1.7 -0.12 1.83 try h1[n]* h2[n] h1[n]=[1/3,1/3,1/3] h2[n]=[1/3,-1/3,1/3] Impulse response M y [ n ] = � bk x [ n k ] FIR filter k= 0 �1 n = 0 x [ n ] = �[n] = � Delta function � 0 otherwise M y [ n ] x= � [n ] = h[n] = � bk� [ n k ] k= 0 impulse response y [ n] = � � h[n]x [n � k ] k=�� convolution sum LTI: FIR, IIR Frequency response M y [ n ] = � h [ k ] x [ n k ] convolution k= 0 x [ n ] = Ae j� e j�ˆn Complex exponential input �ˆ = �Ts M y [ n ] = � h [ k ] Ae j� e j�ˆ ( nk) k= 0 M � � j� j�ˆn j�ˆk = � h [ k ]e Ae e � k= 0 = H (�ˆ ) Ae j� e j�ˆn H (�ˆ ) frequency response let M H (�ˆ ) = � h[k]e j�ˆk k= 0 M y [ n] = � h [k ] x [n k ] convolution k= 0 x [ n ] = Ae j� e j�ˆn y [ n ] = H (�ˆ ) Ae e j� j�ˆn complex exponential input M H (�ˆ ) = � h[k ]e j�ˆk k= 0 frequency response complex j � +�H (�ˆ )) j�ˆn y [ n ] = H (�ˆ ) Ae ( e output same frequency as input, but amplitude scaled and a phase shift LTI: FIR & IIR � n x [n]� � �x n = � n 1 �[ ] [ ] �0 �1 0 � � � 0 � �2 �3 0 � � � 0 � y[ n ] = ? �4 �> 5 0 � system �y[n]� h[n] = y[n] x[ n ]=� [ n ]� 1/ 3 � � � � 0 � � � 1/ 3 � � � 0 � � � 1/ 3 � � � 0 � Ex. h[n] = 13 � [n] + 13 � [n 2] + 13 � [n 4 ] FIR y[n] = 13 x [n] + 13 x[n 2] + 13 x [n 4 ] 4 H (�ˆ ) = � h[k]e j�ˆ k k=0 = h[0]e j�ˆ 0 + h[2]e j�ˆ 2 + h[4]e j�ˆ 4 = 13 + 13 e j�ˆ 2 + 13 e j�ˆ 4 = 13 (1+ e j�ˆ 2 + e j 2�ˆ 4 ) = 13 e j�ˆ 2 (e j�ˆ 2 +1+ e j�ˆ 2 ) = 13 e j�ˆ 2 (1+ 2 cos 2�ˆ ) Also try by inspection if bk’s symmetric, then factor out e j�ˆ ( M /2) where M is the order of the filter. This leaves complex conjugate paired exponentials to transform into trigonometric functions (cosines/sines). H (�ˆ ) = 13 e j�ˆ 2 (1+ 2 cos 2�ˆ ) 1 H (�ˆ ) = 13 (1+ 2 cos 2�ˆ ) Note: H( ) =0 H( �) = 0 � 3 0.5 H (�ˆ ) 1 3 (1+ 2 cos 2�ˆ ) 0 zeros -0.5 -1 2 3 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 3 �H (�ˆ ) = 2�ˆ 2 linear phase �H (�ˆ ) = �H (�ˆ ) 1 �H (�ˆ ) 0 -1 -2 -3 �ˆ principal value of phase fn if not, add multiples of 2 � � < �H (�ˆ ) < � Want positive magnitudes, H (�ˆ ) � 0 so absorb negative sign into phase by adding an additional � at each zero H (�ˆ ) = 13 e j 2�ˆ (1+ 2 cos 2�ˆ ) 1 H (�ˆ ) = (1+ 2 cos 2�ˆ ) 1 3 Note: H ( �3 ) = 0 H( 2� 3 ) =0 H (�ˆ ) 1 3 band stop filter (1+ 2 cos 2�ˆ ) 0 zero -0.5 -1 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 3 �H (�ˆ ) = �2�ˆ � �2�ˆ � = � �2�ˆ + � ��2�ˆ + 2 � � 0.5 2 linear phase 0 � �ˆ < � 3 � 3 � �ˆ < 2 � 3 2 � / 3 � �ˆ < � phase odd function �H (�ˆ ) = �H (�ˆ ) principal value of phase fn � < �H (�ˆ ) < � 1 �H (�ˆ ) 0 -1 -2 -3 �ˆ Linear Phase delay of n0 sample periods y[n] = x [n n0 ] H (�ˆ ) = e j�ˆ n0 �H (�ˆ ) = n0�ˆ H (�ˆ ) = 1 FIR filters are linear phase if the coefficients are symmetric linear phase 3 y = sin(2 �� (t + nTs ) ) 2 higher frequencies need larger phase shifts than lower frequencies to achieve same time delay = sin(2 ��t + 2 ��nTs ) 1 0 -1 �H (�ˆ ) = �2�ˆ � �2�ˆ � = � �2�ˆ + � ��2�ˆ + 2 � � linear phase, 2 sample delay 0 � �ˆ < � 3 � 3 � �ˆ < 2 � 3 2 � / 3 � �ˆ < � -3 -2 -3 -2 = sin(2 ��t + � ) � = 2 �Ts n� -1 0 1 2 3 -1 0 1 2 3 3 2 �H (�ˆ ) 1 0 -1 -2 -3 �ˆ Linear Phase “It turns out that, within very generous tolerances, humans are insensitive to [audio] phase shifts. …”- Floyd E. Toole, PhD Vice President Acoustical Engineering Harman International Industries, Inc. “For data transmission, a nonlinear phase delay causes intersymbol interference which increases error rate, particulary if the signal-to­ noise ration is poor” - Digital Signal Processing in Communication Systems By Marvin E. Frerking “These are the pulse responses of each of the filters.The pulse response is nothing more than a positive going step response followed by a negative going step response. The pulse response is used here because it displays what happens to both the rising and falling edges in a signal. Here is the important part: zero and linear phase filters have left and right edges that look the same, while nonlinear phase filters have left and right edges that look different. Many applications cannot tolerate the left and right edges looking different. One example is the display of an oscilloscope, where this difference could be misinterpreted as a feature of the signal being measured. Another example is in video processing. Can you imagine turning on your TV to find the left ear of your favorite actor looking different from his right ear?” http://www.dspguide.com/ch19/4.htm FREQZ Z-transform digital filter frequency response. When N is an integer, [H,W] = FREQZ(B,A,N) returns the N-point frequency vector W in radians and the N-point complex frequency response vector H of the filter B/A: -1 -nb jw B(z) b(1) + b(2)z + .... + b(nb+1)z H(e) = ---- = ---------------------------­ -1 -na A(z) 1 + a(2)z + .... + a(na+1)z given numerator and denominator coefficients in vectors B and A. <snip> FREQZ(B,A,...) with no output arguments plots the magnitude and unwrapped phase of B/A in the current figure window. -1 H (�ˆ ) = 13 e2 j�ˆ (1+ 2 cos 2�ˆ ) = 13 + 13 e j�ˆ 2 + 13 e j�ˆ 4 z 1 = e j�ˆ + 13 z 2 + 13 z 4 H (�ˆ ) = 1 1 3 >> freqz([1/3,0,1/3,0,1/3],[1]) b(1) = 13 ,b(2) = 0,b(3) = 13 ,b(4) = 0,b(5) = 13 a(1) = 1 H (�ˆ ) = 13 e j 2�ˆ (1+ 2 cos 2�ˆ ) = 13 + 13 e j�ˆ 2 + 13 e j�ˆ 4 >> freqz([1/3,0,1/3,0,1/3],[1]) Bode Plot (frequency response curve, amp and phase) Magnitude Response (dB) 0 Magnitude response is plotted on a logarithmic scale. -10 -20 decibels (dB) = 20log10(|H|) -30 -40 -50 -60 TextEnd 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Normalized frequency (Nyquist == 1) 0.8 0.9 1 0.3 0.4 0.5 0.6 0.7 Normalized frequency (Nyquist == 1) 0.8 0.9 1 150 Phase (degrees) 100 50 0 -50 TextEnd -100 -150 0 0.1 0.2 Note: In this plot the normalized frequency goes � from DC to Nyquist (�= � ), so this is just one side. We normally plot from � -�< � < �. Remember: For real filter coefficients, magnitude is an even function; phase is an odd function Superposition and the frequency response x [ n ] = 3 + 3cos(0.6�n ) y[n] = 13 x [n] + 13 x[n 2] + 13 x [n 4 ] input FIR filter sample domain y[n] = 1+ cos(0.6 �n) +1+ cos(0.6 � (n 2)) +1+ cos(0.6 � (n 4 )) = 3+ cos(0.6 �n) + cos(0.6 �n) cos(1.2 � ) + sin(0.6 �n) sin(1.2 � ) + cos(0.6 �n) cos(2.4 � ) + sin(0.6 �n) sin( 2.4 � ) = 3+ [1+ cos(1.2 � ) + cos(2.4 � )] cos( 0.6 �n) + [sin(1.2 � ) + sin(2.4 � )] sin(0.6 �n ) = 3+ A cos(0.6 �n) + Bsin( 0.6 �n) = 3+ A 2 + B 2 cos(0.6 �n + tan 1 (B / A)) = 3+ 0.618 cos(0.6 �n 0.2 � ) frequency domain x [ n ] = 3 + 3cos(0.6�n ) closer �ˆ to a zero, the smaller the output. 3 2 H (�ˆ ) 1 0 -1 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 3 2 �H (�ˆ ) 1 0 -1 -2 -3 H (�ˆ ) = 1 3 (1+ 2 cos 2�ˆ ) �H (�ˆ ) = 2�ˆ + � �ˆ H (0) = 1 H (0.6 � ) = 0.206 �H (0) = 0 �H (2 � 0.6 � + � ) = 0.2 � y[n ] = 3(1) + 3(0.206) cos(0.6 �n 0.2 � ) = 3+ 0.618 cos(0.6 �n 0.2 � ) chirp 3 2 H (�ˆ ) 1 0 -1 -3 -2 -1 0 1 2 3 -3 -2 -1 0 1 2 3 3 2 �H (�ˆ ) 1 0 -1 -2 -3 �ˆ