Fortran Coder

查看: 7172|回复: 4
打印 上一主题 下一主题

[数学库] intel fortran调用FFTW,傅里叶正变换值为何显示N/2+1

[复制链接]

6

帖子

2

主题

0

精华

入门

F 币
52 元
贡献
23 点
楼主
发表于 2019-11-20 11:11:45 | 显示全部楼层
您好,我算了一个4*4的数组,得到的结果和您类似,结果中也只显示了N/2+1的数据,N/2+1以后的数据都是0,通过对比matlab算的结果,发现偏差很大;
麻烦问一下,如果我要得到N/2+1以后的数据,应该怎么做呢??
[Fortran] 纯文本查看 复制代码
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
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-3 17:52

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表