<?xml version="1.0" encoding="utf-8"?>
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:q="http://cnx.rice.edu/qml/1.0" id="new" module-id="" cnxml-version="0.6">
  <title>Complex Fourier Series Data Analysis Using C++ and x86 Inline Assembler</title>
  <metadata xmlns:md="http://cnx.rice.edu/mdml/0.4">
  <!-- WARNING! The 'metadata' section is read only. Do not edit below.
       Changes to the metadata section in the source will not be saved. -->
  <md:content-id>m15993</md:content-id>
  <md:title>Complex Fourier Series Data Analysis Using C++ and x86 Inline Assembler</md:title>
  <md:version>1.4</md:version>
  <md:created>2008/04/13 09:36:34 GMT-5</md:created>
  <md:revised>2009/05/07 03:11:22.931 GMT-5</md:revised>
  <md:authorlist>
    <md:author id="orioncs">
        <md:firstname>Marc</md:firstname>
        <md:othername>David</md:othername>
        <md:surname>Balke</md:surname>
        <md:fullname>Marc Balke</md:fullname>
        <md:email>balke_m@hotmail.com</md:email>
    </md:author>
  </md:authorlist>
  <md:maintainerlist>
    <md:maintainer id="orioncs">
        <md:firstname>Marc</md:firstname>
        <md:othername>David</md:othername>
        <md:surname>Balke</md:surname>
        <md:fullname>Marc Balke</md:fullname>
        <md:email>balke_m@hotmail.com</md:email>
    </md:maintainer>
  </md:maintainerlist>
  <md:license href="http://creativecommons.org/licenses/by/2.0/"/>
  <md:licensorlist>
    <md:licensor id="orioncs">
        <md:firstname>Marc</md:firstname>
        <md:othername>David</md:othername>
        <md:surname>Balke</md:surname>
        <md:fullname>Marc Balke</md:fullname>
        <md:email>balke_m@hotmail.com</md:email>
    </md:licensor>
  </md:licensorlist>
  <md:keywordlist>
    <md:keyword>80x86 Assembler</md:keyword>
    <md:keyword>Computer Programming</md:keyword>
    <md:keyword>Data Analysis</md:keyword>
    <md:keyword>Fourier Series</md:keyword>
    <md:keyword>Visual C++</md:keyword>
  </md:keywordlist>
  <md:subjectlist>
    <md:subject>Mathematics and Statistics</md:subject>
  </md:subjectlist>
  <md:abstract>Complex Fourier Series Written in 80x86 Asembler Using x86 FPU commands, no error checking, utilized in a Visual C++ 2005 function wrapper.</md:abstract>
  <md:language>en</md:language>
  <!-- WARNING! The 'metadata' section is read only. Do not edit above.
       Changes to the metadata section in the source will not be saved. -->
</metadata>

<content>
    <para id="element-236">This Function is a small part of a larger data analysis program utilizing Visual C# and Visual C++ to analyze Stock Markets, Stocks, Funds, Options and US Federal Reserve Data.

   Stock Market, Individual Stocks, Options, Mutual Fund Data or <link url="http://research.stlouisfed.org/fred2/"> Federal Reserve Economic Data </link> can be analyzed. Input to the function is a double precision (IEEE 754 stanard) vector, containing of one of the data streams from a given series ( Market, Stock, Option, Mutual Fund, FRED ). The start and end pointers into the input vector are required, along with the sample frequency ( Minimum 2x the number of data points supplied ). Output consists of 3 vectors -- Frequency, Amplitude and Phase Shift.

   By using the Complex Fourier Function, we are able to break down the input data into a Constant ( DC ) component, and variable Frequency, Amplitude and Phase Shift components. Amplitude results of 0 are of no significance. When reconstructed, the data stream should contain future values for the given input data. The idea is to build a more accurate time series forcasting model.</para><para id="delete_me"><!-- Insert module text here -->


FOURIERDEV_API void DFT64(double* , double* , double* , double* , int );
FOURIERDEV_API void DFT32(float* , float* , float* , float* , int );



FOURIERDEV_API void DFT64(double* dxx, double* cxx, double* th, double* fr, int cnt)
{
	double dxe, cxe, theta, freq, rad, pi2, dne, dnx, cv, cvc;
	int i, j, n;

	n = cnt;
	rad = 360.0;

	__asm
	{
		;
		finit;
		;
		fldpi;
		fldpi;
		fadd;
		fstp		pi2;
		;
		fld			rad;
		fdiv		pi2;
		fstp		rad;
		;
		fld			pi2;
		fchs;
		fidiv		n;
		fstp		pi2;
		;
		mov			i,0;
		;
Loop1:	;
		;
		fild		i;
		fmul		pi2;
		fstp		dnx;
		;
	}

	dxe = *(dxx + i);

	__asm
	{
		;
		fldz;
		fstp		cv;
		;
		mov			j,0;
		;
Loop2:	;
		;
		fild		j;
		fmul		dnx;
		fstp		dne;
		;
	}

	cxe = exp(dne);

	__asm
	{
		;
		fld			cxe;
		fmul		dxe;
		fadd		cv;
		fstp		cv;
		;
		inc			j;
		mov			eax,j;
		cmp			eax,n;
		jl			Loop2;
		;
		fld			cv;
		fcos;
		fmul		cv;
		fdiv		cv;
		fstp		cvc;
		;
	}

	theta = acos(cvc);
	
	__asm
	{
		;
		fld			theta;
		fmul		rad;
		fstp		theta;
		;
		fild		i;
		fstp		freq;
		;
	}

	*(cxx + i) = cv;
	*(th + i) = theta;
	*(fr + i) = freq;

	__asm
	{
		;
		inc			i;
		mov			eax,i;
		cmp			eax,n;
		jl			Loop1;
		;
	}

}

FOURIERDEV_API void DFT32(float* dxx, float* cxx, float* th, float* fr, int cnt)
{
	float dxe, cxe, theta, freq, rad, pi2, dne, dnx, cv, cvc;
	int i, j, n;

	n = cnt;
	rad = 360.0;

	__asm
	{
		;
		finit;
		;
		fldpi;
		fldpi;
		fadd;
		fstp		pi2;
		;
		fld			rad;
		fdiv		pi2;
		fstp		rad;
		;
		fld			pi2;
		fchs;
		fidiv		n;
		fstp		pi2;
		;
		mov			i,0;
		;
Loop1:	;
		;
		fild		i;
		fmul		pi2;
		fstp		dnx;
		;
	}

	dxe = *(dxx + i);

	__asm
	{
		;
		fldz;
		fstp		cv;
		;
		mov			j,0;
		;
Loop2:	;
		;
		fild		j;
		fmul		dnx;
		fstp		dne;
		;
	}

	cxe = exp(dne);

	__asm
	{
		;
		fld			cxe;
		fmul		dxe;
		fadd		cv;
		fstp		cv;
		;
		inc			j;
		mov			eax,j;
		cmp			eax,n;
		jl			Loop2;
		;
		fld			cv;
		fcos;
		fmul		cv;
		fdiv		cv;
		fstp		cvc;
		;
	}

	theta = acos(cvc);
	
	__asm
	{
		;
		fld			theta;
		fmul		rad;
		fstp		theta;
		;
		fild		i;
		fstp		freq;
		;
	}

	*(cxx + i) = cv;
	*(th + i) = theta;
	*(fr + i) = freq;

	__asm
	{
		;
		inc			i;
		mov			eax,i;
		cmp			eax,n;
		jl			Loop1;
		;
	}
}

</para>   
  </content>
  
</document>
