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

  1. echo on
  2. clc
  3. %    The command SEGMENT segments data that are generated from
  4. %    systems that may undergo abrupt changes. Typical applications
  5. %    for data segmentation are segmentation of speech signals (each
  6. %    segment corresponds to a phonem), failure detection (the segments
  7. %    correspond to operation with and without failures) and estimating
  8. %    different working modes of a system.  We shall study a system
  9. %    whose time delay changes from two to one.
  10.  
  11. load iddemo6m.mat
  12.  
  13. %    First, take a look at the data:
  14.  
  15. clf reset
  16. pause, idplot(z), pause   % Press any key for plot.
  17. clc
  18. %    The change takes place at sample number 20, but this is not
  19. %    so easy to see.
  20. %
  21. %    We would like to estimate the system as an ARX-structure model
  22. %    with one a-parameter, two b-parameters and one delay:
  23.  
  24. %    y(t) + a*y(t-1) = b1*u(t-1) + b2*u(t-2)
  25.  
  26. %    The information to be given is the data, the model orders
  27. %    and a guess of the variance (r2) of the noise that affects
  28. %    the system. If this is entirely unknown, it may be estimated
  29. %    automatically: 
  30.  
  31. nn = [1 2 1];
  32. seg = segment(z,nn);
  33.  
  34. pause % Press any key to continue.
  35. clc
  36. %    Let's take a look at the segmented model. Solid/red line
  37. %    is for the a-parameter. Dashed/green is for b1 and dotted/blue
  38. %    for the parameter b2. 
  39.  
  40. pause, plot(seg), pause     % Press any key for plot.
  41. hold on
  42. clc
  43. %     We see clearly the jump at sample number 20. b1 goes from
  44. %    0 to 1 and b2 vice versa, which shows the change of the
  45. %    delay. The true values can also be shown:
  46.  
  47. pause, plot(pars), pause   % Press any key for plot.
  48. hold off
  49. clc
  50. %    It is usually better to provide a guess of the variance r2
  51. %    than to estimate it, and the rule of thumb is that it is
  52. %    better to overestimate it than to underestimate it. Assuming
  53. %    that the variance r2 is 0.1 gives
  54.  
  55. [seg,v,tvmod] = segment(z,[1 2 1],0.1);
  56.  
  57. pause % Press any key for plot.
  58. plot(seg), hold on, plot(pars), hold off, pause
  59. clc
  60. %    The method for segmentation is based on AFMM (adaptive
  61. %    forgetting through multiple models), Andersson, Int. J.
  62. %    Control Nov 1985.  A multi-model approach is used in a first
  63. %    step to track the time varying system. The resulting tracking
  64. %    model could be of interest in its own right, and are given by
  65. %    the third output argument of SEGMENT (tvmod in our case). They
  66. %    look as follows:
  67.  
  68. pause, plot(tvmod), pause     % Press any key for plot.
  69. clc
  70. %    The SEGMENT M-file is thus an alternative to the recursive
  71. %    algorithms RPEM, RARX etc for tracking time varying systems.
  72. %    It is particularily suited for systems that may change rapidly.
  73.  
  74. %    From the tracking model, SEGMENT estimates the time points when
  75. %    jumps have occured, and constructs the segmented model by a
  76. %    smoothing procedure over the tracking model.
  77.  
  78. %    The two most important "knobs" for the algorithm are r2, as
  79. %    mentioned before, and the guessed probability of jumps, q, the
  80. %    fourth input argument to SEGMENT.  The smaller r2 and the larger
  81. %    q, the more willing SEGMENT will be to indicate segmentation
  82. %    points. In an off line situation, the user will have to try a
  83. %    couple of choices (r2 is usually more sensitive than q). The
  84. %    second output argument to SEGMENT, v, is the loss function for
  85. %    the segmented model (i.e. the estimated prediction error variance
  86. %    for the segmented model). A goal will be to minimize this value.
  87.  
  88. pause    % Press any key to continue.
  89. clc
  90. %    OBJECT DETECTION IN LASER RANGE DATA
  91. %
  92. %    The reflected signal from a laser (or radar) beam contains
  93. %    information about the distance to the reflecting object. The
  94. %    signals can be quite noisy.  The presence of objects affects
  95. %    both the distance information and the correlation between
  96. %    neighbouring points. (A smooth object increases the 
  97. %    correlation between nearby points.)
  98. %
  99. %    In the following we study some quite noisy laser range data.
  100. %    They are obtained by one horisontal sweep, like one line on
  101. %    a TV-screen. The value is the distance to the reflecting object.
  102. %    We happen to know that an object of interest hides between
  103. %    sample numbers 17 and 48. 
  104.  
  105. pause, plot(hline), pause   % Press any key for plot.
  106. clc
  107. %    The eye is not good at detecting the object. We shall use
  108. %    "segment".  First we detrend and normalize the data to a
  109. %    variance about one. (This is not necessary, but it means that
  110. %    the default choices in the algorithm are better tuned.)
  111.  
  112. hline = dtrend(hline)/200;
  113.  
  114. %    We shall now build a model of the kind:
  115. %
  116. %       y(t) + a y(t-1) = b
  117. %
  118. %    The coefficient 'a' will pick up correlation information.  The
  119. %    value 'b' takes up the possible changes in level. We thus
  120. %    introduce a fake input of all ones:
  121.  
  122.  
  123. [m,n]=size(hline);
  124. zline = [hline ones(m,n)];
  125. s = segment(zline,[1 1 1],0.2);
  126.  
  127. pause    % Press any key to check segmentation.
  128. subplot(211),plot(hline),title('LASER RANGE DATA')
  129. subplot(212),plot(s)
  130. title('SEGMENTED MODELS, solid/red: correlation, dashed/green: distance'),pause
  131. clc
  132. %    The segmentation has thus been quite successful.
  133.  
  134. %    SEGMENT is capable of handling multi-input systems, and of using
  135. %    ARMAX models for the added noise.  We may try this on the test
  136. %    data iddata1.mat (which contains no jumps):
  137.  
  138. load iddata1.mat
  139. s = segment(z1(1:100,:),[2 2 2 1],1);
  140. clf reset
  141. pause, plot(s),hold on, pause  % Press any key for plot.
  142. clc
  143. %    Compare this with the true values: 
  144.  
  145. pause    % Press any key for plot.
  146. plot([ ones(100,1)*[-1.5 0.7],ones(100,1)*[1 0.5],ones(100,1)*[-1 0.2]]),pause
  147. hold off
  148. clc
  149.  
  150. %    SEGMENT thus correctly finds that no jumps have occured, and
  151. %    also gives good estimates of the parameters.
  152.  
  153. pause    % Press any key to continue.
  154.  
  155. set(gcf,'NextPlot','replace');
  156.  
  157.