### Question:
SpectralUtils { public static ComplexDoubleMatrix fftshift(ComplexDoubleMatrix inMatrix) { if (!inMatrix.isVector()) { logger.error("ifftshift: only vectors"); throw new IllegalArgumentException("ifftshift: works only for vectors!"); } final int cplxMatrixLength = 2*inMatrix.length; ComplexDoubleMatrix outMatrix = new ComplexDoubleMatrix(inMatrix.rows, inMatrix.columns); final int start = (int) (Math.floor((double) cplxMatrixLength / 2) + 1); System.arraycopy(inMatrix.data, start, outMatrix.data, 0, cplxMatrixLength - start); System.arraycopy(inMatrix.data, 0, outMatrix.data, cplxMatrixLength - start, start); return outMatrix; }  static void fft1D_inplace(ComplexDoubleMatrix vector, final int fftLength); static void invfft1D_inplace(ComplexDoubleMatrix vector, final int fftLength); static ComplexDoubleMatrix fft1D(ComplexDoubleMatrix vector, final int fftLength); static ComplexDoubleMatrix invfft1D(ComplexDoubleMatrix vector, final int fftLength); static ComplexDoubleMatrix fft(ComplexDoubleMatrix inMatrix, final int dimension); static ComplexDoubleMatrix invfft(ComplexDoubleMatrix inMatrix, final int dimension); static void fft_inplace(ComplexDoubleMatrix inMatrix, int dimension); static void invfft_inplace(ComplexDoubleMatrix inMatrix, int dimension); static void fft2D_inplace(ComplexDoubleMatrix A); static ComplexDoubleMatrix fft2D(ComplexDoubleMatrix inMatrix); static void fft2D_inplace(DoubleMatrix A); static void invfft2D_inplace(ComplexDoubleMatrix A); static ComplexDoubleMatrix invfft2d(ComplexDoubleMatrix inMatrix); static ComplexDoubleMatrix fftshift(ComplexDoubleMatrix inMatrix); static DoubleMatrix fftshift(DoubleMatrix inMatrix); static void fftshift_inplace(ComplexDoubleMatrix inMatrix); static void fftshift_inplace(DoubleMatrix inMatrix); static ComplexDoubleMatrix ifftshift(ComplexDoubleMatrix inMatrix); static DoubleMatrix ifftshift(DoubleMatrix inMatrix); static void ifftshift_inplace(ComplexDoubleMatrix inMatrix); static void ifftshift_inplace(DoubleMatrix inMatrix);  }### Answer:
@Test public void testFftshiftDouble() throws Exception { final DoubleMatrix matrix_EXPECTED = new DoubleMatrix(vector_EXPECTED); final DoubleMatrix matrixShift_EXPECTED = new DoubleMatrix(shiftVector_EXPECTED); DoubleMatrix matrixShift_ACTUAL = SpectralUtils.fftshift(matrix_EXPECTED); Assert.assertEquals(matrixShift_EXPECTED,matrixShift_ACTUAL); }
@Test public void testFftshiftComplex() throws Exception { ComplexDoubleMatrix matrixCplx_EXPECTED = new ComplexDoubleMatrix(new DoubleMatrix(vector_EXPECTED), new DoubleMatrix(vector_EXPECTED)); ComplexDoubleMatrix shiftMatrixCplx_EXPECTED = new ComplexDoubleMatrix(new DoubleMatrix(shiftVector_EXPECTED), new DoubleMatrix(shiftVector_EXPECTED)); ComplexDoubleMatrix matrixShiftCplx_ACTUAL = SpectralUtils.fftshift(matrixCplx_EXPECTED); Assert.assertEquals(shiftMatrixCplx_EXPECTED, matrixShiftCplx_ACTUAL); }