intel fortran调用FFTW,傅里叶正变换值为何显示N/2+1
intel fortran调用FFTW,real to complex。傅里叶正变换值为何只显示N/2+1数据,结果如下,怎样才能使得傅里叶变化的数据都显示出来呢?程序:
program test1d
implicit none
integer,parameter::N=5
double precision in(N)
double complex out(N)
double precision var1(N)
integer :: plan
integer :: i
integer,parameter :: fftw_estimate = 64
!
do i=1,N
in(i)=i
end do
call dfftw_plan_dft_r2c_1d(plan,N,in,out,FFTW_ESTIMATE) ! in ---> out1 means ifft
call dfftw_execute_dft_r2c(plan,in,out)
call dfftw_destroy_plan(plan)
call dfftw_plan_dft_c2r_1d(plan,N,out,var1,FFTW_ESTIMATE) ! out ---> var1-1 means fft
call dfftw_execute_dft_c2r(plan,out,var1)
call dfftw_destroy_plan(plan)
do i=1,N
! var1(i)=var1(i)/N
write(*,*) i, in(i), out(i)!,var1(i)
end do
end program test1d
计算结果:
11.000000000000 (15.000000000000, 0.000000000000000)
22.000000000000 (-2.5000000000000, 3.44095480117793)
33.000000000000 (-2.5000000000000, 0.812299240582266)
44.000000000000 (0.0000000000000, 0.000000000000000)
55.000000000000 (0.0000000000000, 0.000000000000000)
后面是共轭对称的呀。 vvt 发表于 2018-8-2 17:40
后面是共轭对称的呀。
就是2,3和4,5是共轭对称的?我用matlab验证了一下,好像是这样;我逆变换(ifft)后,也返回原值了。谢谢您。 是的。
{:5_121:} 您好,我算了一个4*4的数组,得到的结果和您类似,结果中也只显示了N/2+1的数据,N/2+1以后的数据都是0,通过对比matlab算的结果,发现偏差很大;
麻烦问一下,如果我要得到N/2+1以后的数据,应该怎么做呢??program main
USE globalvars
implicit none
include 'fftw3.f'
integer :: i,j
real,allocatable:: eta(:,:), input(:,:)
complex,allocatable :: etak(:,:), output(:,:)
allocate (eta(nx,ny), input(nx,ny))
allocate (etak(nx,ny), output(nx,ny))
eta = reshape([3,0,-1,0,&
-1,-2,1,1,&
-2,2,2,2,&
2,-1,4,3],shape(eta))
do i=1,nx
do j=1,ny
write(*,*) eta(j,i)
enddo
enddo
CALL sfftw_plan_dft_r2c_2d(p_up, nx, ny, input, output, FFTW_EXHAUSTIVE)
CALL sfftw_plan_dft_c2r_2d(p_dn, nx, ny, output, input, FFTW_EXHAUSTIVE)
call forward(eta,etak)
do i=1,nx
do j=1,ny
write(*,*) etak(j,i)
enddo
enddo
call backward(etak,eta)
do i=1,nx
do j=1,ny
write(*,*) eta(j,i)
enddo
enddo
deallocate (eta, input)
deallocate (etak, output)
end program
MODULE globalvars
IMPLICIT NONE
! Simulation cell parameters:
integer,parameter:: Nx = 4, Ny = 4
integer(kind = 8) :: p_up, p_dn
END MODULE globalvars
subroutine backward(output,input)
USE globalvars
!calculates backward fourier transform (complex to real) using FFTW
implicit none
COMPLEX, INTENT(IN) :: output(nx,ny)
REAL, INTENT(OUT) :: input(nx,ny)
COMPLEX :: tempk(nx,ny)
INTEGER :: i,j
REAL :: sizescale
sizescale = 1.0/FLOAT(nx * ny)
tempk = 0.0
DO j=1,ny
DO i=1,nx
tempk(i,j) = output(i,j)
END DO
END DO
CALL sfftw_execute_dft_c2r(p_dn,tempk,input)
DO j=1,ny
DO i=1,nx
input(i,j) = sizescale*input(i,j)
END DO
END DO
! RETURN
END subroutine backward
subroutine forward(input,output)
USE globalvars
!calculates forward fourier transform (real to complex) using FFTW
implicit none
real, intent(IN) :: input(nx,ny)
complex, intent(OUT) :: output(nx,ny)
call sfftw_execute_dft_r2c(p_up,input,output)
! RETURN
end subroutine forward
页:
[1]