ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
FFT.h
Go to the documentation of this file.
1/**
2 * @file FFT.h
3 * @brief Provides an implementation of the Radix-2 FFT algorithm and related utilities.
4 *
5 * @date 22/12/2024
6 * @version 1.0
7 * @author Coela Can't
8 */
9
10#pragma once
11
12#include "../../Utils/Math/Mathematics.h"
13
14/**
15 * @class FFT
16 * @brief A templated class for performing Fast Fourier Transform (FFT) operations.
17 * @tparam fftSize The size of the FFT, must be a power of 2.
18 */
19template<int fftSize>
20class FFT {
21private:
22 /**
23 * @brief Precomputed twiddle coefficients for the FFT.
24 */
25 static const constexpr float twiddleCoefficients[fftSize * 2] = [] {
26 float temp[fftSize * 2];
27
28 for (int i = 0; i < fftSize * 2; ++i) {
30 }
31
32 return temp;
33 }();
34
35 /**
36 * @brief Calculates the number of bits required for bit reversal based on FFT size.
37 * @param size The FFT size.
38 * @param count Recursive parameter to count the bits.
39 * @return The number of bits required.
40 */
41 static constexpr int CalculateBits(int size, int count = 0);
42
43 /**
44 * @brief The number of bits needed for bit reversal for this FFT size.
45 */
46 static const constexpr int bitCount = CalculateBits(fftSize);
47
48 /**
49 * @brief Reorders the data array in bit-reversed order.
50 * @param data The data array to reorder.
51 */
52 static void BitReverseOrder(float* data);
53
54 /**
55 * @brief Reverses the bits of an integer.
56 * @param num The number whose bits are to be reversed.
57 * @return The bit-reversed integer.
58 */
59 static int ReverseBits(int num);
60
61 /**
62 * @brief Swaps two floating-point values.
63 * @param a Pointer to the first value.
64 * @param b Pointer to the second value.
65 */
66 static void Swap(float* a, float* b);
67
68public:
69 /**
70 * @brief Performs a Radix-2 FFT on the provided data.
71 * @param data The input array containing interleaved real and imaginary components.
72 */
73 static void Radix2FFT(float* data);
74
75 /**
76 * @brief Computes the magnitude of complex numbers from interleaved real and imaginary components.
77 * @param complexData The input array containing interleaved real and imaginary components.
78 * @param magnitude The output array for storing computed magnitudes.
79 */
80 static void ComplexMagnitude(float* complexData, float* magnitude);
81};
82
83#include "FFT.tpp"
A templated class for performing Fast Fourier Transform (FFT) operations.
Definition FFT.h:20
static void Radix2FFT(float *data)
Performs a Radix-2 FFT on the provided data.
static constexpr int CalculateBits(int size, int count=0)
Calculates the number of bits required for bit reversal based on FFT size.
static const constexpr int bitCount
The number of bits needed for bit reversal for this FFT size.
Definition FFT.h:46
static void BitReverseOrder(float *data)
Reorders the data array in bit-reversed order.
static void Swap(float *a, float *b)
Swaps two floating-point values.
static void ComplexMagnitude(float *complexData, float *magnitude)
Computes the magnitude of complex numbers from interleaved real and imaginary components.
static const constexpr float twiddleCoefficients[fftSize *2]
Precomputed twiddle coefficients for the FFT.
Definition FFT.h:25
static int ReverseBits(int num)
Reverses the bits of an integer.
Implements a generic Kalman Filter for 1D data.