1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-15 02:05:36 +00:00
LatAnalyze/lib/Numerical/GslFFT.cpp

91 lines
2.7 KiB
C++
Raw Normal View History

2017-10-10 16:56:23 +01:00
/*
* GslFFT.cpp, part of LatAnalyze
*
2020-01-13 09:57:06 +00:00
* Copyright (C) 2013 - 2020 Antonin Portelli
2017-10-10 16:56:23 +01:00
*
* LatAnalyze is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LatAnalyze is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LatAnalyze. If not, see <http://www.gnu.org/licenses/>.
*/
#include <LatAnalyze/Numerical/GslFFT.hpp>
2017-10-10 16:56:23 +01:00
#include <LatAnalyze/includes.hpp>
using namespace std;
using namespace Latan;
/******************************************************************************
* GslFFT implementation *
******************************************************************************/
// constructor /////////////////////////////////////////////////////////////////
GslFFT::GslFFT(const Index size)
{
resize(size);
}
// destructor //////////////////////////////////////////////////////////////////
GslFFT::~GslFFT(void)
{
clear();
}
// size ////////////////////////////////////////////////////////////////////////
void GslFFT::resize(const Index size)
{
if (size_ != size)
{
2020-02-02 18:42:54 +00:00
clear();
2017-10-10 16:56:23 +01:00
size_ = size;
wavetable_ = gsl_fft_complex_wavetable_alloc(size_);
workspace_ = gsl_fft_complex_workspace_alloc(size_);
}
}
// fft /////////////////////////////////////////////////////////////////////////
void GslFFT::operator()(CMat &x, const unsigned int dir)
{
if (x.size() != size_)
{
LATAN_ERROR(Size, "wrong input vector size");
}
else
{
switch (dir)
{
case FFT::Forward:
gsl_fft_complex_forward((double *)x.data(), 1, size_,
wavetable_, workspace_);
break;
case FFT::Backward:
gsl_fft_complex_backward((double *)x.data(), 1, size_,
wavetable_, workspace_);
break;
default:
LATAN_ERROR(Argument, "invalid FT direction");
break;
}
}
}
// destroy GSL objects /////////////////////////////////////////////////////////
void GslFFT::clear(void)
{
if (!wavetable_)
{
gsl_fft_complex_wavetable_free(wavetable_);
}
if (!workspace_)
{
gsl_fft_complex_workspace_free(workspace_);
}
}