Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upconvert and downconvert matrix must return a matrix #39

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ end
function upconvert(s::AbstractMatrix, sps, fc, pulseshape=rrcosfir(0.25, sps); fs=framerate(s))
mapreduce(hcat, eachcol(s)) do x
upconvert(x, sps, fc, pulseshape; fs=fs)
end
end[:,:]
end

"""
Expand All @@ -143,7 +143,7 @@ end
function downconvert(s::AbstractMatrix, sps, fc, pulseshape=rrcosfir(0.25, sps); fs=framerate(s))
mapreduce(hcat, eachcol(s)) do x
downconvert(x, sps, fc, pulseshape; fs=fs)
end
end[:,:]
end

"""
Expand Down Expand Up @@ -499,19 +499,16 @@ function _istft(iX::AbstractMatrix{T}, nfft::Int, noverlap::Int, window::Union{F
# H. Zhivomirov, TEM Journal, Vol. 8, No. 1, pp. 56-64, 2019.
(window === nothing) && (window = rect)
win, norm2 = Periodograms.compute_window(window, nfft)

nstep = nfft - noverlap
nseg = size(iX, 2)
outputlength = nfft + (nseg-1) * nstep

iX .*= win
x = zeros(T, outputlength)
normw = zeros(eltype(win), outputlength)
for i = 1:nseg
@views x[1+(i-1)*nstep:nfft+(i-1)*nstep] .= x[1+(i-1)*nstep:nfft+(i-1)*nstep] .+ iX[:,i]
@views normw[1+(i-1)*nstep:nfft+(i-1)*nstep] .= normw[1+(i-1)*nstep:nfft+(i-1)*nstep] .+ win .^ 2
end

trimlength = nfft % 2 == 0 ? outputlength - nfft : outputlength - nfft + 1
(sum(@view(normw[1+nfft÷2:end-nfft÷2]) .> 1e-10) != trimlength) && (
@warn "NOLA condition failed, STFT may not be invertible")
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,16 @@ end
@test framerate(z) == 100
@test amp2db(rms(x-z)/rms(z)) < -40.0

x = x[:,1:1]
y = upconvert(x, 10, 100)
@test nchannels(y) == 1
@test framerate(y) == 1000
@test y isa AbstractMatrix
z = downconvert(y, 10, 100)[12:end-11,:]
@test nchannels(z) == 1
@test framerate(z) == 100
@test z isa AbstractMatrix

x = rcosfir(0.25, 10)
@test length(x) == 221
@test x[1:10:end] ≈ vcat(zeros(11), 0.326598866403003, zeros(11))
Expand Down
Loading