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