2.2.3.9.38 matrixbase::GetPhase

Description

Get the phase angle matrix, in radians, of the Complex matrix.

Syntax

BOOL GetPhase( matrix & mPhase )

Parameters

mPhase
[output] matrix containing the phase angle matrix for this Complex matrix

Return

Returns TRUE on successful exit and FALSE on failure.

Examples

EX1

void matrixbase_GetPhase_ex1()
{
    int ii,jj;
    matrix mAng;
    matrix<complex> mComplex = {
        { 1,  1+1i,  1i, -1+1i},
        {-2, -2-2i, -2i,  2-1i},
        { 0,  99,    99,  99  }
    };
    for(ii=0; ii<3; ii++)
        for(jj=0; jj<4; jj++) 
            if(mComplex[ii][jj]==99)
                mComplex[ii][jj]=NANUM;
    int rc = mComplex.GetPhase( mAng );
    if(!rc) 
        printf("Error: GetPhase failed. rc=%d\n", rc); 
    else{
    	printf("The GetPhase matrix is:\n");
        for(int ii=0; ii< mAng.GetNumRows(); ii++){
			for(int jj=0; jj< mAng.GetNumCols(); jj++) 
				printf("%g  ", mAng[ii][jj]);
			printf("\r\n");
        }
    }
}

EX2

// Get the phase and amplitude matrix of a matrix
void matrixbase_GetPhase_ex2()
{
    int ii,jj;

    matrix<complex> mComplex = {
        { 1,  1+1i,  1i, -1+1i},
        {-2, -2-2i, -2i,  2-1i},
        { 0,  99,    99,  99  }
    };
    for(ii=0; ii<3; ii++)
        for(jj=0; jj<4; jj++) 
            if(mComplex[ii][jj]==99)
                mComplex[ii][jj]=NANUM;
    mComplex[2][3]=NANUM;
//  Input matrix is:
//        { 1,  1+1i,  1i, -1+1i}
//        {-2, -2-2i, -2i,  2-2i}
//        { 0,  --,    --,  --  }
//  Output phase matrix is:
//        {0        0.7854   1.5708  2.35619 }
//        {3.14159 -2.35619 -1.5708 -0.463648}
//        {0        --       --      --      }
//    that is,
//        {0   PI/4    PI/2  PI*3/4}
//        {PI -PI*3/4 -PI/2 -PI/4  }
//        {0   --      --    --    }

//  Output amplitude matrix is:
//        {1  1.41421  1    1.41421}
//        {2  2.82843  2    2.82843}
//        {0  --       --   --     }
//    that is,
//        {1  sqrt(2)    1    sqrt(2)  }
//        {2  2*sqrt(2)  2    2*sqrt(2)}
//        {0  --         --   --       }

    matrix mAmp1, mAng1;
    PageBase pgbase;

    MatrixPage MatPg1;
    MatPg1.Create("Origin");
    MatrixLayer MatLy1 = MatPg1.Layers(0);
    MatLy1.SetInternalData(FSI_COMPLEX);   // Set the internal data type to complex
    Matrix<complex> Mat1(MatLy1);
    pgbase = Project.Pages(); // Get the active page
    pgbase.Rename("Original");
    Mat1 = mComplex;
    printf("  Original matrix is %s.\n",Mat1.GetName());
    printf("\n");
    
    MatrixPage MatPg2;
    MatPg2.Create("Origin");
    MatrixLayer MatLy2 = MatPg2.Layers(0);
    Matrix Mat2(MatLy2);
    pgbase = Project.Pages(); // Get the active page
    pgbase.Rename("Phase");

    int rc=mComplex.GetPhase(mAng1);      // Get phase values

    if(!rc) 
        printf("  Error: GetPhase failed.\n");
    else {
        Mat2 = mAng1;
        printf("  Phase matrix is %s.\n",Mat2.GetName());
        printf("  Observe that -PI<angle<=PI.\n"); 
        printf("  Observe that GetPhase(0)=0, and GetPhase(--)=--.\n"); 
    }
    printf("\n");
    
    MatrixPage MatPg3;
    MatPg3.Create("Origin");
    MatrixLayer MatLy3 = MatPg3.Layers(0);
    Matrix Mat3(MatLy3);
    pgbase = Project.Pages(); // Get the active page
    pgbase.Rename("Amplitude");

    rc=mComplex.GetAmplitude(mAmp1);      // Get amplitude values

    if(!rc) 
        printf("  Error: GetAmplitude failed.\n");
    else {
        Mat3 = mAmp1;
        printf("  Amplitude amplitude matrix is %s.\n",Mat3.GetName());
        printf("  Observe that 0<=Amplitude.\n"); 
        printf("  Observe that GetAmplitude(--)=--.\n"); 
    }
}

Remark

Get the phase angle matrix, in radians, of the Complex matrix.

When the angle is Theta, -PI<Theta<=PI .

Causes a runtime error if the underlying base type of the matrix is not Complex.

See Also

matrixbase::GetReal, matrixbase::GetImaginary, matrixbase::GetAmplitude, matrixbase::Conjugate, matrixbase::Cross, matrixbase::Inverse, matrixbase::MakeComplex

Header to Include

origin.h