summaryrefslogtreecommitdiff
path: root/src/fft.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/fft.hpp')
-rw-r--r--src/fft.hpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/fft.hpp b/src/fft.hpp
new file mode 100644
index 0000000..9eac372
--- /dev/null
+++ b/src/fft.hpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2020-2021 Vasile Vilvoiu <vasi.vilvoiu@gmail.com>
+ *
+ * specgram is free software; you can redistribute it and/or modify
+ * it under the terms of the MIT license. See LICENSE for details.
+ */
+
+#ifndef _FFT_HPP_
+#define _FFT_HPP_
+
+#include "window-function.hpp"
+
+#include <fftw3.h>
+
+class FFT {
+private:
+ /* FFT window width */
+ const std::size_t window_width_;
+
+ /* fftw buffers */
+ fftw_complex *in_;
+ fftw_complex *out_;
+
+ /* fftw plan */
+ fftw_plan plan_;
+
+ /* window function */
+ std::unique_ptr<WindowFunction> window_function_;
+
+public:
+ FFT() = delete;
+ FFT(const FFT &c) = delete;
+ FFT(FFT &&) = delete;
+ FFT & operator=(const FFT&) = delete;
+
+ FFT(std::size_t win_width, std::unique_ptr<WindowFunction>& win_func);
+ virtual ~FFT();
+
+ ComplexWindow Compute(const ComplexWindow& input);
+
+ static RealWindow GetMagnitude(const ComplexWindow& input, bool alias);
+ static std::tuple<double, double> GetFrequencyLimits(double rate, std::size_t width);
+ static double GetFrequencyIndex(double rate, std::size_t width, double f);
+ static RealWindow Resample(const RealWindow& input, double rate, std::size_t width, double fmin, double fmax);
+ static RealWindow Crop(const RealWindow& input, double rate, double fmin, double fmax);
+};
+
+#endif \ No newline at end of file