Skip to content

Commit

Permalink
refactor(dsp): rename zak to dzt
Browse files Browse the repository at this point in the history
  • Loading branch information
mchitre committed Jul 22, 2024
1 parent ae40007 commit 9b25402
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
36 changes: 18 additions & 18 deletions src/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Optim: optimize, minimizer, BFGS
export fir, removedc, removedc!, demon
export upconvert, downconvert, rrcosfir, rcosfir
export mseq, gmseq, circconv, goertzel, pll, hadamard
export mfilter, findsignal, zak, izak
export mfilter, findsignal, dzt, idzt
export istft, whiten, filt, filtfilt, resample, delay!, compose

"""
Expand Down Expand Up @@ -795,60 +795,60 @@ function compose(r, t, a; duration=duration(r)+maximum(t), fs=framerate(r))
end

"""
zak(x, L, K)
zak(x, L)
dzt(x, L, K)
dzt(x, L)
Compute the Zak transform of signal `x` with `L` delay bins and `K` Doppler bins.
The length of signal `x` must be equal to `LK`. If `K` is not specified, it is
assumed to be the length of `x` divided by `L`. Returns a `K × L` complex matrix.
Compute the discrete Zak transform (DZT) of signal `x` with `L` delay bins and `K`
Doppler bins. The length of signal `x` must be equal to `LK`. If `K` is not specified,
it is assumed to be the length of `x` divided by `L`. Returns a `K × L` complex matrix.
If the frame rate of `x` if `fs` Sa/s, the delay bins are spaced at `1/fs` seconds
and the Doppler bins are spaced at `fs/LK` Hz. The Zak transform is scaled such
and the Doppler bins are spaced at `fs/LK` Hz. The DZT is scaled such
that the energy of the signal is preserved, i.e., `sum(abs2, x) ≈ sum(abs2, X)`.
For efficient computation of the Zak transform, `K` should product of small primes.
For efficient computation of the DZT, `K` should product of small primes.
# Examples:
```julia-repl
julia> x = randn(ComplexF64, 4096)
4096-element Vector{ComplexF64}:
:
julia> X = zak(x, 64)
julia> X = dzt(x, 64)
64×64 Matrix{ComplexF64}:
:
```
"""
function zak(x::AbstractVector, L::Int, K::Int)
function dzt(x::AbstractVector, L::Int, K::Int)
length(x) == L * K || throw(ArgumentError("Length of x must be L * K"))
X = complex.(collect(transpose(reshape(x, L, K)))) ./ sqrt(K)
fft!(X, 1)
end

function zak(x::AbstractVector, L::Int)
function dzt(x::AbstractVector, L::Int)
length(x) % L == 0 || throw(ArgumentError("Length of x must be a multiple of L"))
zak(x, L, length(x) ÷ L)
dzt(x, L, length(x) ÷ L)
end

"""
$(SIGNATURES)
Compute the inverse Zak transform of 2D `K × L` complex signal `X` with `L`
delay bins and `K` Doppler bins. The length of the returned signal is `LK`.
Compute the inverse discrete Zak transform (DZT) of 2D `K × L` complex signal `X`
with `L` delay bins and `K` Doppler bins. The length of the returned signal is `LK`.
See [`zak`](@ref) for more details.
See [`dzt`](@ref) for more details.
# Examples:
```julia-repl
julia> x = randn(ComplexF64, 4096)
4096-element Vector{ComplexF64}:
:
julia> X = zak(x, 64)
julia> X = dzt(x, 64)
64×64 Matrix{ComplexF64}:
:
julia> izak(X) ≈ x
julia> idzt(X) ≈ x
true
```
"""
function izak(X::AbstractMatrix)
function idzt(X::AbstractMatrix)
X = ifft(complex.(X), 1)
X .*= sqrt(size(X, 1))
collect(vec(transpose(X)))
Expand Down
18 changes: 9 additions & 9 deletions test/tests-core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -695,19 +695,19 @@ function test_dsp()
@test samples(x) y atol=1e-3

x = rand(rng, ComplexF64, 4096)
@test vec(zak(x, length(x))) == x
@test zak(x, 1) fft(x) / sqrt(length(x))
Zx = zak(x, 64)
@test Zx == zak(x, 64, 64)
@test izak(Zx) x
@test vec(dzt(x, length(x))) == x
@test dzt(x, 1) fft(x) / sqrt(length(x))
Zx = dzt(x, 64)
@test Zx == dzt(x, 64, 64)
@test idzt(Zx) x
@test sum(abs2, x) sum(abs2, Zx)
@test vec(sum(Zx; dims=1)) / sqrt(64) x[1:64]
@test zak(4.2x, 64) 4.2Zx
@test abs.(zak(circshift(x, 10), 64)) abs.(circshift(Zx, (0, 10)))
@test dzt(4.2x, 64) 4.2Zx
@test abs.(dzt(circshift(x, 10), 64)) abs.(circshift(Zx, (0, 10)))
y = rand(rng, ComplexF64, 4096)
Zy = zak(y, 64)
Zy = dzt(y, 64)
@test vec(Zx)' * vec(Zy) x' * y
@test zak(4.2x + 2.7y, 64) 4.2Zx + 2.7Zy
@test dzt(4.2x + 2.7y, 64) 4.2Zx + 2.7Zy

end

Expand Down

0 comments on commit 9b25402

Please sign in to comment.