Fortran Coder

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

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

[复制链接]

2

帖子

1

主题

0

精华

新人

F 币
23 元
贡献
10 点
跳转到指定楼层
楼主
发表于 2018-8-2 17:11:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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 ---> out  1 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

计算结果:
1  1.000000000000   (15.000000000000, 0.000000000000000)
2  2.000000000000   (-2.5000000000000, 3.44095480117793)
3  3.000000000000   (-2.5000000000000, 0.812299240582266)
4  4.000000000000   (0.0000000000000, 0.000000000000000)
5  5.000000000000   (0.0000000000000, 0.000000000000000)
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

955

帖子

0

主题

0

精华

大师

F 币
188 元
贡献
77 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
沙发
发表于 2018-8-2 17:40:33 | 只看该作者
后面是共轭对称的呀。

2

帖子

1

主题

0

精华

新人

F 币
23 元
贡献
10 点
板凳
 楼主| 发表于 2018-8-2 17:59:41 | 只看该作者
vvt 发表于 2018-8-2 17:40
后面是共轭对称的呀。

就是2,3和4,5是共轭对称的?我用matlab验证了一下,好像是这样;我逆变换(ifft)后,也返回原值了。谢谢您。

955

帖子

0

主题

0

精华

大师

F 币
188 元
贡献
77 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
地板
发表于 2018-8-2 18:23:08 | 只看该作者
是的。
回复

使用道具 举报

6

帖子

2

主题

0

精华

入门

F 币
52 元
贡献
23 点
5#
发表于 2019-11-20 11:11:45 | 只看该作者
您好,我算了一个4*4的数组,得到的结果和您类似,结果中也只显示了N/2+1的数据,N/2+1以后的数据都是0,通过对比matlab算的结果,发现偏差很大;
麻烦问一下,如果我要得到N/2+1以后的数据,应该怎么做呢??
[Fortran] 纯文本查看 复制代码
001program main
002 
003USE globalvars
004 
005  implicit none
006   
007  include 'fftw3.f'
008 
009  integer :: i,j
010  real,allocatable  :: eta(:,:), input(:,:)
011  complex,allocatable :: etak(:,:), output(:,:)
012   
013  allocate (eta(nx,ny), input(nx,ny))
014  allocate (etak(nx,ny), output(nx,ny))
015   
016  eta = reshape([3,0,-1,0,&
017           -1,-2,1,1,&
018           -2,2,2,2,&
019           2,-1,4,3],shape(eta))
020   
021  do i=1,nx
022    do j=1,ny
023     
024      write(*,*) eta(j,i)
025     
026    enddo
027 
028  enddo
029 
030  CALL sfftw_plan_dft_r2c_2d(p_up, nx, ny, input, output, FFTW_EXHAUSTIVE)
031  CALL sfftw_plan_dft_c2r_2d(p_dn, nx, ny, output, input, FFTW_EXHAUSTIVE)
032   
033  call forward(eta,etak)
034   
035  do i=1,nx
036    do j=1,ny
037     
038      write(*,*) etak(j,i)
039     
040    enddo
041 
042  enddo
043   
044  call backward(etak,eta)
045   
046  do i=1,nx
047    do j=1,ny
048     
049      write(*,*) eta(j,i)
050     
051    enddo
052 
053  enddo
054   
055  deallocate (eta, input)
056  deallocate (etak, output)
057 
058 end program
059 
060 
061 
062MODULE globalvars
063 
064IMPLICIT NONE
065 
066! Simulation cell parameters:
067  integer,parameter:: Nx = 4, Ny = 4
068  integer(kind = 8) :: p_up, p_dn
069      
070END MODULE globalvars
071 
072 
073subroutine backward(output,input)
074 
075USE globalvars
076!calculates backward fourier transform (complex to real) using FFTW
077  implicit none
078   
079  COMPLEX, INTENT(IN) :: output(nx,ny)
080  REAL, INTENT(OUT)   :: input(nx,ny)
081  COMPLEX :: tempk(nx,ny)
082  INTEGER :: i,j
083  REAL :: sizescale
084 
085  sizescale = 1.0/FLOAT(nx * ny)
086  tempk = 0.0
087  DO j=1,ny
088    DO i=1,nx
089      tempk(i,j) = output(i,j)
090    END DO
091  END DO
092 
093  CALL sfftw_execute_dft_c2r(p_dn,tempk,input)
094  DO j=1,ny
095    DO i=1,nx
096      input(i,j) = sizescale*input(i,j)
097    END DO
098  END DO
099! RETURN
100END subroutine backward
101 
102 
103subroutine forward(input,output)
104 
105USE globalvars
106!calculates forward fourier transform (real to complex) using FFTW
107  implicit none
108   
109  real, intent(IN) :: input(nx,ny)
110  complex, intent(OUT) :: output(nx,ny)
111 
112  call sfftw_execute_dft_r2c(p_up,input,output)
113! RETURN
114end subroutine forward
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2025-5-3 12:56

Powered by Discuz! X3.4

© 2013-2025 Comsenz Inc.

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