【发布时间】:2015-04-04 06:05:43
【问题描述】:
我在 Fortran 90 中使用 FFTPACK5.1 时遇到问题,它包含计算离散傅立叶变换的子例程。我设法安装它并使用例程,但是当我检查频率是否为 A 的简单正弦波是否一切正常时,我得到一个不在 A 处的非零系数(在频率空间中,在光谱),但在 2A。频谱发生了变化,我不明白为什么。我几乎可以肯定(但我有疑问)我正确计算了频率轴步长:
N 是原始正弦波的点数,Fech 是我的采样频率,我将频率轴步长计算为 df(i)=Fech(i-1)/N。
我正在使用 rfft1f 例程,所以如果有人对此有经验并且知道我的问题,我将非常高兴了解这里的问题所在。
这是我的代码:
! n: number of samples in the discret signal
integer ( kind = 4 ), parameter :: n = 4096
real, parameter :: deuxpi=6.283185307
!frequence is the frequence of the signal
!fech is the frequence of sampling
real :: frequence,fech
integer :: kk
! r is the signal i want to process
! t is the built time and f is the built frequency
real ( kind = 4 ) r(n),t(n),f(n)
!Arrays routines need to work (internal recipe):
real ( kind = 4 ), allocatable, dimension ( : ) :: work
real ( kind = 4 ), allocatable, dimension ( : ) :: wsave
!size of arrays wsave and work for internal recipe
lensav = n + int ( log ( real ( n, kind = 4 ) ) / log ( 2.0E+00 ) ) + 4
lenwrk = n
allocate ( work(1:lenwrk) )
allocate ( wsave(1:lensav) )
! initializes rttft1f, wsave array
call rfft1i ( n, wsave, lensav, ier )
frequence=0.5
fech=20
! I built here the signal
do kk=1,n
t (kk) = (kk-1) / (fech)
f (kk) = fech*(kk-1) / n
r (kk) = sin( deuxpi * t(kk) * frequence )
end do
!and I call the rfft1f to build the Discrete Fourier Transform:
call rfft1f ( n, inc, r, lenr, wsave, lensav, work, lenwrk, ier )
!I get back r which contains now the fourier coefficients and plot it
我期望一个简单的正弦波在频率为 0.5(cf 代码)处有一个狄拉克,但在频域中我得到了一个 1. 处的狄拉克。此外,光谱看起来很奇怪......这是我得到的:
【问题讨论】:
-
显示您的代码、预期行为和实际行为。