TsSpectrum.cpp

Go to the documentation of this file.
00001 #include "TsSpectrum.h"
00002 #include "types.h"
00003 
00004 using namespace std;
00005 
00006 //The constructor copies the parameter value into MultiCalc and sets everything else to indicate pristine stare
00007 TsSpectrum::TsSpectrum(bool WantMultiCalc)
00008 {
00009 MultiCalc = WantMultiCalc;
00010 ExistsPlanForward = false;
00011 ExistsPlanReverse = false;
00012 oldsize = 0;
00013 timedomain = NULL;
00014 freqdomain = NULL;
00015 }
00016 
00017 void TsSpectrum::DestroyMem()
00018 {
00019         if (ExistsPlanForward || ExistsPlanReverse) // if we did some calulations before
00020         { 
00021                 if (ExistsPlanForward)
00022                         fftw_destroy_plan(p_forward); // we destroy the old plans
00023                 if (ExistsPlanReverse)
00024                         fftw_destroy_plan(p_reverse); 
00025                 fftw_free(timedomain); // and free the memory allocated
00026                 fftw_free(freqdomain);
00027                 ExistsPlanForward = false; // now there is no plan anymore, so we don't double deallocate
00028                 ExistsPlanReverse = false;
00029         }
00030 }
00031 
00032 TsSpectrum::~TsSpectrum()
00033 {
00034         DestroyMem();
00035 }
00036 
00037 //The size for AssignMem is the size of the time series
00038 void TsSpectrum::AssignMem(const int size)
00039 {
00040                 DestroyMem(); // destroy possible earlier instances
00041                 timedomain = (double *)fftw_malloc(sizeof(double) * size); // reallocate with the required sizes
00042                 freqdomain = (fftw_complex *)fftw_malloc(sizeof(fftw_complex) * (size/2+1));
00043 }
00044 
00045 
00046 void TsSpectrum::Finish_Calculation(const int size)
00047 {
00048         oldsize = size; // The size of the (next) last calculation is the size of this calculation
00049 }
00050 
00051 void TsSpectrum::Prepare_Calculation(const int size)
00052 {
00053         if (size != oldsize) // if the size changed 
00054         {
00055                 AssignMem(size); //reassign memory
00056                 if (MultiCalc) // generate a new plan
00057                 {
00058                         p_reverse = fftw_plan_dft_c2r_1d(size,freqdomain,timedomain,FFTW_MEASURE);
00059                         p_forward = fftw_plan_dft_r2c_1d(size,timedomain,freqdomain,FFTW_MEASURE);
00060                 }
00061                 else
00062                 {
00063                         p_reverse = fftw_plan_dft_c2r_1d(size,freqdomain,timedomain,FFTW_ESTIMATE);
00064                         p_forward = fftw_plan_dft_r2c_1d(size,timedomain,freqdomain,FFTW_ESTIMATE);     
00065                 }
00066                 ExistsPlanReverse = true; // we will have to deallocate at some point
00067                 ExistsPlanForward = true;
00068         } 
00069 }
00070 

Generated on Fri Jul 4 15:30:21 2008 for GPLIB++ by  doxygen 1.5.5