-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Storage sequence of rfft result? #44
Comments
When you use I tried to ask
Here is a simple example I wrote: program example
use fftpack
implicit none
real(rk) :: x(4) = [9, -9, 1, 3]
101 format(a, i2)
100 format(a, *(es9.2, :, ","))
print 101, "length : ", size(x)
print 100, "rfft : ", rfft(x)
print 100, "fft : ", fft(cmplx(x, kind=rk))
print 100, "fftshift: ", fftshift(fft(cmplx(x, kind=rk)))
print *, ""
print 101, "length : ", size(x) + 1
print 100, "rfft : ", rfft(x, 5)
print 100, "fft : ", fft(cmplx(x, kind=rk), 5)
print 100, "fftshift: ", fftshift(fft(cmplx(x, kind=rk), 5))
end program
! length : 4
! rfft : 4.00E+00, 8.00E+00, 1.20E+01, 1.60E+01
! fft : 4.00E+00, 0.00E+00, 8.00E+00, 1.20E+01, 1.60E+01, 0.00E+00, 8.00E+00,-1.20E+01
! fftshift: 1.60E+01, 0.00E+00, 8.00E+00,-1.20E+01, 4.00E+00, 0.00E+00, 8.00E+00, 1.20E+01
!
! length : 5
! rfft : 4.00E+00, 2.98E+00, 9.74E+00, 1.75E+01, 3.39E+00
! fft : 4.00E+00, 0.00E+00, 2.98E+00, 9.74E+00, 1.75E+01, 3.39E+00, 1.75E+01,-3.39E+00, 2.98E+00,-9.74E+00
! fftshift: 1.75E+01,-3.39E+00, 2.98E+00,-9.74E+00, 4.00E+00, 0.00E+00, 2.98E+00, 9.74E+00, 1.75E+01, 3.39E+00 As we can see from the example, I performed
|
Based on the above logic, I run the even real number sequence you gave me: program example
use fftpack
implicit none
integer m
integer, parameter :: N = 8
double precision, parameter :: two_pi = 2.D0*acos(-1.D0), tolerance = 1.0D-06, x_avg = 3.D0
double precision, parameter :: x(*) = x_avg + [(cos(two_pi*dble(m)/dble(N)), m=0, N - 1)]
double precision, allocatable, dimension(:) :: rfft_x, x_round_trip
double complex, allocatable :: x_hat(:)
101 format(a, i2)
100 format(a, *(es9.2, :, ","))
print 101, "length : ", size(x)
print 100, "rfft : ", rfft(x)
print 100, "fft : ", fft(cmplx(x, kind=rk))
print 100, "fftshift: ", fftshift(fft(cmplx(x, kind=rk)))
end program
! length : 8
! rfft : 2.40E+01, 4.00E+00,-2.22E-16, 0.00E+00,-0.00E+00, 0.00E+00,-2.22E-16, 0.00E+00
! fft : 2.40E+01, 0.00E+00, 4.00E+00,-2.22E-16, 0.00E+00, 0.00E+00, 0.00E+00,-4.44E-16, 0.00E+00, 0.00E+00, 0.00E+00, 2.22E-16, 0.00E+00, 0.00E+00, 4.00E+00, 4.44E-16
! fftshift: 0.00E+00, 0.00E+00, 0.00E+00, 2.22E-16, 0.00E+00, 0.00E+00, 4.00E+00, 4.44E-16, 2.40E+01, 0.00E+00, 4.00E+00,-2.22E-16, 0.00E+00, 0.00E+00, 0.00E+00,-4.44E-16 As can be seen from |
My confusion is twofold:
Instead, the |
PR #48 demonstrates how to compute the coefficients in comment 44 above. |
Could someone help me understand the storage sequence of the rfft function result and how to get the actual complex result from the forward FFT of a real data? I wrote the test program below to transform a 3 + cos(x). I'm unclear why the rfft result is real so I tried using
transfer
to get the correspondingcomplex
values. The result is close to what I'd expect but not quite.which gives the output
where I would have expected like
and a corresponding reordering of
rfft_x
.The text was updated successfully, but these errors were encountered: