Skip to content

Commit fafa0fc

Browse files
committed
add rfftfreq function
1 parent eeaee23 commit fafa0fc

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/fftpack.f90

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module fftpack
77
public :: zffti, zfftf, zfftb
88
public :: fft, ifft
99
public :: fftshift, ifftshift
10-
public :: fftfreq
10+
public :: fftfreq, rfftfreq
1111

1212
public :: dffti, dfftf, dfftb
1313
public :: rfft, irfft
@@ -181,6 +181,11 @@ pure module function fftfreq(n) result(out)
181181
integer, dimension(n) :: out
182182
end function fftfreq
183183

184+
pure module function rfftfreq(n) result(out)
185+
integer, intent(in) :: n
186+
integer, dimension(n) :: out
187+
end function rfftfreq
188+
184189
end interface
185190

186191
!> Version: experimental

src/fftpack_utils.f90

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,29 @@ pure module function fftfreq(n) result(out)
3232
end if
3333
end function fftfreq
3434

35+
!> Returns an integer array with the frequency values involved in the
36+
!> performed real FFT, ordered in the standard way (zero first, then
37+
!> positive frequencies, then, if applicable, the negative one).
38+
pure module function rfftfreq(n) result(out)
39+
integer, intent(in) :: n
40+
integer, dimension(n) :: out
41+
integer :: i
42+
43+
out(1) = 0
44+
if (n == 1) return
45+
46+
if (mod(n,2) == 0) then !> n even, smallest n = 2
47+
do i = 2, n-2, 2
48+
out(i) = out(i-1) + 1
49+
out(i+1) = out(i)
50+
end do
51+
out(n) = -n/2
52+
else !> n odd, smallest n = 3
53+
do i = 2, n-1, 2
54+
out(i) = out(i-1) + 1
55+
out(i+1) = out(i)
56+
end do
57+
end if
58+
end function rfftfreq
59+
3560
end submodule fftpack_utils

0 commit comments

Comments
 (0)