MIT OpenCourseWare http://ocw.mit.edu 2.161 Signal Processing: Continuous and Discrete Fall 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.a f n g n f n b 0 y n 1 MASSACHUSETTS INSTITUTE OF TECHNOLOGY DEPARTMENT OF MECHANICAL ENGINEERING 2.161 Signal Processing - Continuous and Discrete Direct Form Digital Filter Structures 1 Linear shift-invariant digital filters can be represented in block diagram form in terms of the three primitive elements c o e f f i c i e n t ( g a i n ) u n i t d e l a y s u m m e r y n = a fn fn z - 1 y n = fn - 1 f n - y n = fn - gn In this handout we examine common structures for FIR and IIR filters, and give tutorial MATLAB functions to implement these structures. Transversal FIR Structure Let the FIR structure to be implemented be N H(z)= � bnz −k k=0 so that the difference equation is N yn = � bkfn−k. k=0 The following block diagram is the transversal form of this system: z z z z N 2 1 3 - 1 - 1 - 1 - 1 b b b bff f f n - 1 n - 2 n - 3 n - N The following MATLAB code implements this structure in a point-by-point filtering function: 1D. Rowell November 18, 2008 1% -------------------------------------------------------------------------% 2.161 Classroom Example - firdf - Demonstration FIR Direct Form % implementation. % Usage : 1) Initialization: % b=[123454321]; % y = iirdf1(’initial’, b); % where b are the numerator polynomial coefficients. Example: % y = iirdf1(’initial’,[1252 1]); % Note: firdf returnsy=0for initialization % 2) Filtering: % y_out = firdf(f); % where f is a single input value, and % y_out is the computed output value. % Example: To compute the step response: % for j=1:100 % y(j) = firdf(1); % end % -------------------------------------------------------------------------% function y_n = firdf(f_n,B) persistent f_register Bx N % % The following is initialization, and is executed once % if (ischar(f_n) && strcmp(f_n,’initial’)) N = length(B); Bx=B; f_register = zeros(1,N); y_n=0; else % Filtering: y_n=0; for J = N:-1:2 f_register(J) = f_register(J-1); y_n = y_n + Bx(J)*f_register(J); end y_n = y_n + Bx(1)*f_n; f_register(1) = f_n; end 2b 0 x yn f n 2 IIR Direct Form Structures Let the IIR structure to be implemented be �N k=0 bnz−k H(z)= �N1+ k=1 akz−k where it is assumed that the orders of the numerator and denominator of H(z) are equal. The difference equation is N N yn = − � akyn−k + � bkfn−k. k=1 k=0 Write H(z) as a pair of cascaded sub-systems, H(z)= H1(z)H2(z) where N −kH1(z)= � bnz , and H2(z)= �N 1 . k=0 1+ k=1 akz−k 2.1 Direct Form I Define an intermediate variable xn, and implement as X(z)= H1(z)F (z) and Y (z)= H2(z)X(z), or in difference equation form as N xn = � bkfn−k k=0 N yn = − � akyn−k + xn k=1 as shown below: z z z z z - 1 z z z a NN 1 2 1 2 33 y y yy n - 1 n - 2 n - 3 n - N n - - 1 - 1 - 1- 1 - 1 - 1 - 1 a a ab b b bff f f n - 1 n - 2 n - 3 n - N The following MATLAB code implements the Direct Form I structure in a point-by-point filtering function. 3% -------------------------------------------------------------------------% 2.161 Classroom Example - iirdf1 - Demonstration IIR Direct Form I % implementation. % Usage : 1) Initialization: % y = iirdf1(’initial’, b, a) % where b, a are the numerator and denominator polynomial % coefficients. Example: % [b,a] = butter(7,0.4); % y = iirdf1(’initial’,b,a); % Note: iirdf1 returnsy=0for initialization % 2) Filtering: % y_out = iirdf1(f_{in}; % where f_in is a single input value, and % y_out is the computed output value. % Example: To compute the step response: % for j=1:100 % y(j) = iirdf1(1); % end % -------------------------------------------------------------------------% function y_n = iirdf1(f_n,B,A) persistent f_register y_register Bx Ax N % % The following is initialization, and is executed once % if (ischar(f_n) && strcmp(f_n,’initial’)) N = length(A); Ax=A; Bx=B; f_register = zeros(1,N); y_register = zeros(1,N); y_n=0; else % Filtering: (Note that a Direct Form I filter needs two shift registers.) x=0;y=0; for J = N:-1:2 y_register(J) = y_register(J-1); % Move along the shift register f_register(J) = f_register(J-1); y=y-Ax(J)*y_register(J); x=x+ Bx(J)*f_register(J); end x=x+ Bx(1)*f_n; y_n=y+x; f_register(1) = f_n; y_register(1) = y_n; end 4f n n n x n - N x n - N 2.2 Direct Form II The Direct Form II structure results from reversing the order of H1(z) and H2(z) so that X(z)= H2(z)F (z) and Y (z)= H1(z)X(z), or in difference equation form as N xn = − � akfn−k k=1 N yn = � bkxn−k. k=0 as shown below: z- 1 zzza N12 3 - - 1 - 1 - 1 aaazzzz- 1- 1 - 1 - 1N2b13bbbn - 1n - 2xn - 3xxxn b0 yn f z- 1zzzaN1- 1- 1- 123- aaaNb2n - 1x13bbbn - 2 n - 3xxxn b0 y Notice that only a single delay register is required for the Direct Form II structure, as is shown on the right. The following MATLAB code on the following page implements the Direct Form II struc-ture in a point-by-point filtering function. 5% -------------------------------------------------------------------------% 2.161 Classroom Example - iirdf2 - Demonstration IIR Direct Form II % implementation. % Usage : 1) Initialization: % y = iirdf2(’initial’, b, a) % where b, a are the numerator and denominator polynomial % coefficients. Example: % [b,a] = butter(7,0.4); % y = iirdf2(’initial’,b,a); % Note: iirdf2 returnsy=0for initialization % 2) Filtering: % y_out = iirdf2(f_{in}; % where f_in is a single input value, and % y_out is the computed output value. % Example: To compute the step response: % for j=1:100 % y(j) = iirdf2(1); % end % -------------------------------------------------------------------------% function y_n = iirdf2(f_n,B,A) persistent register Bx Ax N % % The following is initialization, and is executed once % if (ischar(f_n) && strcmp(f_n,’initial’)) N = length(A); Ax=A; Bx=B; register = zeros(1,N); y_n=0; else % Filtering: (Note that a Direct Form II filter needs only a single % shift register.) x=0;y=0; for J = N:-1:2 register(J) =
View Full Document