Mantid
Loading...
Searching...
No Matches
MaxentTransformFourier.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <utility>
9
10#include <gsl/gsl_fft_complex.h>
11#include <memory>
12#include <stdexcept>
13
14#include <stdexcept>
15
16namespace Mantid::Algorithms {
17
20 : m_dataSpace(std::move(dataSpace)), m_imageSpace(std::move(imageSpace)) {}
21
34std::vector<double> MaxentTransformFourier::imageToData(const std::vector<double> &image) {
35
36 std::vector<double> complexImage = m_imageSpace->toComplex(image);
37
38 /* Performs backward Fourier transform */
39
40 size_t n = complexImage.size();
41
42 if (n % 2) {
43 throw std::invalid_argument("Cannot transform to data space");
44 }
45
46 /* Backward FT */
47 gsl_fft_complex_wavetable *wavetable = gsl_fft_complex_wavetable_alloc(n / 2);
48 gsl_fft_complex_workspace *workspace = gsl_fft_complex_workspace_alloc(n / 2);
49 gsl_fft_complex_inverse(complexImage.data(), 1, n / 2, wavetable, workspace);
50 gsl_fft_complex_wavetable_free(wavetable);
51 gsl_fft_complex_workspace_free(workspace);
52
53 return m_dataSpace->fromComplex(complexImage);
54}
55
68std::vector<double> MaxentTransformFourier::dataToImage(const std::vector<double> &data) {
69
70 std::vector<double> complexData = m_dataSpace->toComplex(data);
71
72 /* Performs forward Fourier transform */
73
74 size_t n = complexData.size();
75
76 if (n % 2) {
77 throw std::invalid_argument("Cannot transform to image space");
78 }
79
80 /* Fourier transofrm */
81 gsl_fft_complex_wavetable *wavetable = gsl_fft_complex_wavetable_alloc(n / 2);
82 gsl_fft_complex_workspace *workspace = gsl_fft_complex_workspace_alloc(n / 2);
83 gsl_fft_complex_forward(complexData.data(), 1, n / 2, wavetable, workspace);
84 gsl_fft_complex_wavetable_free(wavetable);
85 gsl_fft_complex_workspace_free(workspace);
86
87 return m_imageSpace->fromComplex(complexData);
88}
89
90} // namespace Mantid::Algorithms
gsl_fft_real_wavetable * wavetable
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::vector< double > imageToData(const std::vector< double > &image) override
Transforms a 1D signal from image space to data space, performing an inverse Fast Fourier Transform.
std::vector< double > dataToImage(const std::vector< double > &data) override
Transforms a 1D signal from data space to image space, performing a forward Fast Fourier Transform.
std::shared_ptr< MaxentSpace > MaxentSpace_sptr
Definition: MaxentSpace.h:33
STL namespace.