~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina5/tina-libs/tina/math/mathNum_fourier.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  *
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc.,
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  **********
 20  *
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/math/mathNum_fourier.c,v $
 23  * Date    :  $Date: 2005/01/23 19:10:21 $
 24  * Version :  $Revision: 1.6 $
 25  * CVS Id  :  $Id: mathNum_fourier.c,v 1.6 2005/01/23 19:10:21 paul Exp $
 26  *
 27  * Author  :  Legacy TINA
 28  *
 29  * Notes : Fast Fourier Transform
 30  *
 31  *********
 32 */
 33 /** 
 34  *  @file
 35  *  @brief  Fast Fourier Transform functions.   
 36  *
 37  *  See Numerical Recipes (3rd ed) Ch 12.2 pp 504-508 for more details regarding the algorithm.
 38  * 
 39 */
 40 
 41 #include "mathNum_fourier.h"
 42 
 43 #if HAVE_CONFIG_H
 44 #include <config.h>
 45 #endif
 46 
 47 #include <math.h>
 48 #include <tina/sys/sysDef.h>
 49 #include <tina/sys/sysPro.h>
 50 #include <tina/math/math_GenDef.h>
 51 
 52 void            fft_cmplx_inplace(Complex * z, int n)   /** assumes n is a power of 2 **/
 53 
 54 
 55 {
 56         int             i;
 57         double         *y = dvector_alloc(0, 2 * n);
 58 
 59         for (i = 0; i < n; i++)
 60         {
 61                 y[2 * i] = cmplx_re(z[i]);
 62                 y[2 * i + 1] = cmplx_im(z[i]);
 63         }
 64 
 65         fourier(y - 1, n, 1);
 66 
 67 
 68         for (i = 0; i < n; i++)
 69         {
 70                 cmplx_re(z[i]) = y[2 * i];
 71                 cmplx_im(z[i]) = y[2 * i + 1];
 72         }
 73 
 74         dvector_free(y, 0);
 75 }
 76 
 77 void            fft_inverse_cmplx_inplace(Complex * z, int n)   /** assumes n is a power of 2 **/
 78 
 79 
 80 {
 81         int             i;
 82         double         *y = dvector_alloc(0, 2 * n);
 83 
 84         for (i = 0; i < n; i++)
 85         {
 86                 y[2 * i] = cmplx_re(z[i]);
 87                 y[2 * i + 1] = cmplx_im(z[i]);
 88         }
 89 
 90         fourier(y - 1, n, -1);
 91 
 92         for (i = 0; i < n; i++)
 93         {
 94                 cmplx_re(z[i]) = y[2 * i] / n;
 95                 cmplx_im(z[i]) = y[2 * i + 1] / n;
 96         }
 97 
 98         dvector_free(y, 0);
 99 }
100 
101 /** assumes complex data is interlaced in data[1] ... data[2n] **/
102 
103 void            fourier(double *data, int nn, int isign)
104 {
105         int             n, mmax, m, j, istep, i;
106         double          wtemp, wr, wpr, wpi, wi, theta;
107         double          tempr, tempi;
108 
109         n = nn << 1;
110         j = 1;
111         for (i = 1; i < n; i += 2)
112         {
113                 if (j > i)
114                 {
115                         SWAP(double, data[j], data[i]);
116                         SWAP(double, data[j + 1], data[i + 1]);
117                 }
118                 m = n >> 1;
119                 while (m >= 2 && j > m)
120                 {
121                         j -= m;
122                         m >>= 1;
123                 }
124                 j += m;
125         }
126         mmax = 2;
127         while (n > mmax)
128         {
129                 istep = 2 * mmax;
130                 theta = TWOPI / (isign * mmax);
131                 wtemp = sin(0.5 * theta);
132                 wpr = -2.0 * wtemp * wtemp;
133                 wpi = sin(theta);
134                 wr = 1.0;
135                 wi = 0.0;
136                 for (m = 1; m < mmax; m += 2)
137                 {
138                         for (i = m; i <= n; i += istep)
139                         {
140                                 j = i + mmax;
141                                 tempr = wr * data[j] - wi * data[j + 1];
142                                 tempi = wr * data[j + 1] + wi * data[j];
143                                 data[j] = data[i] - tempr;
144                                 data[j + 1] = data[i + 1] - tempi;
145                                 data[i] += tempr;
146                                 data[i + 1] += tempi;
147                         }
148                         wr = (wtemp = wr) * wpr - wi * wpi + wr;
149                         wi = wi * wpr + wtemp * wpi + wi;
150                 }
151                 mmax = istep;
152         }
153 }
154 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.