# getfgrid

## PURPOSE

Helper function that gets the frequency grid associated with a given fft based computation

## SYNOPSIS

function [f,findx]=getfgrid(Fs,nfft,fpass)

## DESCRIPTION

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

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- CrossSpecMat
- CrossSpecMatc Multi-taper cross-spectral matrix - another routine, allows for multiple trials and channels
- coherencyc Multi-taper coherency,cross-spectrum and individual spectra - continuous process
- coherencyc_unequal_length_trials This routine computes the average multi-taper coherence for a given set of unequal length segments. It is
- cohgramc Multi-taper time-frequency coherence,cross-spectrum and individual spectra - continuous processes
- cohmatrixc Multi-taper coherency,cross-spectral matrix - continuous process
- ftestc computes the F-statistic for sine wave in locally-white noise (continuous data).
- mtdspecgramc Multi-taper derivative of the time-frequency spectrum - continuous process
- mtdspectrumc Multi-taper frequency derivative of the spectrum - continuous process
- mtspecgramc Multi-taper time-frequency spectrum - continuous process
- mtspectrum_of_spectrumc Multi-taper segmented, second spectrum (spectrum of the log spectrum) for a continuous process
- mtspectrumc Multi-taper spectrum - continuous process
- mtspectrumc_unequal_length_trials This routine computes the multi-taper spectrum for a given set of unequal length segments. It is
- mtspectrumsegc Multi-taper segmented spectrum for a univariate continuous process
- spsvd Space frequency SVD of input data - continuous processes
- coherencycpb Multi-taper coherency,cross-spectrum and individual spectra - continuous and binned point process data
- coherencycpt Multi-taper coherency,cross-spectrum and individual spectra -continuous data and point process as times
- cohgramcpb Multi-taper time-frequency coherence,cross-spectrum and individual spectra
- cohgramcpt Multi-taper time-frequency coherence,cross-spectrum and individual spectra
- CrossSpecMatpb
- coherencypb Multi-taper coherency,cross-spectrum and individual spectra - binned point process
- cohgrampb Multi-taper time-frequency coherence,cross-spectrum and individual spectra - two binned point processes
- cohmatrixpb Multi-taper coherency matrix - binned point process
- mtdspecgrampb Multi-taper derivatives of time-frequency spectrum - binned point process
- mtdspectrumpb Multi-taper spectral derivative - binned point process
- mtspecgrampb Multi-taper time-frequency spectrum - binned point process
- mtspectrumpb Multi-taper spectrum - binned point process
- mtspectrumsegpb Multi-taper segmented spectrum for a univariate binned point process
- CrossSpecMatpt
- coherencypt Multi-taper coherency - point process times
- cohgrampt Multi-taper time-frequency coherence - two point processes given as times
- cohmatrixpt Multi-taper coherency matrix - point process times
- mtdspecgrampt Multi-taper derivative time-frequency spectrum - point process times
- mtdspectrumpt Multi-taper spectral derivative - point process times
- mtspecgrampt Multi-taper time-frequency spectrum - point process times
- mtspectrumpt Multi-taper spectrum - point process times
- mtspectrumsegpt Multi-taper segmented spectrum for a univariate binned point process
- mtspecgramc_fast Multi-taper time-frequency spectrum - continuous process
- mtspecgramc_slow Multi-taper time-frequency spectrum - continuous process

## SOURCE CODE

    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);