kube-gustavson-fft.hpp

Go to the documentation of this file.
00001 #ifndef KUBE_GUSTAVSON_HPP
00002 #define KUBE_GUSTAVSON_HPP
00003 #include <cmath>
00004 /**************************************************************
00005  * kube_fft.hpp
00006  *
00007  * Forward and inverse discrete 2D Fourier transforms.
00008  *
00009  * This software is in the public domain.
00010  *
00011  **************************************************************/
00012 
00013 struct COMPLEX {
00014  float re; float im;
00015  // Operatoren zur einfacheren Benutzung
00016  COMPLEX (float real=0.0, float imag=0.0) : re(real), im(imag) {}
00017  COMPLEX (const COMPLEX& c) : re(c.re), im(c.im) {}
00018  
00019  COMPLEX& operator = (float val) {
00020    re=val;
00021    return *this;
00022  }
00023 
00024  COMPLEX& operator = (const COMPLEX& c) {
00025    re=c.re;
00026    im=c.im;
00027    return *this;
00028  }  
00029  
00030  COMPLEX& operator -= (const COMPLEX& c) {
00031    re-=c.re;
00032    im-=c.im;
00033    return *this;
00034  }
00035  
00036  COMPLEX operator - (const COMPLEX& c) const {
00037    COMPLEX erg(re-c.re, im-c.im);
00038    return erg;
00039  }
00040  
00041  COMPLEX& operator += (const COMPLEX& c) {
00042    re+=c.re;
00043    im+=c.im;
00044    return *this;
00045  }
00046  
00047  COMPLEX operator + (const COMPLEX& c) const {
00048    COMPLEX erg(re+c.re, im+c.im);
00049    return erg;
00050  }
00051 
00052  COMPLEX& operator /= (const COMPLEX& c) {
00053     const float r =  re * c.re + im * c.im;
00054     const float n =  c.re*c.re+c.im*c.im;
00055     im = im * c.re - re * c.im / n;
00056     re = r / n;
00057     return *this;
00058  }
00059  
00060  COMPLEX operator / (const COMPLEX& c) const {
00061    COMPLEX erg(*this);
00062    erg/=c;
00063    return erg;
00064  }
00065 
00066  bool operator != (const COMPLEX& c) const {
00067   
00068     return ((re!=c.re) || (im!=c.im)); 
00069  }
00070 
00071 };
00072 
00073 inline COMPLEX operator * (const COMPLEX& c, float mult) {
00074   COMPLEX erg;
00075   erg.re=c.re*mult;
00076   erg.im=c.im*mult;
00077   return erg;
00078 }
00079 
00080 inline COMPLEX operator * (float mult, const COMPLEX& c) {
00081   COMPLEX erg;
00082   erg.re=c.re*mult;
00083   erg.im=c.im*mult;
00084   return erg;
00085 }
00086 
00087 // Multiplikation mit einer anderen komplexen Zahl
00088 inline COMPLEX operator *(const COMPLEX& a, const COMPLEX& b) {
00089   COMPLEX c;
00090   c.re= a.re*b.re - a.im*b.im;
00091   c.im= a.re*b.im + a.im*b.re;
00092   return c;
00093 }  
00094 
00095 
00096 inline COMPLEX& operator *= (COMPLEX& c, float mult) {
00097   c.re*=mult;
00098   c.im*=mult;
00099   return c;
00100 }
00101 
00102 inline float abs(const COMPLEX& c) {
00103   return sqrt(c.re*c.re+c.im*c.im);
00104 }  
00105 
00106 inline float norm(const COMPLEX& c) {
00107   return c.re*c.re+c.im*c.im;
00108 }
00109 
00110 
00111 struct DCOMPLEX {double re; double im;};
00112 
00113 #ifndef ERROR
00114 #define ERROR -1
00115 #define NO_ERROR 0
00116 #endif
00117 
00118 #define FFT_FORWARD     0
00119 #define FFT_INVERSE 1
00120 
00121 #define PI      3.1415926535897932
00122 #define TWOPI   6.2831853071795865 /* 2.0 * PI */
00123 #define HALFPI  1.5707963267948966 /* PI / 2.0 */
00124 #define PI8     0.392699081698724 /* PI / 8.0 */
00125 #define RT2     1.4142135623731  /* sqrt(2.0) */
00126 #define IRT2    0.707106781186548  /* 1.0/sqrt(2.0) */
00127 
00128 /* Perform forward 2D transform on a COMPLEX array. */
00129 extern int forward_fft2f(COMPLEX *array, int rows, int cols);
00130 
00131 /* Perform inverse 2D transform on a COMPLEX array. */
00132 extern int inverse_fft2f(COMPLEX *array, int rows, int cols);
00133 
00134 /* Perform forward 2D transform on a DCOMPLEX array. */
00135 extern int forward_fft2d(DCOMPLEX *array, int rows, int cols);
00136 
00137 /* Perform inverse 2D transform on a DCOMPLEX array. */
00138 extern int inverse_fft2d(DCOMPLEX *array, int rows, int cols);
00139 
00140 #endif

Generated on Fri Jul 24 12:49:17 2009 for Xgrayimg Library by  doxygen 1.5.5