### Question:
PhaseFilter { private void constructRectKernel() { final DoubleMatrix kernel1d = new DoubleMatrix(1, blockSize); final int overlapLines = (int) Math.floor(kernelArray.length / 2.); for (int ii = -overlapLines; ii <= overlapLines; ++ii) { kernel1d.put(0, (ii + blockSize) % blockSize, kernelArray[ii + overlapLines]); } kernel2d = new ComplexDoubleMatrix(LinearAlgebraUtils.matTxmat(kernel1d, kernel1d)); SpectralUtils.fft2D_inplace(kernel2d); kernel2d.conji(); } PhaseFilter(String method, ComplexDoubleMatrix data, int blockSize, int overlap, double[] kernelArray, float goldsteinAlpha); void setMethod(String method); void setData(ComplexDoubleMatrix data); ComplexDoubleMatrix getData(); void setBlockSize(int blockSize); void setOverlap(int overlap); void setKernelArray(double[] kernelArray); void setGoldsteinAlpha(float goldsteinAlpha); void setKernel2d(ComplexDoubleMatrix kernel2d); void filter(); static DoubleMatrix arrangeKernel2d(DoubleMatrix kernel2dIn, final double scaleFactor); @Deprecated static DoubleMatrix smoothSpace(final DoubleMatrix data, final int blockSize);  }### Answer:
@Test public void testSpatialConvFilter() throws Exception { String kernelFileName = testDirectorySpatial + "kernel2d.cr4.swap"; ComplexDoubleMatrix kernel2d_EXPECTED = readCplxFloatData(kernelFileName, 128, 128); final double[] kernel = {0.2, 0.2, 0.2, 0.2, 0.2}; DoubleMatrix kernel2d = PhaseFilterUtils.constructRectKernel(128, kernel); ComplexDoubleMatrix kernel2d_ACTUAL = new ComplexDoubleMatrix(kernel2d); SpectralUtils.fft2D_inplace(kernel2d_ACTUAL); kernel2d_ACTUAL.conji(); Assert.assertArrayEquals(kernel2d_EXPECTED.real().toArray(), kernel2d_ACTUAL.real().toArray(), DELTA_03); Assert.assertArrayEquals(kernel2d_EXPECTED.imag().toArray(), kernel2d_ACTUAL.imag().toArray(), DELTA_03); }
@Test public void testSpatialConv() throws Exception { String cplxDataFileName = testDirectorySpatial + "data_input.cr4.swap"; ComplexDoubleMatrix cplxData = readCplxFloatData(cplxDataFileName, 128, 512); String cplxDataFilteredFileName = testDirectorySpatial + "data_filtered.cr4.swap"; ComplexDoubleMatrix cplxDataFilt_EXPECTED = readCplxFloatData(cplxDataFilteredFileName, 128, 512); final double[] kernel = {0.2, 0.2, 0.2, 0.2, 0.2}; DoubleMatrix kernel2d = PhaseFilterUtils.constructRectKernel(128, kernel); ComplexDoubleMatrix kernel2d_ACTUAL = new ComplexDoubleMatrix(kernel2d); SpectralUtils.fft2D_inplace(kernel2d_ACTUAL); kernel2d_ACTUAL.conji(); int overlap = 2; ComplexDoubleMatrix cplxDataFilt_ACTUAL = PhaseFilterUtils.convbuffer(cplxData, kernel2d_ACTUAL, overlap); Assert.assertArrayEquals(cplxDataFilt_EXPECTED.real().toArray(), cplxDataFilt_ACTUAL.real().toArray(), DELTA_01); Assert.assertArrayEquals(cplxDataFilt_EXPECTED.imag().toArray(), cplxDataFilt_ACTUAL.imag().toArray(), DELTA_01); }