Mercurial > hg > x
diff fft.h @ 1:6422640a802f
first upload
author | Wen X <xue.wen@elec.qmul.ac.uk> |
---|---|
date | Tue, 05 Oct 2010 10:45:57 +0100 |
parents | |
children | 5f3c32dc6e17 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fft.h Tue Oct 05 10:45:57 2010 +0100 @@ -0,0 +1,82 @@ +#ifndef fftH +#define fftH + +/* + fft.cpp - fast Fourier and cosine transforms + + Arguments of the function in this unit roughly follow the following rules: + Wid : size of transform + Order : log2(Wid) + W : FFT buffer: twiddle factors, standard size Wid/2 + X : FFT buffer: data buffer, standard size Wid + bitinv: FFT buffer: table of bit-inversed integers, standard size Wid + Window: window function, standard size Wid + spec : complex spectrogram + Amp : amplitude spectrogram + Arg : phase spectrogram + prefix h- : half-size + prefix q- : quarter-size +*/ + + +#include <math.h> +#include "xcomplex.h" +#include "align8.h" + +//--------------------------------------------------------------------------- +/* + macro AllocateFFTBuffer: allocates FFT buffers X and W of given length with an extra LDATA buffer the + right size for hosting such arrays as the standard-size window function or output amplitude spectrum. + + This macro allocates buffer with 64-bit alignment, which must be freed with free8() or FreeFFTBuffer + macro. +*/ +#define AllocateFFTBuffer(_WID, _LDATA, _W, _X) \ + double *_LDATA=(double*)malloc8(sizeof(double)*_WID*4); \ + cdouble *_X=(cdouble*)&_LDATA[_WID]; \ + cdouble *_W=(cdouble*)&_X[_WID]; \ + SetTwiddleFactors(_WID, _W); +#define FreeFFTBuffer(_LDATA) free8(_LDATA); + +//--compelx FFT and IFFT----------------------------------------------------- +void CFFTCbii(int Order, cdouble* W, cdouble* X); //complex FFT subroutine after bit-inversed ordering +void CFFTC(int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex FFT, compact in-place +void CFFTC(cdouble* Input, double* Amp, double *Arg, int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex FFT +void CFFTCW(double* Window, int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex FFT with window, compact in-place +void CFFTCW(cdouble* Input, double* Window, double *Amp, double *Arg, int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex FFT with window +void CIFFTC(int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex IFFT, compact in-place +void CIFFTC(cdouble* Input, int Order, cdouble* W, cdouble* X, int* bitinv=0); //complex IFFT + +//--real FFT and IFFT-------------------------------------------------------- +void RFFTC_ual(double* Input, double* Amp, double* Arg, int Order, cdouble* W, cdouble* X, int* hbitinv=0); //real-to-complex FFT +void RFFTC_ual_old(double* Input, double *Amp, double *Arg, int Order, cdouble* W, double* XR, double* XI, int* bitinv=0); //depreciated +void RFFTCW(double* Input, double* Window, double *Amp, double *Arg, int Order, cdouble* W, cdouble* X, int* hbitinv=0); //real-to-complex FFT with window, double-type input +void RFFTCW(__int16* Input, double* Window, double *Amp, double *Arg, int Order, cdouble* W, cdouble* X, int* hbitinv=0); //real-to-complex FFT with window, __int16 input +void CIFFTR(cdouble* Input, int Order, cdouble* W, double* X, int* hbitinv=0); //complex-to-real IFFT + +/* + macro RFFTC: was defined as RFFTC_ual (literally "unaligned RFFTC") enveloped by ALIGN8(). However, as + ALIGN8() is currently disabled for lack of compiler support, RFFTC is equivalent to RFFTC_ual. +*/ +#define RFFTC(Input, Amp, Arg, Order, W, X, hbitinv) RFFTC_ual(Input, Amp, Arg, Order, W, X, hbitinv); + +//--MFT---------------------------------------------------------------------- +void CMFTC(double* xR, double* xI, int Order, cdouble** X, cdouble* W); //complex fast multiresolution FT + +//--DCT and IDCT------------------------------------------------------------- +void RDCT1(double* Input, double* Output, int Order, cdouble* qW, cdouble* qX, int* qbitinv=0); //DCT1 +void RDCT4(double* Input, double* Output, int Order, cdouble* hW, cdouble* hX, int* hbitinv=0); //DCT4 +void RIDCT1(double* Input, double* Output, int Order, cdouble* qW, cdouble* qX, int* qbitinv=0); //IDCT1 +void RIDCT4(double* Input, double* Output, int Order, cdouble* hW, cdouble* hX, int* hbitinv=0); //IDCT4 + +//--LCT---------------------------------------------------------------------- +void RLCT(double** spec, double* data, int Count, int Order, int wid, double* g); //local cosine transform +void RILCT(double* data, double** spec, int Fr, int Order, int wid, double* g); //inverse local cosine transform + +//--tools-------------------------------------------------------------------- +double Atan2(double, double); +int* CreateBitInvTable(int Order); //creates table of bit-inversed integers +void SetTwiddleFactors(int N, cdouble* w); //set twiddle factors + + +#endif