-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetfgrid_CM.m
More file actions
36 lines (36 loc) · 1.61 KB
/
getfgrid_CM.m
File metadata and controls
36 lines (36 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function [f,findx]=getfgrid_CM(Fs,nfft,fpass)
%________________________________________________________________________________________________________________________
% Utilized in analysis by Kevin L. Turner
% The Pennsylvania State University, Dept. of Biomedical Engineering
% https://github.com/KL-Turner
%
% Code unchanged with the exception of this title block for record keeping
%
% Last Opened: February 23rd, 2019
%________________________________________________________________________________________________________________________
%
% 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);