orsa_fft.h

Go to the documentation of this file.
00001 /* 
00002    ORSA - Orbit Reconstruction, Simulation and Analysis
00003    Copyright (C) 2002-2004 Pasquale Tricarico
00004    
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009    
00010    As a special exception, Pasquale Tricarico gives permission to
00011    link this program with Qt commercial edition, and distribute the
00012    resulting executable, without including the source code for the Qt
00013    commercial edition in the source distribution.
00014    
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019    
00020    You should have received a copy of the GNU General Public License
00021    along with this program; if not, write to the Free Software
00022    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 */
00024 
00025 #ifndef _ORSA_FFT_H_
00026 #define _ORSA_FFT_H_
00027 
00028 #include "orsa_analysis.h"
00029 #include "orsa_orbit.h"
00030 
00031 #include <vector>
00032 
00033 #include <fftw.h>
00034 
00035 #include <gsl/gsl_vector.h>
00036 #include <gsl/gsl_min.h>
00037 
00038 namespace orsa {
00039   
00040   // gsl d=1 minimization stuff
00041   typedef struct gsl_d1_minimization_parameters {
00042     fftw_complex * pointer_points_sequence;
00043     int size;
00044   } gsl_d1_minimization_parameters;
00045   
00046   class FFTDataStructure {
00047   public:
00048     double time,amplitude,phase;
00049     virtual ~FFTDataStructure() {};
00050   };
00051   
00052   class FFTDataStream : public std::vector<FFTDataStructure> {
00053   public:
00054     double timestep;
00055   };
00056   
00057   class FFTPowerSpectrumBaseElement {
00058   public:
00059     double frequency;
00060     double power;
00061   };
00062   
00063   class FFTPowerSpectrum : public std::vector<FFTPowerSpectrumBaseElement> {};
00064   
00065   class Peak {
00066   public:
00067     inline void Set(double f, double a, double p) {
00068       frequency = f;
00069       amplitude = a;
00070       phase     = p;
00071     } 
00072     
00073   public:
00074     /* 
00075        // used to sort peaks by increasing frequency 
00076        inline bool operator < (const Peak &p) const {
00077        return (frequency < p.frequency);
00078        }
00079     */
00080     // used to sort peaks by decreasing amplitude
00081     inline bool operator < (const Peak &p) const {
00082       return (p.amplitude < amplitude);
00083     }
00084     
00085   public:
00086     double frequency,amplitude,phase;
00087     
00088   public:
00089     fftw_complex phiR, phiL;
00090     
00091   public:
00092     virtual ~Peak() {};
00093   };
00094   
00095   //! signal types
00096   enum FFTSearch {HK=0,D,PQ,NODE,ANOMALY,ANOMALY_PHASE,A_M,TESTING};
00097   
00098   enum FFTSearchAmplitude {A,E,I,SIN_I,TAN_I_2,ONE};
00099   enum FFTSearchPhase     {OMEGA_NODE,OMEGA_PERICENTER,OMEGA_TILDE,MM,LAMBDA,ZERO};
00100   
00101   enum FFTAlgorithm { 
00102     algo_FFT,   // Search only power spectrum peaks
00103     algo_FFTB,  // Search only power spectrum peaks, on positive and negative frequencies
00104     algo_MFT,   // Original method by Laskar
00105     algo_FMFT1, // MFT with linear freq. corrections (Sidlichovsky and Nesvorny 1997, Cel. Mech. 65, 137)
00106     algo_FMFT2  // FMFT1 with addition non-linear corrections (Sidlichovsky and Nesvorny 1997, Cel. Mech. 65, 137)
00107   };
00108   
00109   //! FFT analysis 
00110   class FFT : public Analysis {
00111     
00112   public: 
00113     FFT(OrbitStream&, FFTPowerSpectrum&, std::vector<Peak>&, FFTDataStream&);
00114     
00115     void Search(FFTSearch,FFTAlgorithm=algo_FFT);
00116     void Search(FFTSearchAmplitude,FFTSearchPhase,FFTAlgorithm=algo_FFT);
00117     
00118   private:
00119     void Search_FFT();   // FourierTransformPeaks
00120     void Search_FFTB();
00121     void Search_MFT();   // ModifiedFourierTransform
00122     void Search_FMFT1(); // FrequencyModifiedFourierTransform_1
00123     void Search_FMFT2(); // FrequencyModifiedFourierTransform_2
00124     //
00125     void Search_FMFT_main();
00126     
00127   public:   
00128     //! frequency range parameters
00129     // double freq_start, freq_stop;
00130     
00131   public:
00132     std::vector<int> candidate_bin;
00133     
00134   public:
00135     double relative_amplitude;
00136       
00137   private:
00138     double default_peak_reset_frequency;
00139     double default_peak_reset_amplitude;
00140     double default_peak_reset_phase;
00141     
00142   public:
00143     bool  HiResSpectrum;
00144     
00145   private:
00146     void FillDataStream(FFTSearch);
00147     void FillDataStream(FFTSearchAmplitude,FFTSearchPhase);
00148     void ComputeCommonPowerSpectrum();
00149     void ComputeCommonReconstructedSignal();
00150     
00151   public:
00152     gsl_d1_minimization_parameters par;
00153     gsl_function F;
00154     gsl_min_fminimizer *s;
00155     const gsl_min_fminimizer_type *T;
00156     
00157   protected:
00158     std::vector<double>     psd;
00159     FFTPowerSpectrum  *fps;
00160 
00161     std::vector<Peak>   *peaks;
00162     OrbitStream    *os;
00163     
00164     FFTDataStream  *reconstructed_data_stream;    
00165     
00166   public:
00167     FFTDataStream  data_stream; // should be used readonly from outside this class...
00168     
00169   public:
00170     unsigned int nfreq;
00171   };
00172   
00173 } // namespace orsa
00174 
00175 #endif // _ORSA_FFT_H_
00176 

Generated on Fri Nov 3 20:37:41 2006 for liborsa by  doxygen 1.4.7