Summary: Complex Fourier Series Written in 80x86 Asembler Using x86 FPU commands, no error checking, utilized in a Visual C++ 2005 function wrapper.
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 Federal Reserve Economic Data 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.
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; ; } }