XLPack 6.1
Julia API Reference Manual
Loading...
Searching...
No Matches

◆ rfft1f()

function rfft1f ( n::Integer  ,
r::Array{Float64}  ,
wsave::Array{Float64}  ,
inc::Integer  = 1 
)

One-dimensional real Fourier transform

Purpose
rfft1f computes the one-dimensional Fourier transform of a periodic sequence within a real array. This is referred to as the forward transform or Fourier analysis, transforming the sequence from physical to spectral space.
r[0] = (1/n)Σr[j] (Σ for j = 0 to n-1)
r[2k-1] = (2/n)Σr[j]cos(2πjk/n) (Σ for j = 0 to n-1) (k = 1 to nh)
r[2k] = (2/n)Σr[j]sin(2πjk/n) (Σ for j = 0 to n-1) (k = 1 to nh)
r[n-1] = (1/n)Σ(-1)^j r[j] (Σ for j = 0 to n-1) (only if n is even)
(If n is even, nh = n/2-1. If n is odd, nh = (n-1)/2)
This transform is normalized since a call to rfft1f followed by a call to rfft1b (or vice-versa) reproduces the original array subject to algorithmic constraints, roundoff error, etc.
Returns
info (Int32)
= 0: Successful exit
= -1: The argument n had an illegal value (n < 1)
= -2: The argument r is invalid
= -3: The argument wsave is invalid
= -4: The argument inc had an illegal value (inc < 1)
Parameters
[in]nThe length of the sequence to be transformed. (n >= 1)
The transform is most efficient when n is a product of small primes.
[in,out]r1-dimensional array (Float64, inc*(n - 1) + 1)
[in] The sequence to be transformed.
[out] The Fourier forward transformed sequence of data.
[in]wsave1-dimensional array (Float64, n + ln(n)/ln(2) + 4)
Work data. Its contents must be initialized with a call to rfft1i before the first call to rfft1f or rfft1b for a given transform length n.
[in]inc(Optional)
Integer increment between the locations, in array r, of two consecutive elements within the sequence. (inc >= 1) (default = 1)
Reference
FFTPACK 5.1
Example Program
Compute the Fourier transform and backward transform of 5 random data sequence successively, and compare with the original data sequence.
function TestRfft1()
# Initialization
println("** Rfft1 **")
seed = 13
n = 5
lwsave::Cint = n + round(Cint, log(n)/log(2)) + 4
wsave = Vector{Cdouble}(undef, lwsave)
info = rfft1i(n, wsave)
if info != 0
println("Error during initialization: info = ", info)
return 1
end
# Generate test data
inc = 1
lr = inc*(n - 1) + 1
r = Vector{Cdouble}(undef, lr)
rcopy = Vector{Cdouble}(undef, lr)
for i = 1:n
k = 1 + inc*(i - 1)
r[k] = genrand_res53()
rcopy[k] = r[k]
end
# Forward transform
info = rfft1f(n, r, wsave)
if info != 0
println("Error in Rfft1f: info = ", info)
return 2
end
# Backward transform
info = rfft1b(n, r, wsave)
if info != 0
println("Error in Rfft1b: info = ", info)
return 3
end
# Check results
diff = 0.0
for i = 1:n
k = 1 + inc*(i - 1)
if abs(r[k] - rcopy[k]) > diff
diff = abs(r[k] - rcopy[k])
end
println(rcopy[k], " ", r[k], " ", abs(r[k] - rcopy[k]))
end
println("diff(max) = ", diff)
end
function rfft1b(n::Integer, r::Array{Float64}, wsave::Array{Float64}, inc::Integer=1)
One-dimensional real fast Fourier backward transform
function rfft1i(n::Integer, wsave::Array{Float64})
Initialization of work data for rfft1f and rfft1b
function rfft1f(n::Integer, r::Array{Float64}, wsave::Array{Float64}, inc::Integer=1)
One-dimensional real Fourier transform
function genrand_res53()
53 bit real random number in [0, 1) (Mersenne Twister)
function init_genrand(s::Integer)
Initialization with seed for random number generator (Mersenne Twister)
Example Results
> TestRfft1()
0.7777024105738202 0.7777024105738204 2.220446049250313e-16
0.2375412200349123 0.23754122003491207 2.220446049250313e-16
0.8242785326613685 0.8242785326613685 0.0
0.9657491980429997 0.9657491980429999 1.1102230246251565e-16
0.9726011139048933 0.9726011139048933 0.0
diff(max) = 2.220446049250313e-16