Skip to content

Commit 6a11c6a

Browse files
add 2D nufft of type I-I
1 parent fa238d3 commit 6a11c6a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/nufft.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,19 @@ function Base.A_mul_B!{T}(f::AbstractVector{T}, P::NUFFTPlan{3,T}, c::AbstractVe
167167
f
168168
end
169169

170+
function A_mul_B_col_J!{T}(F::Matrix{T}, P::NUFFTPlan{3,T}, C::Matrix{T}, J::Int)
171+
U, V, p, t, temp, temp2, Ones = P.U, P.V, P.p, P.t, P.temp, P.temp2, P.Ones
172+
173+
broadcast_col_J!(*, temp2, C, V, J)
174+
A_mul_B!(temp, p, temp2)
175+
reindex_temp!(temp, t, temp2)
176+
broadcast!(*, temp, U, temp2)
177+
COLSHIFT = size(C, 1)*(J-1)
178+
A_mul_B!(F, temp, Ones, 1+COLSHIFT, 1)
179+
180+
F
181+
end
182+
170183
function reindex_temp!{T}(temp::Matrix{T}, t::Vector{Int}, temp2::Matrix{T})
171184
@inbounds for j = 1:size(temp, 2)
172185
for i = 1:size(temp, 1)
@@ -227,6 +240,17 @@ immutable NUFFT2DPlan{T,P1,P2} <: Base.DFT.Plan{T}
227240
temp::Vector{T}
228241
end
229242

243+
doc"""
244+
Pre-computes a 2D nonuniform fast Fourier transform of type I-I.
245+
"""
246+
function plan_nufft1{T<:AbstractFloat}::AbstractVector{T}, π::AbstractVector{T}, ϵ::T)
247+
p1 = plan_nufft1(ω, ϵ)
248+
p2 = plan_nufft1(π, ϵ)
249+
temp = zeros(Complex{T}, length(π))
250+
251+
NUFFT2DPlan(p1, p2, temp)
252+
end
253+
230254
doc"""
231255
Pre-computes a 2D nonuniform fast Fourier transform of type II-II.
232256
"""
@@ -258,6 +282,15 @@ function Base.A_mul_B!{T}(F::Matrix{T}, P::NUFFT2DPlan{T}, C::Matrix{T})
258282
F
259283
end
260284

285+
doc"""
286+
Computes a 2D nonuniform fast Fourier transform of type I-I:
287+
288+
```math
289+
f_{j_1,j_2} = \sum_{k_1=1}^M\sum_{k_2=1}^N C_{k_1,k_2} e^{-2\pi{\rm i} ((j_1-1)/M \omega_{k_1} + (j_2-1)/N \pi_{k_2})},\quad{\rm for}\quad 1 \le j_1 \le M,\quad 1 \le j_2 \le N.
290+
```
291+
"""
292+
nufft1{T<:AbstractFloat}(C::Matrix, ω::AbstractVector{T}, π::AbstractVector{T}, ϵ::T) = plan_nufft1(ω, π, ϵ)*C
293+
261294
doc"""
262295
Computes a 2D nonuniform fast Fourier transform of type II-II:
263296

test/nuffttests.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ using FastTransforms, Base.Test
6868
@test norm(exact - fast, Inf) < err_bnd
6969
end
7070

71+
function nudft1{T<:AbstractFloat}(C::Matrix{Complex{T}}, ω1::AbstractVector{T}, ω2::AbstractVector{T})
72+
# Nonuniform discrete Fourier transform of type I-I
73+
74+
M, N = size(C)
75+
output = zeros(C)
76+
@inbounds for j1 = 1:M, j2 = 1:N
77+
for k1 = 1:M, k2 = 1:N
78+
output[j1,j2] += exp(-2*T(π)*im*((j1-1)/M*ω1[k1]+(j2-1)/N*ω2[k2]))*C[k1,k2]
79+
end
80+
end
81+
return output
82+
end
83+
7184
function nudft2{T<:AbstractFloat}(C::Matrix{Complex{T}}, x::AbstractVector{T}, y::AbstractVector{T})
7285
# Nonuniform discrete Fourier transform of type II-II
7386

@@ -89,6 +102,13 @@ using FastTransforms, Base.Test
89102

90103
x = (collect(0:n-1) + 0.25*rand(n))/n
91104
y = (collect(0:n-1) + 0.25*rand(n))/n
105+
ω1 = collect(0:n-1) + 0.25*rand(n)
106+
ω2 = collect(0:n-1) + 0.25*rand(n)
107+
108+
exact = nudft1(C, ω1, ω2)
109+
fast = nufft1(C, ω1, ω2, ϵ)
110+
@test norm(exact - fast, Inf) < err_bnd
111+
92112
exact = nudft2(C, x, y)
93113
fast = nufft2(C, x, y, ϵ)
94114
@test norm(exact - fast, Inf) < err_bnd

0 commit comments

Comments
 (0)