getfgrid.m 1.1 KB

1234567891011121314151617181920212223242526
  1. function [f,findx]=getfgrid(Fs,nfft,fpass)
  2. % Helper function that gets the frequency grid associated with a given fft based computation
  3. % Called by spectral estimation routines to generate the frequency axes
  4. % Usage: [f,findx]=getfgrid(Fs,nfft,fpass)
  5. % Inputs:
  6. % Fs (sampling frequency associated with the data)-required
  7. % nfft (number of points in fft)-required
  8. % fpass (band of frequencies at which the fft is being calculated [fmin fmax] in Hz)-required
  9. % Outputs:
  10. % f (frequencies)
  11. % findx (index of the frequencies in the full frequency grid). e.g.: If
  12. % Fs=1000, and nfft=1048, an fft calculation generates 512 frequencies
  13. % between 0 and 500 (i.e. Fs/2) Hz. Now if fpass=[0 100], findx will
  14. % contain the indices in the frequency grid corresponding to frequencies <
  15. % 100 Hz. In the case fpass=[0 500], findx=[1 512].
  16. if nargin < 3; error('Need all arguments'); end;
  17. df=Fs/nfft;
  18. f=0:df:Fs; % all possible frequencies
  19. f=f(1:nfft);
  20. if length(fpass)~=1;
  21. findx=find(f>=fpass(1) & f<=fpass(end));
  22. else
  23. [fmin,findx]=min(abs(f-fpass));
  24. clear fmin
  25. end;
  26. f=f(findx);