home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 9.ddi / IDENT.DI$ / PREDICT.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.7 KB  |  56 lines

  1. function [yhat,thpred]=predict(z,theta,m)
  2. %PREDICT Computes the m-step ahead prediction
  3. %    
  4. %    YP = predict(Z,TH,M)
  5. %    
  6. %    Z : The output - input data for which the prediction is computed.
  7. %        Z = [Y U], where Y and U are column vectors (one column for each 
  8. %        output and input)
  9. %    TH: The model in the THETA format (see help theta)
  10. %    M : The prediction horizon. Old outputs up to time t-M are used to
  11. %        predict the output at time t. All relevant inputs are used.
  12. %        M = inf gives a pure simulation of the system.(Default M=1).
  13. %    YP: The resulting predicted output.
  14. %     With [YP,THPRED] = predict(Z,TH,M) the predictor is returned in the
  15. %    THETA format
  16. %    See also COMPARE
  17.  
  18. %    L. Ljung 10-1-89
  19. %    Copyright (c) 1989-90 by the MathWorks, Inc.
  20. %    All Rights Reserved.
  21.  
  22. if nargin<3, m=1;end
  23. if isempty(m), m=1;end
  24. if isthss(theta), eval('yhat=predicts(z,theta,m);')
  25. if nargout==2,disp('The predictor will not be returned for a theta-model that is defined via a state space model'),end,return,end
  26. [a,b,c,d,f]=th2poly(theta);
  27. nu=theta(1,3);
  28. T=gett(theta);
  29. if T<0,error('This is a continuous time model of input-output type. Please sample it (using thc2thd) before applying predict!'),end
  30.  
  31. if nu>0,ff=1;for ku=1:nu, 
  32. bt=b(ku,:);for kku=1:nu,if kku~=ku,bt=conv(bt,f(kku,:));end,end
  33. bb(ku,:)=bt;
  34. ff=conv(ff,f(ku,:));end
  35. a=conv(conv(a,ff),d);c=conv(c,ff);else a=conv(a,d);end
  36.  
  37.  
  38. na=length(a);nc=length(c);nn=max(na,nc);
  39. a=[a,zeros(1,nn-na)];c=[c,zeros(1,nn-nc)];
  40. [f,g]=deconv(conv([1 zeros(1,m-1)],c),a);
  41. ng=length(g);
  42.  
  43. if nu>0,
  44. df=conv(d,f);
  45.  
  46. for ku=1:nu
  47. bf(ku,:)=conv(bb(ku,:),df);
  48. end
  49. nbf=length(bf(1,:));nn=max(ng,nbf);
  50. gg=[[g,zeros(1,nn-ng)];[bf,zeros(nu,nn-nbf)]];
  51. else gg=g;end
  52. thpred=poly2th(c,gg);
  53. yhat=idsim(z,thpred);
  54.  
  55.