1

I used the Accord Framework to perform 2D cross-correlation in C#, hence applying this formula : corr(a, b) = ifft(fft(a_and_zeros) * conj(fft(b_and_zeros))).

My output data are stored in a Complex[,] object, but the zero frequency component is shifted towards the top-left corner of the matrix, which is expected.

I have done the same thing with MATLAB previously and I used the fftshift function to re-center it. I, Alas, couldn't find any equivalent function in the Accord Framework to work with my C# code.

Is there a way to do it that would be more elegant than copying each quarter of the matrix in new matrixes and reorganizing them into the original matrix?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Trion
  • 115
  • 11

1 Answers1

0

I used the ILNumerics Framework :

Array<complex> convRes = fft2(out_if);
                    // Shift FFT output
                    int n_ = (int)convRes.Length;
                    int m_ = n_ / 2;
                    for (int s = 0; s < m_; s++)
                    {
                        complex temp_ = (complex)convRes[s];
                        convRes[s] = convRes[s + m_];
                        convRes[s + m_] = temp_;
                    }
mah
  • 1
  • This works only for even-sized arrays. If the size is odd, you cannot just swap elements, the movement is more complex. See here: https://stackoverflow.com/a/19752002/7328782 – Cris Luengo Mar 06 '23 at 07:22