00001 #include "TsSpectrum.h"
00002 #include "types.h"
00003
00004 using namespace std;
00005
00006
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)
00020 {
00021 if (ExistsPlanForward)
00022 fftw_destroy_plan(p_forward);
00023 if (ExistsPlanReverse)
00024 fftw_destroy_plan(p_reverse);
00025 fftw_free(timedomain);
00026 fftw_free(freqdomain);
00027 ExistsPlanForward = false;
00028 ExistsPlanReverse = false;
00029 }
00030 }
00031
00032 TsSpectrum::~TsSpectrum()
00033 {
00034 DestroyMem();
00035 }
00036
00037
00038 void TsSpectrum::AssignMem(const int size)
00039 {
00040 DestroyMem();
00041 timedomain = (double *)fftw_malloc(sizeof(double) * size);
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;
00049 }
00050
00051 void TsSpectrum::Prepare_Calculation(const int size)
00052 {
00053 if (size != oldsize)
00054 {
00055 AssignMem(size);
00056 if (MultiCalc)
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;
00067 ExistsPlanForward = true;
00068 }
00069 }
00070