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].

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

Generated on Fri 28-Sep-2012 12:34:30 by