From 67fa25e5128dc0acbb7acb850b846367c0c19b40 Mon Sep 17 00:00:00 2001 From: Mandar Chitre Date: Wed, 9 Aug 2023 00:37:59 +0800 Subject: [PATCH] fix(dsp): upconvert and downconvert matrix return matrix (#38) --- src/dsp.jl | 7 ++----- test/runtests.jl | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/dsp.jl b/src/dsp.jl index baf6532..a65864d 100644 --- a/src/dsp.jl +++ b/src/dsp.jl @@ -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 """ @@ -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 """ @@ -499,11 +499,9 @@ 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) @@ -511,7 +509,6 @@ function _istft(iX::AbstractMatrix{T}, nfft::Int, noverlap::Int, window::Union{F @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") diff --git a/test/runtests.jl b/test/runtests.jl index 89ca848..a2835b8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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))