/branches/R2-1-x/octave-forge/main/irsa/irsa_dftfp.m

# · MATLAB · 86 lines · 79 code · 7 blank · 0 comment · 10 complexity · e6989ca06a988f1d59b4dc063601616b MD5 · raw file

  1. ## Copyright (C) 2003 Joerg Huber
  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 of the License, or
  6. ## (at your option) any later version.
  7. ##
  8. ## This program is distributed in the hope that it will be useful,
  9. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ## GNU General Public License for more details.
  12. ##
  13. ## You should have received a copy of the GNU General Public License
  14. ## along with this program; if not, write to the Free Software
  15. ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. ## -*- texinfo -*-
  17. ## @deftypefn {Function File} {irsa_dftfp.m}
  18. ## [@var{fxp},@var{Nf},@var{fxps},@var{Nfe}] = irsa_dft (@var{xp},
  19. ## [@var{hifac}], [@var{ofac}])
  20. ##
  21. ## Compute frequency points for the Discrete Fourier Transformations of
  22. ## irregular sampled time series
  23. ##
  24. ## Input:
  25. ##
  26. ## @var{xp} : Columnvector -- sampling points
  27. ##
  28. ## @var{hifac}: Scalar -- factor for the amount of higher frequencies
  29. ##
  30. ## @var{ofac} : Scalar -- factor for the oversampling rate
  31. ##
  32. ## Output:
  33. ##
  34. ## @var{fxp} : Columnvector -- frequency points corresponding to the
  35. ## order the DFT or FFT are assuming.
  36. ##
  37. ## @var{Nf} : Scalar -- length of fxp (only a convenience)
  38. ##
  39. ## @var{fxps} : Columnvector -- frequency points in ascending order
  40. ##
  41. ## @var{Nfe} : Scalar -- true (1) if Nf is even or false (0) if not.
  42. ##
  43. ## Notice: @var{fxps} and @var{Nfe} are convenient for example for plotting
  44. ## spectra: There you may need the frequency series in a sorted order
  45. ## and you get it with @code{[fxps, shift(fyp, floor(Nf/2) - Nfe)]}
  46. ## @end deftypefn
  47. ## TODO: Look for a better estimation of the highest frequency, because
  48. ## the current limit is much to high in most cases.
  49. function [fxp, Nf, fxps, Nfe] = irsa_dftfp (xp, hifac, ofac )
  50. if( nargin < 1 || nargin > 3 )
  51. usage( "[fxp, fxps, Nf, Nfe ] = irsa_dftfp (xp, [hifac], [ofac])" );
  52. endif
  53. if( nargin < 3 || isempty( ofac ) )
  54. ofac = 1;
  55. endif
  56. if( nargin < 2 || isempty( hifac ) );
  57. hifac = 1;
  58. endif
  59. N = length(xp);
  60. Tmean = (xp(N) - xp(1)) / (N-1);
  61. Df = 1 / ( Tmean*N*ofac );
  62. if( hifac == 0 )
  63. ## Take the smallest time intervall to compute the highest frequency
  64. ## taken into account.
  65. fhighest = 1 / ( min( diff( xp ) ) * N * ofac );
  66. hifac = (fhighest/Df);
  67. endif
  68. Nf = ceil(ofac*hifac*N);
  69. lastnu = floor(Nf/2);
  70. Nfe = fmod(Nf/2+1,1);
  71. pfxp = [0:Df:lastnu*Df].';
  72. nfxp = flipud(-pfxp(2:Nf-lastnu));
  73. fxp = [pfxp;nfxp];
  74. fxps = [nfxp;pfxp];
  75. endfunction
  76. ### Local Variables:
  77. ### mode: octave
  78. ### End: