matrixbase::FFTShift

Description

Shift this matrix placing the result in the matrix passed as an argument.

Syntax

int FFTShift( matrixbase & mbShifted, int nDim = -1 )

Parameters

mbShifted
[output] The output matrix in which the shifted matrix is returned
nDim
[input] Shifts can occur row wise (relative to the first dimension when nDim=1), column wise (relative to the second dimension when nDim=2), or relative to both or the first dimension and then the second dimension (when nDim=-1 default)

Return

Returns 0 on success and a non-zero error code on failure:

-1 means nDim is not -1, 1, or 2

-2 means Internal casting error

Examples

EX1

void matrixbase_FFTShift_ex1()
{ 
    matrix mSource = {
        {1,2,3},
        {4,5,6},
        {7,8,9}
    };
    int rc = mSource.FFTShift( mSource );
    if(rc!=0) 
        printf("Error: FFTShift failed. rc=%d\n", rc); 
    else{
        printf("The matrix is:\n");
        for(int ii=0; ii< mSource.GetNumRows(); ii++){
                        for(int jj=0; jj< mSource.GetNumCols(); jj++) 
                                printf("%g  ", mSource[ii][jj]);
                        printf("\r\n");
        }
    }
}

EX2

// Shifting matrix rows or columns
void matrixbase_FFTShift_ex2()
{
    int rc;
    
    matrix mSource = {
        {1,2,3},
        {4,5,6},
        {7,8,9}
    };
    matrix mShifted;
    int ii, jj;

    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    Matrix Mat1(MatLy1);
    Mat1 = mSource;
    printf("  The original matrix is %s.\n",Mat1.GetName());
    
    rc=mSource.FFTShift(mShifted); //relative to both or the first dimension and then the second dimension    
    if(rc!=0) 
        printf("  Error: FFTShift(nDim: default) failed.\n");
    else {
        MatrixPage MatPg2;
        MatPg2.Create("Origin");
        MatrixLayer MatLy2 = MatPg2.Layers(0);
        Matrix Mat2(MatLy2);
        printf("  %s is a shifted matrix relative to both 1st and 2nd dimensions.\n",Mat2.GetName());
        Mat2 = mShifted;
    }
    
    rc=mSource.FFTShift(mShifted, 1);  //relative to the first dimension   
    if(rc!=0) 
        printf("  Error: FFTShift(nDim=1) failed.\n");
    else {
        MatrixPage MatPg3;
        MatPg3.Create("Origin");
        MatrixLayer MatLy3 = MatPg3.Layers(0);
        Matrix Mat3(MatLy3);
        printf("  %s is a sfifted matrix relative to the 1st dimension.\n",Mat3.GetName());
        Mat3 = mShifted;
    }
    
    rc=mSource.FFTShift(mShifted, 2);  //relative to the second dimension   
    if(rc!=0) 
        printf("  Error: FFTShift(nDim=2) failed.\n");
    else {
        MatrixPage MatPg4;
        MatPg4.Create("Origin");
        MatrixLayer MatLy4 = MatPg4.Layers(0);
        Matrix Mat4(MatLy4);
        printf("  %s is a sfifted matrix relative to the 2nd dimension.\n",Mat4.GetName());
        Mat4 = mShifted;
    }
}

Remark

Shift this matrix placing the result in the matrix passed as an argument. Shifts can occur row wise or relative to the first dimension (nDim=1), column wise or relative to the second dimension (nDim=2), or relative to both or the first dimension and then the second dimension (nDim=-1 default). The result matrix and this matrix can be the same (i.e. m1.FFTShift(m1);).

See Also

matrixbase::IFFTShift

header to Include

origin.h