Matrix MatAbsPow2(Matrix2& mat) { Matrix out = ZMatrix(mat.real.size1(), mat.real.size2()); for(int i = 0; i < out.size1(); ++i) { for(int j = 0; j < out.size2(); ++j) { out(i, j) = mat.real(i, j) * mat.real(i, j) + mat.imge(i, j) * mat.imge(i, j); } } return out; }
Matrix ifft2_1D(const Matrix2& mat) { fftw_complex* data_in; fftw_complex* ifft; fftw_plan plan_b; data_in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * mat.imge.size1()); ifft = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * mat.imge.size1()); plan_b = fftw_plan_dft_1d(mat.imge.size1(), data_in, ifft, FFTW_BACKWARD, FFTW_ESTIMATE); for(int i = 0, k = 0; i < mat.imge.size1(); ++i) { data_in[k][0] = mat.real(i, 0); data_in[k][1] = mat.imge(i, 0); k++; } /* perform FFT */ fftw_execute(plan_b); double normal_val = 1.0 / (mat.imge.size1() * mat.imge.size2()); Matrix out(mat.imge.size1(), mat.imge.size2()); for(int i = 0, k = 0; i < mat.imge.size1(); ++i) { for(int j = 0; j < mat.imge.size2(); ++j) { out(i, j) = ifft[k][0] * normal_val; k++; } } fftw_destroy_plan(plan_b); fftw_free(data_in); fftw_free(ifft); return out; }