Advertisement
Ilya_konstantinov

fftw

Dec 25th, 2024
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <fftw3.h>
  2. #include "include/fft.h"
  3. #include <vector>
  4. #include <iostream>
  5.  
  6. #include <cmath>
  7.  
  8.  
  9. class DctCalculator::Impl {
  10. public:
  11. fftw_plan plan;
  12. size_t width;
  13. std::vector<double>* input;
  14. std::vector<double>* output;
  15.  
  16. Impl(size_t width, std::vector<double> *input, std::vector<double> *output)
  17. : input(input), output(output), width(width) {
  18. if (!(input->size() == output->size() && input->size() == width * width)) {
  19. throw std::invalid_argument("Wrong arrays");
  20. }
  21. plan = fftw_plan_r2r_2d(width, width, input->data(), output->data(), FFTW_REDFT01, FFTW_REDFT01, FFTW_ESTIMATE);
  22. }
  23.  
  24. ~Impl() {
  25. fftw_destroy_plan(plan);
  26. }
  27.  
  28. void Inverse() {
  29. double two_sqrt = std::sqrt(2);
  30.  
  31. for (size_t i = 0; i < width * width; ++i) {
  32. (*input)[i] *= 4 * (i < width ? two_sqrt : 1) * (i % width == 0 ? two_sqrt : 1);
  33. }
  34. fftw_execute(plan);
  35. // for (size_t i = 0; i < output->size(); ++i) {
  36. // output->at(i) /= (width * width);
  37. // }
  38. }
  39. };
  40.  
  41. DctCalculator::DctCalculator(size_t width, std::vector<double> *input, std::vector<double> *output)
  42. : impl_(new Impl(width, input, output)) {
  43. }
  44.  
  45. void DctCalculator::Inverse() {
  46. impl_->Inverse();
  47. }
  48.  
  49. DctCalculator::~DctCalculator() = default;
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement