Skip to content

Commit a7ac3e6

Browse files
committed
Power of 2 FFT in place
1 parent 557247b commit a7ac3e6

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ authors = ["Danny Sharp <[email protected]> and contributors"]
44
version = "0.1.0"
55

66
[deps]
7+
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
78
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
89
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
910

src/NSFFT.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module NSFFT
22

3-
using Primes, StaticArrays
3+
using Primes, StaticArrays, LoopVectorization
44
export pow2FFT!, myfft_sv
55

66
include("algos.jl")

src/algos.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
@enum Direction FFT_FORWARD FFT_BACKWARD
22

3+
"""
4+
Power of 2 FFT in place, forward
5+
6+
"""
37
function pow2FFT!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_FORWARD}) where {T<:Complex}
48
N = length(out)
59
if N == 1
@@ -19,4 +23,29 @@ function pow2FFT!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_FORWA
1923
out[j+m] = out_j - wj*out[j+m]
2024
wj *= w1
2125
end
26+
end
27+
28+
"""
29+
Power of 2 FFT in place, backward
30+
31+
"""
32+
function pow2FFT!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_BACKWARD}) where {T<:Complex}
33+
N = length(out)
34+
if N == 1
35+
out[1] = in[1]
36+
return
37+
end
38+
pow2FFT!(@view(out[1:(end÷2)]), @view(in[1:2:end]), Val(FFT_BACKWARD))
39+
pow2FFT!(@view(out[(end÷2+1):end]), @view(in[2:2:end]), Val(FFT_BACKWARD))
40+
41+
inc = 2*π/N
42+
w1 = T(cos(inc), sin(inc));
43+
wj = T(1,0)
44+
m = N ÷ 2
45+
for j in 1:m
46+
out_j = out[j]
47+
out[j] = out_j + wj*out[j+m]
48+
out[j+m] = out_j - wj*out[j+m]
49+
wj *= w1
50+
end
2251
end

0 commit comments

Comments
 (0)