1
1
const BigFloats = Union{BigFloat,Complex{BigFloat}}
2
2
3
- real (x... )= Base. real (x... )
4
- real {T<:Real} (:: Type{T} )= T
5
- real {T<:Real} (:: Type{Complex{T}} )= T
3
+ if VERSION < v " 0.7-"
4
+ import Base. FFTW: fft, fft!, rfft, irfft, ifft, conv, dct, idct, dct!, idct!,
5
+ plan_fft!, plan_ifft!, plan_dct!, plan_idct!,
6
+ plan_fft, plan_ifft, plan_rfft, plan_irfft, plan_dct, plan_idct
7
+ else
8
+ import FFTW: fft, fft!, rfft, irfft, ifft, conv, dct, idct, dct!, idct!,
9
+ plan_fft!, plan_ifft!, plan_dct!, plan_idct!,
10
+ plan_fft, plan_ifft, plan_rfft, plan_irfft, plan_dct, plan_idct
11
+ end
6
12
7
13
# The following implements Bluestein's algorithm, following http://www.dsprelated.com/dspbooks/mdft/Bluestein_s_FFT_Algorithm.html
8
14
# To add more types, add them in the union of the function's signature.
9
- function Base . fft {T<:BigFloats} (x:: Vector{T} )
15
+ function fft {T<:BigFloats} (x:: Vector{T} )
10
16
n = length (x)
11
17
ispow2 (n) && return fft_pow2 (x)
12
18
ks = linspace (zero (real (T)),n- one (real (T)),n)
13
- Wks = exp .((- im). * convert (T,π).* ks.^ 2. / n)
14
- xq,wq = x.* Wks,conj ([exp (- im* convert (T,π)* n);reverse (Wks);Wks[2 : end ]])
19
+ Wks = exp .((- im). * convert (T,π).* ks.^ 2 ./ n)
20
+ xq, wq = x.* Wks, conj ([exp (- im* convert (T,π)* n);reverse (Wks);Wks[2 : end ]])
15
21
return Wks.* conv (xq,wq)[n+ 1 : 2 n]
16
22
end
17
23
18
- function Base . fft! {T<:BigFloats} (x:: Vector{T} )
24
+ function fft! {T<:BigFloats} (x:: Vector{T} )
19
25
x[:] = fft (x)
20
26
return x
21
27
end
22
28
23
29
# add rfft for BigFloat, by calling fft
24
- # this creates ToeplitzMatrices.rfft, so avoids changing Base. rfft
25
- Base . rfft {T<:BigFloats} (v:: Vector{T} )= fft (v)[1 : div (length (v),2 )+ 1 ]
26
- function Base . irfft {T<:BigFloats} (v:: Vector{T} ,n:: Integer )
30
+ # this creates ToeplitzMatrices.rfft, so avoids changing rfft
31
+ rfft {T<:BigFloats} (v:: Vector{T} )= fft (v)[1 : div (length (v),2 )+ 1 ]
32
+ function irfft {T<:BigFloats} (v:: Vector{T} ,n:: Integer )
27
33
@assert n== 2 length (v)- 1
28
34
r = Vector {Complex{BigFloat}} (n)
29
35
r[1 : length (v)]= v
30
36
r[length (v)+ 1 : end ]= reverse (conj (v[2 : end ]))
31
37
real (ifft (r))
32
38
end
33
39
34
- Base . ifft {T<:BigFloats} (x:: Vector{T} ) = conj! (fft (conj (x)))/ length (x)
35
- function Base . ifft! {T<:BigFloats} (x:: Vector{T} )
40
+ ifft {T<:BigFloats} (x:: Vector{T} ) = conj! (fft (conj (x)))/ length (x)
41
+ function ifft! {T<:BigFloats} (x:: Vector{T} )
36
42
x[:] = ifft (x)
37
43
return x
38
44
end
39
45
40
- function Base . conv {T<:BigFloats} (u:: StridedVector{T} , v:: StridedVector{T} )
46
+ function conv {T<:BigFloats} (u:: StridedVector{T} , v:: StridedVector{T} )
41
47
nu,nv = length (u),length (v)
42
48
n = nu + nv - 1
43
49
np2 = nextpow2 (n)
@@ -101,7 +107,7 @@ function ifft_pow2{T<:BigFloat}(x::Vector{Complex{T}})
101
107
end
102
108
103
109
104
- function Base . dct (a:: AbstractArray{Complex{BigFloat}} )
110
+ function dct (a:: AbstractArray{Complex{BigFloat}} )
105
111
N = big (length (a))
106
112
c = fft ([a; flipdim (a,1 )])
107
113
d = c[1 : N]
@@ -110,9 +116,9 @@ function Base.dct(a::AbstractArray{Complex{BigFloat}})
110
116
scale! (inv (sqrt (2 N)), d)
111
117
end
112
118
113
- Base . dct (a:: AbstractArray{BigFloat} ) = real (dct (complex (a)))
119
+ dct (a:: AbstractArray{BigFloat} ) = real (dct (complex (a)))
114
120
115
- function Base . idct (a:: AbstractArray{Complex{BigFloat}} )
121
+ function idct (a:: AbstractArray{Complex{BigFloat}} )
116
122
N = big (length (a))
117
123
b = a * sqrt (2 * N)
118
124
b[1 ] = b[1 ] * sqrt (big (2 ))
@@ -122,18 +128,18 @@ function Base.idct(a::AbstractArray{Complex{BigFloat}})
122
128
c[1 : N]
123
129
end
124
130
125
- Base . idct (a:: AbstractArray{BigFloat} ) = real (idct (complex (a)))
131
+ idct (a:: AbstractArray{BigFloat} ) = real (idct (complex (a)))
126
132
127
- Base . dct! {T<:BigFloats} (a:: AbstractArray{T} ) = (b = dct (a); a[:] = b)
128
- Base . idct! {T<:BigFloats} (a:: AbstractArray{T} ) = (b = idct (a); a[:] = b)
133
+ dct! {T<:BigFloats} (a:: AbstractArray{T} ) = (b = dct (a); a[:] = b)
134
+ idct! {T<:BigFloats} (a:: AbstractArray{T} ) = (b = idct (a); a[:] = b)
129
135
130
136
# dummy plans
131
- type DummyFFTPlan{T,inplace} <: Plan{T} end
132
- type DummyiFFTPlan{T,inplace} <: Plan{T} end
133
- type DummyrFFTPlan{T,inplace} <: Plan{T} end
134
- type DummyirFFTPlan{T,inplace} <: Plan{T} end
135
- type DummyDCTPlan{T,inplace} <: Plan{T} end
136
- type DummyiDCTPlan{T,inplace} <: Plan{T} end
137
+ struct DummyFFTPlan{T,inplace} <: Plan{T} end
138
+ struct DummyiFFTPlan{T,inplace} <: Plan{T} end
139
+ struct DummyrFFTPlan{T,inplace} <: Plan{T} end
140
+ struct DummyirFFTPlan{T,inplace} <: Plan{T} end
141
+ struct DummyDCTPlan{T,inplace} <: Plan{T} end
142
+ struct DummyiDCTPlan{T,inplace} <: Plan{T} end
137
143
138
144
for (Plan,iPlan) in ((:DummyFFTPlan ,:DummyiFFTPlan ),
139
145
(:DummyrFFTPlan ,:DummyirFFTPlan ),
@@ -164,19 +170,19 @@ end
164
170
165
171
166
172
167
- Base . plan_fft! {T<:BigFloats} (x:: Vector{T} ) = DummyFFTPlan {Complex{BigFloat},true} ()
168
- Base . plan_ifft! {T<:BigFloats} (x:: Vector{T} ) = DummyiFFTPlan {Complex{BigFloat},true} ()
169
- # Base. plan_rfft!{T<:BigFloats}(x::Vector{T}) = DummyrFFTPlan{Complex{BigFloat},true}()
170
- # Base. plan_irfft!{T<:BigFloats}(x::Vector{T},n::Integer) = DummyirFFTPlan{Complex{BigFloat},true}()
171
- Base . plan_dct! {T<:BigFloats} (x:: Vector{T} ) = DummyDCTPlan {T,true} ()
172
- Base . plan_idct! {T<:BigFloats} (x:: Vector{T} ) = DummyiDCTPlan {T,true} ()
173
+ plan_fft! {T<:BigFloats} (x:: Vector{T} ) = DummyFFTPlan {Complex{BigFloat},true} ()
174
+ plan_ifft! {T<:BigFloats} (x:: Vector{T} ) = DummyiFFTPlan {Complex{BigFloat},true} ()
175
+ # plan_rfft!{T<:BigFloats}(x::Vector{T}) = DummyrFFTPlan{Complex{BigFloat},true}()
176
+ # plan_irfft!{T<:BigFloats}(x::Vector{T},n::Integer) = DummyirFFTPlan{Complex{BigFloat},true}()
177
+ plan_dct! {T<:BigFloats} (x:: Vector{T} ) = DummyDCTPlan {T,true} ()
178
+ plan_idct! {T<:BigFloats} (x:: Vector{T} ) = DummyiDCTPlan {T,true} ()
173
179
174
- Base . plan_fft {T<:BigFloats} (x:: Vector{T} ) = DummyFFTPlan {Complex{BigFloat},false} ()
175
- Base . plan_ifft {T<:BigFloats} (x:: Vector{T} ) = DummyiFFTPlan {Complex{BigFloat},false} ()
176
- Base . plan_rfft {T<:BigFloats} (x:: Vector{T} ) = DummyrFFTPlan {Complex{BigFloat},false} ()
177
- Base . plan_irfft {T<:BigFloats} (x:: Vector{T} ,n:: Integer ) = DummyirFFTPlan {Complex{BigFloat},false} ()
178
- Base . plan_dct {T<:BigFloats} (x:: Vector{T} ) = DummyDCTPlan {T,false} ()
179
- Base . plan_idct {T<:BigFloats} (x:: Vector{T} ) = DummyiDCTPlan {T,false} ()
180
+ plan_fft {T<:BigFloats} (x:: Vector{T} ) = DummyFFTPlan {Complex{BigFloat},false} ()
181
+ plan_ifft {T<:BigFloats} (x:: Vector{T} ) = DummyiFFTPlan {Complex{BigFloat},false} ()
182
+ plan_rfft {T<:BigFloats} (x:: Vector{T} ) = DummyrFFTPlan {Complex{BigFloat},false} ()
183
+ plan_irfft {T<:BigFloats} (x:: Vector{T} ,n:: Integer ) = DummyirFFTPlan {Complex{BigFloat},false} ()
184
+ plan_dct {T<:BigFloats} (x:: Vector{T} ) = DummyDCTPlan {T,false} ()
185
+ plan_idct {T<:BigFloats} (x:: Vector{T} ) = DummyiDCTPlan {T,false} ()
180
186
181
187
182
188
function interlace {S<:Number,V<:Number} (a:: Vector{S} ,b:: Vector{V} )
0 commit comments