From cbe8a1cecc84315aeb22fa5d4d8fc3c93b053407 Mon Sep 17 00:00:00 2001 From: Seb James Date: Wed, 23 Sep 2026 10:10:35 +0100 Subject: [PATCH] Adds function to conveniently obtain the real part of the inverse. --- sm/hexfft.cppm | 11 +++++++++++ tests/hexfft1.cpp | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/sm/hexfft.cppm b/sm/hexfft.cppm index d7c6b47..b8d6d04 100644 --- a/sm/hexfft.cppm +++ b/sm/hexfft.cppm @@ -408,6 +408,17 @@ export namespace sm::hexfft return this->image_asa_to_hexgrid(); } + //! Return the real component of the inverse FFT. + sm::vvec inverse_real() + { + sm::vvec> inv_cplx = this->inverse(); + sm::vvec inv_real (inv_cplx.size(), F{0}); + for (std::uint32_t i = 0; i < inv_cplx.size(); ++i) { + inv_real[i] = std::real (inv_cplx[i]); + } + return inv_real; + } + private: //! Find parameters for the enclosing hexgrid (used to populate d0/d1 and create hg_asa) diff --git a/tests/hexfft1.cpp b/tests/hexfft1.cpp index d6698f8..159201d 100644 --- a/tests/hexfft1.cpp +++ b/tests/hexfft1.cpp @@ -27,10 +27,14 @@ static bool roundtrips (sm::hexgrid& hg, const char* label) sm::hexfft::fft hfft (&hg, data); sm::vvec> back = hfft.inverse(); + sm::vvec back_real = hfft.inverse_real(); + F maxerr = F{0}; for (std::uint32_t i = 0; i < hg.num(); ++i) { F err = std::abs (back[i] - std::complex (data[i], F{0})); + F err_real = std::abs (back_real[i] - data[i]); maxerr = std::max (maxerr, err); + maxerr = std::max (maxerr, err_real); } std::cout << label << ": hg.num()=" << hg.num() << " spectrum rows=" << hfft.asa_rows << " cols=" << hfft.asa_cols << " (size " << hfft.size() << ") max roundtrip error: " << maxerr << std::endl;