Skip to content

Instantly share code, notes, and snippets.

@linktohack
Created April 19, 2013 22:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linktohack/5423582 to your computer and use it in GitHub Desktop.
Save linktohack/5423582 to your computer and use it in GitHub Desktop.
Generate Frequency for FFT
function fftfreq(st, block)
implicit none
real*8, intent(in) :: st(:) ! sample time
integer, intent(in) :: block
real*8 :: fftfreq(size(st))
integer*4 :: n, i
real*8 :: t
n = size(st)
t = (st(n) - st(1))*block/(n - 1)
if (mod(block, 2) == 0) then
fftfreq = (/ (i, i=0, block/2-1), (i, i=-block/2, -1) /) / t
else
fftfreq = (/ (i, i=0, (block-1)/2), (i, i=(-block-1)/2, -1) /) / t
end if
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment