home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts / signal / spectral_xdf.m < prev    next >
Text File  |  1999-03-26  |  2KB  |  67 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 = spectral_xdf (X, [win, [b]])
  18. ## 
  19. ## Returns the spectral density estimator.
  20. ## X ....... data vector
  21. ## win ..... window name, eg. "triangle" or "rectangle"
  22. ##           spectral_adf searches for a function called win_sw ()
  23. ## b ....... bandwidth
  24. ## 
  25. ## If win is omitted, the triangle window is used as default.
  26. ## If b is omitted, 1 / sqrt (length (X)) is used as default.
  27.   
  28. ## Author:  FL <Friedrich.Leisch@ci.tuwien.ac.at>
  29. ## Description:  Spectral density estimation
  30.   
  31. function retval = spectral_xdf (X, win, b)
  32.   
  33.   xr = length (X);
  34.   
  35.   if (columns (X) > 1)
  36.     X = X';
  37.   endif
  38.   
  39.   if (nargin < 3)
  40.     b = 1 / ceil (sqrt (xr));
  41.   endif
  42.   
  43.   if (nargin == 1)
  44.     w = triangle_sw (xr, b);
  45.   else
  46.     win = [win, "_sw"];
  47.     w = feval (win, xr, b);
  48.   endif
  49.   
  50.   X = X - sum (X) / xr;
  51.  
  52.   retval = (abs (fft (X)) / xr).^2;
  53.   retval = real (ifft (fft(retval) .* fft(w)));
  54.   
  55.   retval = [(zeros (xr, 1)), retval];
  56.   retval(:, 1) = (0 : xr-1)' / xr;
  57.   
  58. endfunction
  59.     
  60.  
  61.   
  62.  
  63.  
  64.  
  65.  
  66.  
  67.