/**
* @brief origin shift (top-left <-> center)
* @author maeda
* @date 2008/09/10
*/
#include "DCexchange.h"
/**
* in-place DC exchange for 2dimensional data (top-left <-> center)
* this function works both odd/even size data
* @param data fft data
* @param cols column size of the data ( sometimes the size of x )
* @param rows row size of the data ( sometimes the size of y )
* @return true if succeed
*/
int maDCexchange2D( fftw_complex *data, int cols, int rows )
{
int i,j;
int p1,p2; // point position
int c2,r2; // temporary for cols/2,rows/2
double re,im; // temporary
if( data==NULL ) return false;
if( rows<0 || cols<0 ) return false;
c2 = cols/2;
r2 = rows/2;
for( j=0; j<r2; j++ ){
for( i=0; i<cols; i++ ){
// exchange p1( i, j ) <-> p2( (cols/2+i)%cols, rows/2+j )
p1 = j*cols + i;
p2 = (r2+j)*cols + (c2+i)%cols;
re = data[p1][0];
im = data[p1][1];
data[p1][0] = data[p2][0];
data[p1][1] = data[p2][1];
data[p2][0] = re;
data[p2][1] = im;
}
}
return true;
}
最終更新:2009年01月21日 20:48