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

allow iterables in fftshift and ifftshift #16229

Closed
wants to merge 4 commits into from
Closed
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
6 changes: 3 additions & 3 deletions base/dft.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ fftshift(x)

function fftshift(x,dim)
s = zeros(Int,ndims(x))
s[dim] = div(size(x,dim),2)
for i in dim; s[i] = div(size(x,i),2); end
circshift(x, s)
end

"""
fftshift(x,dim)

Swap the first and second halves of the given dimension of array `x`.
Swap the first and second halves of the given dimension or iterable of dimensions of array `x`.
"""
fftshift(x,dim)

Expand All @@ -367,7 +367,7 @@ ifftshift

function ifftshift(x,dim)
s = zeros(Int,ndims(x))
s[dim] = -div(size(x,dim),2)
for i in dim; s[i] = -div(size(x,i),2); end
circshift(x, s)
end

Expand Down
12 changes: 12 additions & 0 deletions test/dsp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,25 @@ si = [0.9967207836936347,-1.4940914728163142,1.2841226760316475,-0.4524417279474
@test_throws ArgumentError filt!([1, 2], [1], [1], [1])
@test xcorr([1, 2], [3, 4]) == [4, 11, 6]

# Shift-Functions
@test fftshift([1 2 3]) == [3 1 2]
@test fftshift([1, 2, 3]) == [3, 1, 2]
@test fftshift([1 2 3; 4 5 6]) == [6 4 5; 3 1 2]

@test fftshift([1 2 3; 4 5 6], 1) == [4 5 6; 1 2 3]
@test fftshift([1 2 3; 4 5 6], ()) == [1 2 3; 4 5 6]
@test fftshift([1 2 3; 4 5 6], (1,2)) == [6 4 5; 3 1 2]
@test fftshift([1 2 3; 4 5 6], 1:2) == [6 4 5; 3 1 2]

@test ifftshift([1 2 3]) == [2 3 1]
@test ifftshift([1, 2, 3]) == [2, 3, 1]
@test ifftshift([1 2 3; 4 5 6]) == [5 6 4; 2 3 1]

@test ifftshift([1 2 3; 4 5 6], 1) == [4 5 6; 1 2 3]
@test ifftshift([1 2 3; 4 5 6], ()) == [1 2 3; 4 5 6]
@test ifftshift([1 2 3; 4 5 6], (1,2)) == [5 6 4; 2 3 1]
@test ifftshift([1 2 3; 4 5 6], 1:2) == [5 6 4; 2 3 1]

# Convolution
a = [1., 2., 1., 2.]
b = [1., 2., 3.]
Expand Down