Frequency Response of FIR Filters Chapter 6 This chapter continues the study of FIR filters from Chapter 5, but the emphasis is frequency response, which relates to how the filter responds to an input of the form xn e jˆ n n. A fundamental result we shall soon see, is that the frequency response and impulse response are related through an operation known as the Fourier transform. The Fourier transform itself is not however formally studied in this chapter. Sinusoidal Response of FIR Systems Consider an FIR filter when the input is a complex sinusoid of the form xn Ae j e jˆ n n, (6.1) where it could be that xn was obtained by sampling the complex sinusoid xt Ae j e j t and ˆ T s From the difference equation for an M + 1tap FIR filter, M yn b k xn k b k Ae j e jˆ n k k M k (6.) ECE 61 Signal and Systems 61
Sinusoidal Response of FIR Systems yn Ae j e jˆ n k b k e j ˆ k Ae j e jˆ n jˆ He n where we have defined for arbitrary ˆ M (6.3) He jˆ M b k e j k ˆ k (6.4) to be the frequency response of the FIR filter Note: The notation He jˆ is used rather than say Hˆ, to be consistent with the z-transform which will defined in Chapter 7, and to emphasize the fact that the frequency response is periodic, with period (more on this later) Note: e jˆ cosˆ + jsinˆ, where sine and cosine are both mod functions Returning to (6.), the implication is that when the input is a complex exponential at frequency ˆ, the output is also a complex exponential at frequency ˆ The complex amplitude (magnitude and phase) of the input is changed as a result of passing through the system The frequency response at ˆ multiplies the input amplitude to produce the output It is not true in general that yn He jˆ xn, but only for the special case of xn a complex sinusoid applied starting at ECE 61 Signals and Systems 6
Sinusoidal Response of FIR Systems The frequency response is a complex function of ˆ generally viewed in either polar or rectangular form that is He jˆ He jˆ e j H ejˆ (6.5) ReHe jˆ + jimhe jˆ The polar or magnitude and phase form is perhaps the most common The polar form offers the following interpretation of terms of xn, when the input is a complex sinusoid yn e j H ejˆ He jˆ Ae j H ejˆ He jˆ yn in (6.6) Here we see that the input amplitude is multiplied by the frequency response amplitude, and the input phase has added to it the frequency response phase The output amplitude expression means that is also termed the gain of an LTI system Ae j e jˆ n + jˆ n e He jˆ Example: 11311 b k The frequency response of this FIR filter is b k e jˆ k He jˆ 4 k 1 + e jˆ + 3e jˆ + e j3ˆ + e j4ˆ ECE 61 Signals and Systems 63
Sinusoidal Response of FIR Systems We have used the inverse Euler formula for cosine twice For this particular filter we have that Why? e jˆ He jˆ He jˆ e jˆ e jˆ e jˆ + + 3 + e jˆ + e jˆ cosˆ + cosˆ + 3 3 + cosˆ + cosˆ He jˆ ˆ Use MATLAB to plot the magnitude and phase response >> w :*pi/:*pi; >> H exp(-j**w).*(3 + *cos(w) + *cos(*w)); >> subplot(11) >> plot(w,abs(h)) >> axis([ *pi 8]) >> grid >> ylabel('magnitude') >> subplot(1) >> plot(w,angle(h)) >> axis([ *pi -pi pi]) >> grid >> ylabel('phase (rad)') ECE 61 Signals and Systems 64
Sinusoidal Response of FIR Systems >> xlabel('hat(\omega) (rad)') 8 Magnitude 6 4 3.48 Phase (rad) 1 3 4 5 6-1 3 4 5 6 hat(ω) (rad) Example: Find yn for Input The input frequency is the phase is xn 5e j1 n ˆ 1 rad, the amplitude is 5, and Assuming xn is input to the 4-tap FIR filter in the previous example, the filter output is yn 3 + cos1 + cos 1e j1 16.415e j e jn The amplitude response or gain at ˆ 1 is He j1 3.48; why? 5e j1 n ECE 61 Signals and Systems 65
Superposition and the Frequency Response Superposition and the Frequency Response We can use the linearity of the FIR filter to compute the output to a sum of sinusoids input signal As a special case we first consider a single real sinusoid xn Acosˆ n + (6.7) Using Euler s formula we expand (6.7) xn A -- e j ˆ n + (6.8) The filter output due to each complex sinusoid is known from (6.3), so now using superposition we can write yn (6.9) We can simplify this result to a nice compact form, if we make the assumption that the FIR filter has real coefficients Special Result: It will be shown in a later section of this chapter that an FIR filter with real coefficients has conjugate symmetry What does this mean? A A -- He jˆ j ˆ e n + He jˆ He jˆ A + -- e j ˆ n + ˆ + -- He j H* e jˆ e j ˆ n + ReHe jˆ jimhe jˆ He jˆ He jˆ (6.1) ECE 61 Signals and Systems 66
We now use (6.1) to simplify (6.9) yn A -- He jˆ j ˆ e n + A Superposition and the Frequency Response -- H* e jˆ j + e ˆ n + AH e jˆ e j ˆ n + + He jˆ e j ˆ n + +He jˆ ------------------------------------------------------------------------------------------------ + (6.11) yn AH e jˆ cosˆ n + + He jˆ We see that when a real sinusoid passes through an LTI system, such as an FIR filter (having real coefficients), the output is also a real sinusoid which has picked up the magnitude and phase of the system at ˆ ˆ The generalization (sum of sinusoids) of this result is when N xn X + X k cosˆ kn + X k, (6.1) k 1 then the corresponding LTI system output is yn X He j + N k 1 X k He jˆ k cos ˆ kn+ X k +He jˆ k (6.13) ECE 61 Signals and Systems 67
Superposition and the Frequency Response Example: Three Inputs with The input is The frequency response is The input frequencies are He j He j 4 He j 3 Thus b k 1 11 xn 1 4 --n + -- + cos + 3 --n -- 4 8 cos 3 4 1 e jˆ + e jˆ He jˆ e jˆ 1 + cosˆ >> w :pi/:pi; >> H 1 - exp(-j*w) + exp(-j**w); >> subplot(11) >> plot(w,abs(h)) >> grid >> hold >> plot([pi/4 pi/4],[ 3],'r') ˆ k 4 3 e j 1 + cos 1 e j 4 1 + cos 4.414e j 4 e j 3 1 + cos 3 yn 1 1 + 4.414 cos --n + -- -- 4 8 4 1 + 1.6569 cos --n -- 4 8 ECE 61 Signals and Systems 68
Superposition and the Frequency Response >> plot([pi/3 pi/3],[ 3],'r') >> ylabel('magnitude') >> subplot(1) >> plot(w,angle(h)) >> grid >> hold >> plot([pi/4 pi/4],[- 3],'r') >> ylabel('phase (rad)') >> xlabel('digital Frequency \omega') He jˆ 3.5 Magnitude 1.5 1.414.5.5 1 1.5.5 3 3.5 3 -- 4 -- 3 Phase (rad) 1 1 -- 4.5 1 1.5.5 3 3.5 Digital Frequency ω We have used frequency domain analysis to complete this example We could also perform a time domain analysis using say MATLAB s filter function (more on this in the next section) ECE 61 Signals and Systems 69
Steady-State and Transient Response Steady-State and Transient Response The frequency response definition relies on the fact that the support interval for the complex sinusoid input is In a computer simulation or in a real-time signal processing application, it is not practical to consider input signals which begin at Consider an input that begins at n using the unit step function to turn on the input where X Ae j xn un and Xe jˆ n un 1, n, otherwise (6.14) (6.15) For an LTI FIR system, the convolution sum formula yields M yn b k Xe jˆ n k un k k hk (6.16)... M un k n k k ECE 61 Signals and Systems 61
The sum of (6.16) is composed of three cases When yn n, n n b k e jˆ k jˆ Xe n, n M k M b k e jˆ k jˆ n Xe, n M k Steady-State and Transient Response the input is not present, so the output is zero (6.17) When n M the input has partially engaged the filter and the output produced is the transient response When n M, the output is in steady-state, since the input has fully engaged the filter Note that the steady-state response is also equivalent to saying yn He jˆ Xe jˆ (6.18) Note also that the steady-state output assumes that the input is always Xe jˆ n for n Example: Revisit Three Inputs with n M b k 1 11 The frequency domain analysis used in the previous example obtained just the steady-state portion of the output We can evaluate the convolution sum or use MATLAB s filter function to obtain a solution of the form described in (6.17) ECE 61 Signals and Systems 611
Steady-State and Transient Response >> n -5:; >> x (1 + 4*cos(pi/4*n+pi/8) +... 3*cos(pi/3*n-pi/4)).*ustep(n,); >> y filter([1-1 1],1,x); >> subplot(11) >> stem(n,x,'filled') >> grid >> ylabel('x[n]') >> subplot(1) >> stem(n,y,'filled') >> hold Current plot released >> stem(n,y,'filled') >> grid >> ylabel('y[n]') >> xlabel('sample Index n') 15 x[n] 1 5 5 5 1 15 15 Transient Interval y[n] 1 5 Steady-state 5 5 5 1 15 Sample Index n ECE 61 Signals and Systems 61
The function ustep() is defined as: Steady-State and Transient Response function x ustep(n,n) % function x ustep(n,n) % % Generate a time shifted unit step sequence x zeros(size(n)); i_n find(n > n); x(i_n) ones(size(i_n)); If we consider just the steady-state portion of the output we should be able to discern the same output as obtained from the frequency domain analysis of the previous example 1 11.5 1.6568 3.3138 11 1.5 y[n] 1 9.5 DC 1 y[n] peak lag 1/ sample /8 9 8.5 8 5 1 15 x[n] cos() peak Sample Index n The measurements above agree with the earlier example ECE 61 Signals and Systems 613
Properties of the Frequency Response Properties of the Frequency Response Relation to Impulse Response and Difference Equation In the definition of the frequency response, He jˆ, for an FIR filter, the coefficients were utilized Similarly given the frequency response, the impulse response can be found hn In Chapter 5 we saw that the impulse response and difference equation are directly related, so in summary given one the other two are easy to obtain Example: Given say M we immediately see that The difference equation is The frequency response is b k Time Domain Frequency Domain hk n k He jˆ hk e jˆ k hn k hn yn He jˆ He jˆ M k n + 3n 1 n 3 b k xn + 3xn 1 xn ˆ + 3e j e jˆ ECE 61 Signals and Systems 614
Properties of the Frequency Response Example: Difference Equation from Suppose that We immediately can write that and It could have been that started in this form Example: hn yn He jˆ He jˆ We need to convert the sine form back to complex exponentials The impulse response is thus? ˆ He jˆ 1+ 4e j + He jˆ 4e j4ˆ n + 4n + 4n 4 xn + 4xn + 4xn 4 1 8e jˆ ---------------------------- + + 1+ 8e jˆ cosˆ e jˆ j ˆ e jˆ sin je j ˆ He jˆ e jˆ 1 e jˆ e jˆ e jˆ --------------------------------- j ECE 61 Signals and Systems 615
Properties of the Frequency Response The difference equation is? Periodicity of He jˆ For any discrete-time LTI system, the frequency response is periodic, that is He j ˆ + He jˆ The proof for FIR filters follows He j ˆ M + b k e j ˆ + k M k b k e jˆ (6.19) (6.) This result is consistent with the fact that sinusoidal signals are insensitive to frequency shifts, i.e., In summary, the frequency response is unique on at most a interval, say in particular the interval ˆ Conjugate Symmetry The frequency response He jˆ is in general a complex quantity, in most cases obeys certain symmetry properties e j 1 He jˆ xn Xe j ˆ + n Xe jˆ n jn e Xe jˆ n ECE 61 Signals and Systems 616
Properties of the Frequency Response In particular if the coefficients of a digital filter are real, that * is b k b k or hk h * k, then proof Conjugate Symmetry: He jˆ H * e jˆ H * e jˆ b k e jˆ k * M * jˆ k b k e A consequence of conjugate symmetry is that (6.1) (6.) (6.3) We say that the magnitude response is an even function of ˆ and the phase is an odd function of ˆ It also follows that M k M k b k e j ˆ k k He jˆ When plotting the frequency response we can use the above symmetry to just plot over the interval ˆ He jˆ He jˆ He jˆ He j ˆ ReHe jˆ ReHe jˆ (6.4) ImHe jˆ ImHe jˆ We say that the real part response is an even function of ˆ and the imaginary part is an odd function of ˆ ECE 61 Signals and Systems 617
Graphical Representation of the Frequency Response Graphical Representation of the Frequency Response A useful MATLAB function for plotting the frequency response of any discrete-time (digital) filter is freqz() The interface to freqz() is similar to filter() in that a and b vectors are again required Recall that the b vector holds the FIR coefficients and for FIR filters we set a 1. >> help freqz FREQZ Digital filter frequency response. [H,W] FREQZ(B,A,N) returns the N-point complex frequency response vector H and the N-point frequency vector W in radians/sample of the filter: jw -jw -jmw jw B(e) b(1) + b()e +... + b(m+1)e H(e) ---- ------------------------------------ jw -jw -jnw A(e) a(1) + a()e +... + a(n+1)e given numerator and denominator coefficients in vectors B and A. The frequency response is evaluated at N points equally spaced around the upper half of the unit circle. If N isn't specified, it defaults to 51. [H,W] FREQZ(B,A,N,'whole') uses N points around the whole unit circle. H FREQZ(B,A,W) returns the frequency response at frequencies designated in vector W, in radians/sample (normally between and pi). [H,F] FREQZ(B,A,N,Fs) and [H,F] FREQZ(B,A,N,'whole',Fs) return frequency vector F (in Hz), where Fs is the sampling frequency (in Hz). H FREQZ(B,A,F,Fs) returns the complex frequency response at the frequencies designated in vector F (in Hz), where Fs is the sampling frequency (in Hz). FREQZ(B,A,...) with no output arguments plots the magnitude and unwrapped phase of the filter in the current figure window. See also filter, fft, invfreqz, fvtool, and freqs. b k ECE 61 Signals and Systems 618
Graphical Representation of the Frequency Response Example: Delay System yn xn n This filter contains one coefficient, b n 1, so He jˆ e jˆ n >> [H,w] freqz([ 1],1); >> subplot(11) >> plot(w,abs(h)) >> axis([ pi 1.]); grid >> ylabel('magniude Response') >> subplot(1) >> plot(w,angle(h)) >> axis([ pi -pi pi]); grid >> ylabel('phase Response (rad)') >> xlabel('hat(\omega)') 1 ˆ n Magnitude Response 1.5 Constant magnitude (gain) response n 4.5 1 1.5.5 3 Phase Response (rad) Linear Phase 4ˆ MATLAB wraps the phase mod.5 1 1.5.5 3 hat(ω) ECE 61 Signals and Systems 619
Graphical Representation of the Frequency Response Example: First-Difference System The frequency response is He jˆ yn xn xn 1 1 e jˆ 1 cosˆ + jsinˆ >> w -pi:pi/1:pi; >> H freqz([1-1],1,w); %use a custom w axis >> subplot(11) >> plot(w,abs(h)) >> axis([-pi pi ]); grid; ylabel('magniude Response') >> subplot(1) >> plot(w,angle(h)) >> axis([-pi pi - ]); grid; >> ylabel('phase Response (rad)') >> xlabel('hat(\omega)') Magnitude Response 1.5 1.5 sinˆ 3 1 1 3 Phase Response (rad) 1 1 atan sinˆ --------------------- 1 cosˆ 3 1 1 3 hat(ω) ECE 61 Signals and Systems 6
Graphical Representation of the Frequency Response Example: A Simple Lowpass Filter yn xn + xn 1 + xn The frequency response is He jˆ 1 e jˆ e jˆ >> w -pi:pi/1:pi; >> H freqz([1 1],1,w); >> subplot(11) >> plot(w,abs(h)) >> axis([-pi pi 4]); grid; >> ylabel('magnitude Response') >> subplot(1) >> plot(w,angle(h)) >> axis([-pi pi -pi pi]); grid; >> ylabel('phase Response (rad)') >> xlabel('hat(\omega)') + + e jˆ + cosˆ Magnitude Response 4 3 1 + cosˆ 3 1 1 3 Phase Response (rad) ˆ 3 1 1 3 hat(ω) ECE 61 Signals and Systems 61
Cascaded LTI Systems Cascaded LTI Systems Cascaded LTI system were discussed in Chapter 5 from the time-domain standpoint In the frequency-domain there is an alternative view of the input/output relationships To begin with consider again xn e jˆ n n With LTI #1 followed by LTI #, the output at frequency y 1 n H e jˆ H e jˆ H 1 e jˆ H 1 e jˆ e jˆ n e jˆ n (6.5) ˆ is (6.6) ECE 61 Signals and Systems 6
Cascaded LTI Systems With LTI # followed by LTI #1, the output at frequency y n H 1 e jˆ H 1 e jˆ H e jˆ H e jˆ e jˆ n e jˆ n is (6.7) Since H 1 e jˆ H e jˆ H e jˆ H 1 e jˆ, it follows that y 1 n y n, and we have established that the frequency response for a cascaded system is simply the product of the frequency responses ˆ H cascade e jˆ He jˆ H 1 e jˆ H e jˆ (6.8) We have also shown that a convolution in the time-domain is equivalent to a multiplication in the frequency-domain hn Example: Two System Cascade Consider Time Domain Frequency Domain h 1 n*h n H 1 e jˆ H e jˆ He jˆ H 1 e jˆ 1 + e jˆ H e jˆ 1+ e jˆ + The cascade frequency response is He jˆ e jˆ 1 + e jˆ 1+ e jˆ + 1 3e jˆ + + 3e jˆ + e jˆ e j3ˆ (6.9) ECE 61 Signals and Systems 63
Moving Average Filtering Given the cascade frequency response we can easily convert back to the impulse response of the cascade difference equation hn n + 3n 1+ 3n + n 3 and yn xn + 3xn 1 + 3xn + xn 3 Check h 1 n*h n Moving Average Filtering The moving average filter occurs frequency enough that we should consider finding a general expression for the frequency response The difference equation for an L-point averager is yn The frequency response is L 1 1 -- xn k L k (6.3) He jˆ L 1 1 -- e jˆ k L k (6.31) ECE 61 Signals and Systems 64
This sum is known as a finite geometric series It can be shown (discussed in class) that Moving Average Filtering L 1 k k 1 L -------------- 1, 1 L, 1 (why?) Apply (6.3) to (6.31) by setting e jˆ (6.3) He jˆ 1 -- 1 e jˆ L --------------------- L 1 e jˆ -- 1 e jˆ L e jˆ L e jˆ L --------------------------------------------------------------- L e jˆ e jˆ e jˆ -------------------------- sinˆ L jˆ L 1 e Lsinˆ (6.33) Notice that the phase response is composed of a linear term e jˆ L 1 and due to the sign changes of sinˆ L / Lsinˆ In MATLAB D L e jˆ diricˆ L -------------------------- sinˆ L Lsinˆ can be used for analyzing moving average filters ECE 61 Signals and Systems 65
Moving Average Filtering Plotting the Frequency Response The frequency response can be plotted most easily using MATLAB s freqz() function Consider a 1-point moving average >> w -pi:pi/5:pi; >> H freqz(ones(1,1)/1,1,w); >> subplot(11) >> plot(w,abs(h)) >> grid; axis([-pi pi 1]) >> ylabel('magnitude Response') >> subplot(1) >> plot(w,angle(h)) >> grid; axis([-pi pi -pi pi]) >> ylabel('phase Response (rad)') >> xlabel('hat(\omega)') Magnitude Response 1.5 L 1 3 1 1 3 4 3 -- 5 ----- 5 ˆ ----- 5 ----- L ----- 5 Phase Response (rad) e j4.5 ˆ on this segment 3 1 1 3 hat(ω) ECE 61 Signals and Systems 66
Filtering Sampled Continuous-Time Signals Filtering Sampled Continuous-Time Signals Consider the system model as shown below Suppose that xt t Xe jt We know that after sampling we have (6.34) xn xnt s Xe jnt s Xe jˆ n (6.35) The key relationship to connect the continuous-time and the discrete-time quantities is ˆ T s -- f f ˆ ---- ˆ f s T s ----------- ˆ T s (6.36) As long as the input analog frequency satisfies the sampling theorem, i.e., T s or f f s, the output of the discrete-time system will be f s ----- ˆ f s ECE 61 Signals and Systems 67
Filtering Sampled Continuous-Time Signals yn He jˆ Xe jˆ n (6.37) We can write yn in terms of the analog frequency variable via ˆ T s yn He jt s Xe jt sn (6.38) At the output of the D-to-C converter we have the reconstructed output yt He jt s Xe jt He jf f s Xe j f f st (6.39) where f is the input analog sinusoid frequency (perhaps a better notation would be f ˆ ) Example: Lowpass Averager Consider a 5-point moving average filter wrapped up between a C-to-D and D-to-C system We assume a sampling rate of 1 Hz and an input composed of two sinusoids xt cos1t+ 3cos3t Find the system frequency response in terms of the analog frequency variable f, and find the steady-state output yt We will use freqz() to obtain the frequency response >> w -pi:pi/1:pi; >> H freqz(ones(1,5)/5,1,w); >> subplot(11) ECE 61 Signals and Systems 68
Filtering Sampled Continuous-Time Signals >> plot(w,abs(h)) >> axis([-pi pi 1]); grid >> ylabel('magnitude Response') >> subplot(1) >> plot(w,angle(h)) >> axis([-pi pi -pi pi]); grid >> ylabel('phase Response (rad)') >> xlabel('hat(\omega)') Magnitude Response 1.5 Magnitude and Phase Plots of He jˆ 3 1 1 3 Phase Response (rad) 3 1 1 3 hat(ω) >> subplot(11) >> plot(w*1/(*pi),abs(h)) >> grid >> ylabel('magnitude Response') >> subplot(1) >> plot(w*1/(*pi),angle(h)) >> grid >> ylabel('phase Response (rad)') >> xlabel('f (Hz)') ECE 61 Signals and Systems 69
Filtering Sampled Continuous-Time Signals Magnitude Response 1.5 Magnitude and Phase Plots of He jf f s 5 4 3 1 1 3 4 5 Phase Response (rad) 4 4 5 4 3 1 1 3 4 5 f (Hz) The output yt will be of the same form as the input xt, except the sinusoids at 1 and 3 Hz need to have the filter frequency response applied Note 1 Hz and 3 Hz < 1/ 5 Hz (no aliasing) To properly apply the filter frequency response we need to convert the analog frequencies to the corresponding discretetime frequencies 1Hz ----------- 1 1.1. 3Hz ----------- 3 1.3.6 (6.4) ECE 61 Signals and Systems 63
The frequency response for average filter is Filtering Sampled Continuous-Time Signals in the general moving The frequency response at these two frequencies is He j. He j.6 (6.41) sin.5. --------------------------------------e j..647e j.4 5sin. (6.4) sin.5.6 --------------------------------------e j.6.47e j1. 5sin.6 >> diric(.*pi,5) ans.647 He jˆ >> diric(.6*pi,5) L 5 sin.5ˆ 5 --------------------------e jˆ sinˆ.47e j. ans -.47 % also.47 at angle +/- pi The filter output yn is yn.647cos.n.4 +.7416cos.n 1. + and the D-to-C output is yt.647cos1t.4 +.7416cos3t. (6.43) (6.44) ECE 61 Signals and Systems 631
Filtering Sampled Continuous-Time Signals Interpretation of Delay In the study of the moving average filter, it was noted that where D L e jˆ He jˆ The pure delay system has impulse response and has frequency response D L e jˆ e jˆ L 1 is a purely real function yn xn n hn n n e jn ˆ He jˆ We also know that the impulse response of two systems in cascade is hn He jˆ h 1 n*h n The L-point moving average filter thus incorporates a delay of L 1 samples Viewed as a cascade of subsystems He jˆ If L is odd then the delay is an integer H 1 e jˆ H e jˆ D L e jˆ e jˆ L 1 If L is even then the delay is an odd half integer (6.45) ECE 61 Signals and Systems 63