Skip to content

Commit 96aca89

Browse files
renamed function, added test, beautified line-wraps
1 parent 6a275c4 commit 96aca89

File tree

4 files changed

+477
-32
lines changed

4 files changed

+477
-32
lines changed

src/czt.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export czt, iczt
22

33
"""
4-
czt_1d(xin , scaled , d; kill_wrap=false, pad_value=zero(eltype(xin)))
4+
czt_1d(xin , scaled , d; remove_wrap=false, pad_value=zero(eltype(xin)))
55
66
Chirp z transform along a single direction d of an ND array `xin` into the ND array 'xout'.
77
Note that xin and xout can be the same array for inplace operations.
@@ -14,11 +14,11 @@ This code is based on a 2D Matlab version of the CZT, written by H. Gross et al.
1414
+ `xin`: array to transform
1515
+ `scaled`: factor to zoom into during the 1-dimensional czt.
1616
+ `d`: single dimension to transform (as a tuple)
17-
+ `kill_wrap`: if true, the wrapped places will be set to pad_value
18-
+ `pad_value`: the value that the wrap-around will be set to if `kill_wrap` is `true`.
17+
+ `remove_wrap`: if true, the wrapped places will be set to pad_value
18+
+ `pad_value`: the value that the wrap-around will be set to if `remove_wrap` is `true`.
1919
2020
"""
21-
function czt_1d(xin, scaled, d; kill_wrap=false, pad_value=zero(eltype(xin)))
21+
function czt_1d(xin, scaled, d; remove_wrap=false, pad_value=zero(eltype(xin)))
2222
sz=size(xin)
2323
# returns the real datatype
2424
rtype = real(eltype(xin))
@@ -74,7 +74,7 @@ function czt_1d(xin, scaled, d; kill_wrap=false, pad_value=zero(eltype(xin)))
7474
NDTools.slice(xout,d, o) .-= NDTools.slice(xin,d, 1) .* (1im).^mod(o-midp,4)
7575
end
7676
end
77-
if kill_wrap && (scaled < 1.0)
77+
if remove_wrap && (scaled < 1.0)
7878
nsz = Tuple(d == nd ? ceil(Int64, scaled * size(xin,d)) : size(xin,nd) for nd=1:ndims(xin))
7979
return select_region(select_region(xout, new_size=nsz), new_size=size(xout), pad_value=pad_value)
8080
else
@@ -84,7 +84,7 @@ function czt_1d(xin, scaled, d; kill_wrap=false, pad_value=zero(eltype(xin)))
8484
end
8585

8686
"""
87-
czt(xin , scale, dims=1:length(size(xin)), kill_wrap=false)
87+
czt(xin , scale, dims=1:length(size(xin)), remove_wrap=false)
8888
Chirp z transform of the ND array `xin`
8989
This code is based on a 2D Matlab version of the CZT, written by H. Gross.
9090
The tuple `scale` defines the zoom factors in the Fourier domain. Each has to be bigger than one.
@@ -97,7 +97,7 @@ The tuple `scale` defines the zoom factors in the Fourier domain. Each has to be
9797
+ `xin`: array to transform
9898
+ `scale`: a tuple of factors (one for each dimension) to zoom into during the czt.
9999
+ `dims`: a tuple of dimensions over which to apply the czt.
100-
+ `kill_wrap`: if true, the wrapped places will be set to zero. Note that the `pad_value` argument is only allowed for 1d czts to not cause confusion.
100+
+ `remove_wrap`: if true, the wrapped places will be set to zero. Note that the `pad_value` argument is only allowed for 1d czts to not cause confusion.
101101
102102
#Example:
103103
```jdoctest
@@ -134,16 +134,17 @@ julia> zoomed = real.(ift(xft))
134134
0.0239759 -0.028264 0.0541186 -0.0116475 -0.261294 0.312719 -0.261294 -0.0116475 0.0541186 -0.028264
135135
```
136136
"""
137-
function czt(xin::Array{T,N}, scale, dims=1:length(size(xin)); kill_wrap=false)::Array{complex(T),N} where {T,N}
137+
function czt(xin::Array{T,N}, scale, dims=1:length(size(xin));
138+
remove_wrap=false)::Array{complex(T),N} where {T,N}
138139
xout = xin
139140
for d in dims
140-
xout = czt_1d(xout, scale[d], d; kill_wrap=kill_wrap)
141+
xout = czt_1d(xout, scale[d], d; remove_wrap=remove_wrap)
141142
end
142143
return xout
143144
end
144145

145146
"""
146-
iczt(xin , scale, dims=1:length(size(xin)); kill_wrap=false)
147+
iczt(xin , scale, dims=1:length(size(xin)); remove_wrap=false)
147148
Inverse chirp z transform of the ND array `xin`
148149
This code is based on a 2D Matlab version of the CZT, written by H. Gross.
149150
The tuple `scale` defines the zoom factors in the Fourier domain. Each has to be bigger than one.
@@ -154,7 +155,8 @@ The tuple `scale` defines the zoom factors in the Fourier domain. Each has to be
154155
+ `xin`: array to transform
155156
+ `scale`: a tuple of factors (one for each dimension) of the the inverse czt.
156157
+ `dims`: a tuple of dimensions over which to apply the inverse czt.
157-
+ `kill_wrap`: if true, the wrapped places will be set to zero. Note that the `pad_value` argument is only allowed for 1d czts to not cause confusion.
158+
+ `remove_wrap`: if true, the wrapped places will be set to zero.
159+
Note that the `pad_value` argument is only allowed for 1d czts to not cause confusion.
158160
159161
#See also: czt, czt_1d
160162
@@ -193,6 +195,6 @@ julia> iczt(xft,(1.2,1.3))
193195
-0.0965531+0.0404296im -0.159713+0.0637132im 0.48095+0.0775406im 0.67753-0.263814im 0.77553-0.121603im 0.660335-0.00736904im 0.495205-0.135059im -0.163859+0.125535im
194196
```
195197
"""
196-
function iczt( xin , scale, dims=1:length(size(xin)); kill_wrap=false)
197-
conj(czt(conj(xin), scale, dims; kill_wrap=kill_wrap)) / prod(size(xin))
198+
function iczt( xin , scale, dims=1:length(size(xin)); remove_wrap=false)
199+
conj(czt(conj(xin), scale, dims; remove_wrap=remove_wrap)) / prod(size(xin))
198200
end

0 commit comments

Comments
 (0)