home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 8.ddi / SIGNAL.DI$ / FILTIC.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.2 KB  |  34 lines

  1. function vinit = filtic( b, a, ypast, xpast )
  2. %FILTIC    Make initial conditions for filter() function.
  3. %   V = filtic( B, A, Y, X )
  4. %      converts past values of x[n] & y[n] into initial conditions
  5. %       for the state variables v_i[n] needed in the
  6. %       TRANSPOSED DIRECT FORM II filter structure.
  7. %   V = filtic( B, A, Y ) assumes that x[n] = 0 in the past.
  8. %      The vector of past inputs & outputs stored as:
  9. %          xpast = [ x[-1] x[-2] x[-3] ... x[-nb] ]
  10. %          ypast = [ y[-1] y[-2] y[-3] ... y[-na] ]
  11. %    NOTE: if not enough past values are given, then
  12. %          zeropad x[n] or y[n] as needed.
  13. %
  14. if nargin == 3
  15.    xpast = [0];   % this is the zero input condition
  16. end
  17. na = length(a);   nb = length(b);
  18. m = max([na nb]) - 1;
  19. if( m < 1 )
  20.    vinit = [];  return
  21. end
  22. Lx = length(xpast);   Ly = length(ypast);
  23. if( Lx < (nb-1) ),   xpast(nb-1) = 0;    end   %--- zero pad
  24. if( Ly < (na-1) ),   ypast(na-1) = 0;    end
  25. vinit = zeros(1,m);  vx = vinit;
  26. % --- use filter() to do convolution
  27. if( na-1 > 0 )
  28.   vinit((na-1):-1:1) = filter( -a(na:-1:2)/a(1), 1, ypast(1:(na-1)) );
  29. end
  30. if( nb-1 > 0 )
  31.   vx((nb-1):-1:1) = filter( b(nb:-1:2)/a(1), 1, xpast(1:(nb-1)) );
  32. end
  33. vinit = vinit + vx;
  34.