Skip to main content
3 of 5
added 2334 characters in body
Cedron Dawg
  • 7.6k
  • 2
  • 9
  • 24

If you are seeing half the magnitude (amplitude is the height of the signal, magnitude is the size of a complex value), that means you are using a 1/N normalized DFT (BTW, my preference). The sum will be the same (since the other half is orthogonal), you are just dividing it by twice as large of a number. You should also find that all the even numbered bins are zero and the odd bins have values. This is because the even bin sinusoids split evenly on your half way mark and the odd ones are integer and a half and therefore no longer orthogonal on those regions with your signal.

Hope this helps,

Ced


Followup

Demo for MBaz:

The output is:

Full: -0.000000 + i * 0.000000
Half: 230.265249 + i * 97.354586
Half Magnitude = 250.000000
Half Phase     = 0.400000

The code is:

#include <math.h>
#include <stdio.h>

//===============================================
int main( int argCount, char* argValues[] )
{

        double theSignal[1000];

        double theReal[1000];
        double theImag[1000];

        double theAngleFactor = 2.0 * M_PI / 1000;

        double theFrequency = 50.0;  // Cycles per frame

//--- Build the Arrays

        double thePhi = 0.4;

        for( int n = 0; n < 1000; n++ )
        {
            double theAngle = (double) n
                            * theAngleFactor;

            double theArg = theFrequency * theAngle;

            if( n < 500 )
            {
                theSignal[n] = cos( theArg + thePhi );
            }
            else
            {
                theSignal[n] = -cos( theArg + thePhi );
            }

            theReal[n] =  cos( theArg );
            theImag[n] = -sin( theArg );

        }

//--- Calculate the Bin Value

        double theBinReal = 0.0;
        double theBinImag = 0.0;

        for( int n = 0; n < 1000; n++ )
        {
            theBinReal += theSignal[n] * theReal[n];
            theBinImag += theSignal[n] * theImag[n];
        }

//--- Calculate for Half the Interval

        double theHalfReal = 0.0;
        double theHalfImag = 0.0;

        for( int n = 0; n < 500; n++ )
        {
            theHalfReal += theSignal[n] * theReal[n];
            theHalfImag += theSignal[n] * theImag[n];
        }

        double theMag = sqrt( theHalfReal * theHalfReal
                            + theHalfImag * theHalfImag );

        double thePhase = atan2( theHalfImag, theHalfReal );

//--- Show the Results

        printf( "Full: %f + i * %f\n" ,
                theBinReal, theBinImag );

        printf( "Half: %f + i * %f\n" ,
                theHalfReal, theHalfImag );

        printf( "Half Magnitude = %f\n", theMag );
        printf( "Half Phase     = %f\n", thePhase );
}
//===============================================
Cedron Dawg
  • 7.6k
  • 2
  • 9
  • 24