From ea100edbc42667d742e3424cff280a5406cfae1e Mon Sep 17 00:00:00 2001 From: hzarei4 Date: Mon, 17 Feb 2025 17:01:42 +0100 Subject: [PATCH] fixing the shift of the center of the array for resampling --- src/resampling.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/resampling.jl b/src/resampling.jl index 3be1e8b..c7dd0d6 100644 --- a/src/resampling.jl +++ b/src/resampling.jl @@ -52,11 +52,14 @@ julia> resample([2.0, 0.0], (6,)) ≈ 1 .+ cos.(2π .* (0:5)./6) true ``` """ -function resample(arr::AbstractArray{T, N}, new_size; normalize=true) where {T, N} +function resample(arr::AbstractArray{T, N}, new_size; shift_center=false, normalize=true) where {T, N} if new_size == size(arr) return copy(arr) end # for complex arrays we need a full FFT + if shift_center + arr = ifftshift(arr) + end if T <: Complex arr_out = resample_by_FFT(arr, Tuple(new_size)) else @@ -67,6 +70,9 @@ function resample(arr::AbstractArray{T, N}, new_size; normalize=true) where {T, if normalize arr_out .*= length(arr_out) ./ length(arr) end + if shift_center + arr_out = fftshift(arr_out) + end return arr_out end