1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
20 #include "AliTPCMonitorFFT.h"
23 ClassImp(AliTPCMonitorFFT)
25 //__________________________________________________________________
26 AliTPCMonitorFFT::AliTPCMonitorFFT()
31 //__________________________________________________________________
32 AliTPCMonitorFFT::~AliTPCMonitorFFT()
38 //__________________________________________________________________
39 Int_t AliTPCMonitorFFT::ComplexRadix2ForwardWrap(Double_t* data, Int_t stride, size_t n)
42 // Wrapper function for forward fourier transformation
44 Int_t ret = ComplexRadix2TransformWrap(data,stride,n,direction);
48 //__________________________________________________________________
49 Int_t AliTPCMonitorFFT::ComplexRadix2BackwardWrap(Double_t* data,Int_t stride, size_t n)
51 // Wrapper function for backward fourier transformation
53 Int_t ret = ComplexRadix2TransformWrap(data,stride,n,direction);
57 //__________________________________________________________________
58 Int_t AliTPCMonitorFFT::ComplexRadix2InverseWrap(Double_t* data,Int_t stride, size_t n)
60 // Wrapper function for inverse fourier transformation
62 Int_t ret = ComplexRadix2TransformWrap(data,stride,n,direction);
69 const Double_t norm = 1.0 / n;
71 for (i = 0; i < n; i++)
73 REAL(data,stride,i) *= norm;
74 IMAG(data,stride,i) *= norm;
80 //__________________________________________________________________
81 Int_t AliTPCMonitorFFT::ComplexRadix2TransformWrap(Double_t* data, Int_t stride, size_t n, Int_t sign)
83 // Wrapper function for fourier transformation depending on sign ( forward 1;backward -1 )
90 if (n == 1) /* identity operation */
94 /* make sure that n is a power of 2 */
96 result = FFTBinaryLogn(n) ;
100 cout << " not a power of 2 " << endl;
107 /* apply fft recursion */
111 for (bit = 0; bit < logn; bit++)
113 Double_t w_real = 1.0;
114 Double_t w_imag = 0.0;
116 const Double_t theta = 2.0 * ((Int_t) sign) * M_PI / ((Double_t) (2 * dual));
118 const Double_t s = sin (theta);
119 const Double_t t = sin (theta / 2.0);
120 const Double_t s2 = 2.0 * t * t;
124 for (b = 0; b < dual; b++)
126 for (a = 0; a < n; a+= 2 * dual)
128 const size_t i = b + a;
129 const size_t j = b + a + dual;
131 const Double_t t1_real = REAL(data,stride,i) + REAL(data,stride,j);
132 const Double_t t1_imag = IMAG(data,stride,i) + IMAG(data,stride,j);
133 const Double_t t2_real = REAL(data,stride,i) - REAL(data,stride,j);
134 const Double_t t2_imag = IMAG(data,stride,i) - IMAG(data,stride,j);
136 REAL(data,stride,i) = t1_real;
137 IMAG(data,stride,i) = t1_imag;
138 REAL(data,stride,j) = w_real*t2_real - w_imag * t2_imag;
139 IMAG(data,stride,j) = w_real*t2_imag + w_imag * t2_real;
142 /* trignometric recurrence for w-> exp(i theta) w */
145 const Double_t tmp_real = w_real - s * w_imag - s2 * w_real;
146 const Double_t tmp_imag = w_imag + s * w_real - s2 * w_imag;
154 /* bit reverse the ordering of output data for decimation in
155 frequency algorithm */
157 //status = FUNCTION(fft_complex,bitreverse_order)(data, stride, n, logn) ;
158 status = ComplexBitReverseOrderWrap(data, stride, n, logn) ;
162 //__________________________________________________________________
163 Int_t AliTPCMonitorFFT::ComplexBitReverseOrderWrap(Double_t* data, Int_t stride, size_t n, Int_t logn)
165 // Wrapper function from gnu scientific library
166 /* This is the Goldrader bit-reversal algorithm */
171 logn = 0 ; /* not needed for this algorithm */
173 for (i = 0; i < n - 1; i++)
179 const Double_t tmp_real = REAL(data,stride,i);
180 const Double_t tmp_imag = IMAG(data,stride,i);
181 REAL(data,stride,i) = REAL(data,stride,j);
182 IMAG(data,stride,i) = IMAG(data,stride,j);
183 REAL(data,stride,j) = tmp_real;
184 IMAG(data,stride,j) = tmp_imag;
200 //__________________________________________________________________
201 Int_t AliTPCMonitorFFT::FFTBinaryLogn(size_t n)
204 // Return log on base 2
206 size_t binary_logn = 0 ;
215 ntest = (1 << binary_logn) ;
219 return -1 ; /* n is not a power of 2 */