简体   繁体   中英

upsample complex matrix in julia

I have a complex matrix (ie Array{Complex{Float64},2} ) in julia that I would like to upsample in one dimension.

My equivalent python code is:

data_package['time_series']  = sp.signal.resample(data_package['time_series'] .astype('complex64'), data_package['time_series'].shape[1]*upsample_factor, axis=1)

A resample() function can be found in DSP.jl . But it only works on Vectors, so one has to apply it manually along the desired dimension. One possible way looks like this (resampling along the second dimension, with a new rate of 2):

julia> using DSP

julia> test = reshape([1.0im, 2.0im, 3.0im, 4., 5., 6.], 3, 2)
3×2 Matrix{ComplexF64}:
 0.0+1.0im  4.0+0.0im
 0.0+2.0im  5.0+0.0im
 0.0+3.0im  6.0+0.0im

julia> newRate = 2
2

julia> up = [resample(test[:, i], newRate) for i in 1:size(test, 2)] # gives a vector of vectors
2-element Vector{Vector{ComplexF64}}:
 [0.0 + 0.9999042566881922im, 0.0 + 1.2801955476665785im, 0.0 + 1.9998085133763843im, 0.0 + 2.968204475861045im, 0.0 + 2.9997127700645763im]
 [3.9996170267527686 + 0.0im, 4.466495565312296 + 0.0im, 4.999521283440961 + 0.0im, 6.154504493506763 + 0.0im, 5.9994255401291525 + 0.0im]

julia> cat(up..., dims = 2) # fuse to matrix
5×2 Matrix{ComplexF64}:
 0.0+0.999904im  3.99962+0.0im
 0.0+1.2802im     4.4665+0.0im
 0.0+1.99981im   4.99952+0.0im
 0.0+2.9682im     6.1545+0.0im
 0.0+2.99971im   5.99943+0.0im

Please consider the package FFTResampling.jl

The method is based on the FFT, assuming periodic and band-limited input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM