TsSpectrum.cpp
Go to the documentation of this file.00001 #include "TsSpectrum.h"
00002
00003 using namespace std;
00004
00005 namespace gplib
00006 {
00007
00008
00009 TsSpectrum::TsSpectrum(bool WantMultiCalc)
00010 {
00011 MultiCalc = WantMultiCalc;
00012 ExistsPlanForward = false;
00013 ExistsPlanReverse = false;
00014 oldsize = 0;
00015 timedomain = NULL;
00016 freqdomain = NULL;
00017 }
00018
00019 void TsSpectrum::DestroyMem()
00020 {
00021 if (ExistsPlanForward || ExistsPlanReverse)
00022 {
00023 if (ExistsPlanForward)
00024 fftw_destroy_plan(p_forward);
00025 if (ExistsPlanReverse)
00026 fftw_destroy_plan(p_reverse);
00027 fftw_free(timedomain);
00028 fftw_free(freqdomain);
00029 ExistsPlanForward = false;
00030 ExistsPlanReverse = false;
00031 }
00032 }
00033
00034 TsSpectrum::~TsSpectrum()
00035 {
00036 DestroyMem();
00037 }
00038
00039
00040 void TsSpectrum::AssignMem(const int size)
00041 {
00042 DestroyMem();
00043 timedomain = (double *) fftw_malloc(sizeof(double) * size);
00044 freqdomain = (fftw_complex *) fftw_malloc(sizeof(fftw_complex) * (size
00045 / 2 + 1));
00046 }
00047
00048 void TsSpectrum::Finish_Calculation(const int size)
00049 {
00050 oldsize = size;
00051 }
00052
00053 void TsSpectrum::Prepare_Calculation(const int size)
00054 {
00055 if (size != oldsize)
00056 {
00057 AssignMem(size);
00058
00059 if (MultiCalc)
00060 {
00061 p_reverse = fftw_plan_dft_c2r_1d(size, freqdomain, timedomain,
00062 FFTW_MEASURE);
00063 p_forward = fftw_plan_dft_r2c_1d(size, timedomain, freqdomain,
00064 FFTW_MEASURE);
00065 }
00066 else
00067 {
00068 p_reverse = fftw_plan_dft_c2r_1d(size, freqdomain, timedomain,
00069 FFTW_ESTIMATE);
00070 p_forward = fftw_plan_dft_r2c_1d(size, timedomain, freqdomain,
00071 FFTW_ESTIMATE);
00072 }
00073 ExistsPlanReverse = true;
00074 ExistsPlanForward = true;
00075 }
00076 }
00077 }