Thanks for your explanations.
However, I tried to implement your conclusions, but encountered a few problems.
Let’s discuss the case of having an array with odd length n
and that we downsample it to a length n-1
. lf I understand you procedure correctly, the highest positive frequency is simply removed:
julia> using FFTW
julia> function ds(y)
a = fftshift(fft(y))
b = a[1:end-1]
return ifft(ifftshift(b))
end
ds (generic function with 1 method)
julia> ds([1,2,3,4,5])
4-element Array{Complex{Float64},1}:
1.875 - 0.20307481014556647im
2.654522599411033 + 0.20307481014556647im
4.375 - 0.20307481014556647im
6.095477400588967 + 0.20307481014556647im
So the result is not purely real (as expected?).
However, if we add the highest positive frequency to the highest negative one:
julia> function ds_add(y)
a = fftshift(fft(y))
b = a[1:end-1]
b[1] += a[end]
return ifft(ifftshift(b))
end
ds_add (generic function with 1 method)
julia> ds_add([1,2,3,4,5])
4-element Array{Complex{Float64},1}:
1.25 + 0.0im
3.279522599411033 + 0.0im
3.75 + 0.0im
6.720477400588967 + 0.0im
The result is purely real.
I created a function downsample
doing this procedure in N
dimensions. So far it always returns a purely real result. In 2D (sampling from a odd N
to N-1
) it looks (simplified) like this:
julia> function ds_2D(arr)
a = fftshift(fft(arr))
a[:, 1] += a[:, end]
a[1, :] += a[end, :]
b = a[1:end-1, 1:end-1]
return ifft(ifftshift(b))
end
ds_2D (generic function with 1 method)
julia> x = randn((7,7))
7×7 Array{Float64,2}:
1.28566 0.347374 -0.327131 -0.811201 -0.0554991 -1.38513 -1.15124
0.342884 0.743379 -0.7558 -0.038343 -0.0961781 1.80734 1.07544
0.566522 0.129537 -1.06187 -0.280687 0.0809385 -0.934195 0.149161
1.63082 0.578416 -0.303113 -0.832909 0.0581663 1.80572 -0.29874
0.606241 -0.955447 0.820184 1.27619 -0.143522 -0.716512 0.949464
-0.552843 1.11347 2.24364 -0.711459 0.0939156 0.443312 -0.214561
-0.789011 1.18366 -0.399333 -0.279353 0.588281 -1.69753 -1.83028
julia> ds_2D(x)
6×6 Array{Complex{Float64},2}:
1.74993+0.0im 0.217544+0.0im -0.72932+0.0im -0.646827+0.0im -0.919558+0.0im -2.11846+0.0im
0.153758+0.0im 0.443005+0.0im -1.08628+0.0im 0.413973+0.0im 0.820712+0.0im 2.06099+0.0im
1.6024+0.0im 0.236729+0.0im -1.22807+0.0im -0.73624+0.0im 0.190207+0.0im -0.768012+0.0im
1.60426+0.0im -0.723955+0.0im 0.6624+0.0im 0.0153613+0.0im 1.13091+0.0im 0.700818+0.0im
-0.151597+0.0im 0.871951+0.0im 2.37298+0.0im -0.516958+0.0im -0.309972+0.0im 0.233701+0.0im
-1.35343+0.0im 2.15146+0.0im -0.918603+0.0im 0.552748+0.0im -0.521778+0.0im -2.15894+0.0im
julia> ds_2D(x) |> fft |> fftshift
6×6 Array{Complex{Float64},2}:
8.76707+0.0im 2.16954-1.31279im 4.13384+6.00899im -4.59698+0.0im 4.13384-6.00899im 2.16954+1.31279im
7.66118-0.173246im 10.8922-5.08887im 4.52256-1.21773im -0.234256+7.15146im -1.03317+0.540592im -2.43672-2.49465im
-5.51836+0.708964im 2.0933+7.65555im 8.69814+7.08368im -6.45624+1.60355im -8.06179+1.61042im 2.16754-1.71655im
2.84007+0.0im 2.38215+5.68463im 5.36487+3.4028im 3.29783+0.0im 5.36487-3.4028im 2.38215-5.68463im
-5.51836-0.708964im 2.16754+1.71655im -8.06179-1.61042im -6.45624-1.60355im 8.69814-7.08368im 2.0933-7.65555im
7.66118+0.173246im -2.43672+2.49465im -1.03317-0.540592im -0.234256-7.15146im 4.52256+1.21773im 10.8922+5.08887im
At the moment, it’s just a observation without any proof. If we look at the FFT of a random real matrix, we also see the same symmetry:
julia> fft(fftshift(randn((6,6))))
6×6 Array{Complex{Float64},2}:
-5.68469+0.0im -3.65677+0.370793im -1.80369+8.03579im -3.75849+0.0im -1.80369-8.03579im -3.65677-0.370793im
3.46143-5.19503im 1.6603+2.00749im 6.96219+3.45326im 2.1068-2.61896im -2.25073-0.424612im -2.34791-9.26965im
-0.272129-6.99491im 0.547095+3.00501im 12.6262+3.82233im 2.85939+5.94222im 6.08718-3.48567im -4.73672-6.57986im
6.47331+0.0im 5.59877+3.68285im 2.38269+3.51618im -0.935849+0.0im 2.38269-3.51618im 5.59877-3.68285im
-0.272129+6.99491im -4.73672+6.57986im 6.08718+3.48567im 2.85939-5.94222im 12.6262-3.82233im 0.547095-3.00501im
3.46143+5.19503im -2.34791+9.26965im -2.25073+0.424612im 2.1068+2.61896im 6.96219-3.45326im 1.6603-2.00749im
We can see that (1,1), (4, 1), (4,4) and (1,4) are purely real. This is achieved if we add the highest negative and highest positive frequency, and store it at the position of the highest negative one.
Where do these disagreements to your conclusions come from?