Skip to content

Commit 2be1bb6

Browse files
committed
initial commit
1 parent b7249b8 commit 2be1bb6

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ uuid = "b86e33f2-c0db-4aa1-a6e0-ab43e668529e"
33
authors = ["Danny Sharp <[email protected]> and contributors"]
44
version = "0.1.0"
55

6+
[deps]
7+
Primes = "27ebfcd6-29c5-5fa9-bf4b-fb8fc14df3ae"
8+
69
[compat]
710
julia = "1"
811

src/NSFFT.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module NSFFT
22

3-
# Write your package code here.
3+
using Primes
4+
export pow2FFT!, myfft_sv
5+
6+
include("algos.jl")
47

58
end

src/algos.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@enum Direction FFT_FORWARD FFT_BACKWARD
2+
3+
function pow2FFT!(out::AbstractArray{T,0}, in::AbstractArray{T,0}, ::Val) where T
4+
out[] = in[]
5+
end
6+
7+
function pow2FFT!(out::AbstractVector{T}, in::AbstractVector{T}, ::Val{FFT_FORWARD}) where {T<:Complex}
8+
N = length(out)
9+
if N == 1
10+
out[1] = in[1]
11+
return
12+
end
13+
pow2FFT!(@view(out[1:2:end]), @view(in[1:2:end]), Val(FFT_FORWARD))
14+
pow2FFT!(@view(out[2:2:end]), @view(in[2:2:end]), Val(FFT_FORWARD))
15+
16+
inc = 2*π/N
17+
w1 = T(cos(inc), -sin(inc));
18+
wj = T(1,0)
19+
m = N ÷ 2
20+
for j in 1:m
21+
out_j = out[j]
22+
println(out_j)
23+
out[j] = out_j + wj*out[j+m]
24+
println(out_j)
25+
println()
26+
out[j+m] = out_j - wj*out[j+m]
27+
wj *= w1
28+
end
29+
println()
30+
end
31+
32+
even_zeroindexed_sv(x::SVector{N,T}) where {N,T} = SVector{N÷2}(x[1:2:end])
33+
34+
function myfft_sv(arr::SVector{N, T}) where {N, T<:Complex}
35+
Nhalf = N/2
36+
ft_even = myfft_sv(even_zeroindexed_sv(arr))
37+
ft_odd = myfft_sv(odd_zeroindexed_sv(arr))
38+
f(e, o, n) = e + exp(-2im * T*n/N)) * o
39+
ft_first = map(f, ft_even, ft_odd, 0:Nhalf-1)
40+
ft_second = map(f, ft_even, ft_odd, Nhalf:N-1)
41+
vcat(ft_first, ft_second)
42+
end

0 commit comments

Comments
 (0)