-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfft.cpp
More file actions
32 lines (28 loc) · 932 Bytes
/
Copy pathfft.cpp
File metadata and controls
32 lines (28 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "fft.h"
#include <fftw3.h>
#include <stdexcept>
#include <cmath>
DctCalculator::DctCalculator(size_t width, std::vector<double> *input, std::vector<double> *output)
: width_(width), input_(input), output_(output) {
if (!input_ || !output_ || input_->size() != width_ * width_ ||
output_->size() != width_ * width_) {
throw std::invalid_argument("Bad arguments");
}
plan_ = fftw_plan_r2r_2d(width_, width_, input_->data(), output_->data(), FFTW_REDFT01,
FFTW_REDFT01, FFTW_ESTIMATE);
}
void DctCalculator::Inverse() {
for (size_t i = 0; i < width_ * width_; ++i) {
input_->at(i) /= m_size_ * 2;
if (i < width_) {
input_->at(i) *= sqrt(2);
}
if (i % width_ == 0) {
input_->at(i) *= sqrt(2);
}
}
fftw_execute(plan_);
}
DctCalculator::~DctCalculator() {
fftw_destroy_plan(plan_);
}