Skip to content

Commit 117a7c8

Browse files
Merge pull request #59 from daanhb/master
Fix idct for complex-valued bigfloat vectors
2 parents 53ec4b0 + a1d97ae commit 117a7c8

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/fftBigFloat.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function ifft_pow2(x::Vector{Complex{T}}) where T<:BigFloat
110110
end
111111

112112

113-
function dct(a::AbstractArray{Complex{BigFloat}})
113+
function dct(a::AbstractVector{Complex{BigFloat}})
114114
N = big(length(a))
115115
c = fft([a; flipdim(a,1)])
116116
d = c[1:N]
@@ -121,14 +121,14 @@ end
121121

122122
dct(a::AbstractArray{BigFloat}) = real(dct(complex(a)))
123123

124-
function idct(a::AbstractArray{Complex{BigFloat}})
125-
N = big(length(a))
124+
function idct(a::AbstractVector{Complex{BigFloat}})
125+
N = big(length(a))
126126
b = a * sqrt(2*N)
127127
b[1] = b[1] * sqrt(big(2))
128-
b .*= exp.((im*big(pi)).*(0:N-1)./(2*N))
129-
b = [b; 0; conj(flipdim(b[2:end],1))]
128+
shift = exp.(-im * 2 * big(pi) * (N - big(1)/2) * (0:(2N-1)) / (2 * N))
129+
b = [b; 0; -flipdim(b[2:end],1)] .* shift
130130
c = ifft(b)
131-
c[1:N]
131+
flipdim(c[1:N],1)
132132
end
133133

134134
idct(a::AbstractArray{BigFloat}) = real(idct(complex(a)))

test/fftBigFloattests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ end
1717
@test norm(dct(c) - p*c) == 0
1818

1919
pi = plan_idct!(c)
20-
@test norm(pi*dct(c) - c) < 500norm(c)*eps(BigFloat)
20+
@test norm(pi*dct(c) - c) < 1000norm(c)*eps(BigFloat)
2121

2222
@test norm(dct(c)-dct(map(Float64,c)),Inf) < 10eps()
2323

2424
cc = cis.(c)
2525
@test norm(dct(cc)-dct(map(Complex{Float64},cc)),Inf) < 10eps()
26+
27+
c = big.(rand(100)) + im*big.(rand(100))
28+
@test norm(dct(c)-dct(map(ComplexF64,c)),Inf) < 10eps()
29+
@test norm(idct(c)-idct(map(ComplexF64,c)),Inf) < 10eps()
30+
@test norm(idct(dct(c))-c,Inf) < 1000eps(BigFloat)
31+
@test norm(dct(idct(c))-c,Inf) < 1000eps(BigFloat)
2632
end

0 commit comments

Comments
 (0)