Search code examples
c++armadillo

Armadillo ifftshift and ifft c++


Does anyone know how to do ifftshift + ifft (by row) for matrix in armadillo ?

I did in matlab : ifft(ifftshift(mat,2),[],2); where mat is matrix (3,18000);

I already tried to do something like in C++ :

arma::mat v3(3,18000); ... filled with the same values from Matlab ... 

static arma::cx_mat ifftshift(arma::cx_mat Axx)
{
    return arma::shift(arma::shift(Axx, -ceil(Axx.n_rows/2), 0), -ceil(Axx.n_cols/2), 1);
}

arma::ifft( ifftshift(v3).t() ).t();

The result is not the same like in Matlab.


Solution

  • The problem is likely that your ifftshift() shifts in both dimensions, the matlab command is only shifting in the second (row) dimension ifftshift(mat,2). Try to remove one shift in your function if you want the same behavior
    return arma::shift(Axx,-ceil(Axx.n_cols/2),1).