home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / signal / spec_adf.m < prev    next >
Text File  |  1999-12-24  |  2KB  |  62 lines

  1. ## Copyright (C) 1995, 1996, 1997  Friedrich Leisch
  2. ## 
  3. ## This program is free software; you can redistribute it and/or modify
  4. ## it under the terms of the GNU General Public License as published by
  5. ## the Free Software Foundation; either version 2, or (at your option)
  6. ## any later version.
  7. ## 
  8. ## This program is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. ## General Public License for more details. 
  12. ## 
  13. ## You should have received a copy of the GNU General Public License
  14. ## along with this file.  If not, write to the Free Software Foundation,
  15. ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. ## usage:  retval = spec_adf (c, [win, [b]])
  18. ## 
  19. ## Returns the spectral density estimator.
  20. ## c ....... vector of autocovariances (starting at lag 0)
  21. ## win ..... window name, eg. "triangle" or "rectangle"
  22. ##           spec_adf searches for a function called win_lw ()
  23. ## b ....... bandwidth
  24. ## 
  25. ## If win is omitted, the triangle window is used as default.
  26. ## If b is omitted, 1 / sqrt( length (c)) is used as default.
  27.   
  28. ## Author:  FL <Friedrich.Leisch@ci.tuwien.ac.at>
  29. ## Description:  Spectral density estimation
  30.   
  31. function retval = spec_adf (c, win, b)
  32.   
  33.   cr = length (c);
  34.   
  35.   if (columns (c) > 1)
  36.     c=c';
  37.   endif
  38.  
  39.   if (nargin < 3)
  40.     b = 1 / ceil (sqrt (cr));
  41.   endif
  42.  
  43.   if (nargin == 1)
  44.     w = tri_lw (cr, b);
  45.   else
  46.     win = [win, "_lw"];
  47.     w = feval (win, cr, b);
  48.   endif
  49.       
  50.   c = c .* w;
  51.   
  52.   retval = 2 * real (fft (c)) - c(1);
  53.   retval = [(zeros (cr, 1)), retval];
  54.   retval(:, 1) = (0 : cr-1)' / cr;
  55.   
  56. endfunction
  57.     
  58.  
  59.   
  60.  
  61.  
  62.