Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions TaskFiles/Benchmarks/fft.nebs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Testing benchmark for FFT (Fast Fourier Transform) implementation
# Using the featuretest module so we don' have to benchmark with the slower transformation fft.

feature-test large-fft 10000000
exit
7 changes: 6 additions & 1 deletion TaskFiles/Debugging/profiling.nebs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ echo "Starting profiling.nebs"
# - loading
# - jsonRuleset
# - parsing
set settings.profilingTask transformations
# - fft
set settings.profilingTask fft
####################################################

###################
Expand All @@ -50,3 +51,7 @@ if $({global:settings.profilingTask|strCompare equals jsonRuleset}) then task Ta
###################
# 6.) Parsing performance
if $({global:settings.profilingTask|strCompare equals parsing}) then task TaskFiles/Benchmarks/parsing.nebs

###################
# 7.) FFT performance
if $({global:settings.profilingTask|strCompare equals fft}) then task TaskFiles/Benchmarks/fft.nebs
69 changes: 33 additions & 36 deletions include/Nebulite/Math/FFT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,42 @@
#include <vector>

//------------------------------------------
namespace Nebulite::Math {
/**
* @brief A class that provides static methods for performing Fast Fourier Transform (FFT) and related operations on audio data.
* @namespace Nebulite::Math::Fft
* @brief Functions for performing Fast Fourier Transform (FFT) and related operations on audio data.
*/
class Fft {
public:
/**
* @brief Computes the Fast Fourier Transform (FFT) of the given sound data.
* @param data The sound data to transform.
* @return A vector of complex numbers representing the FFT of the sound data.
*/
static std::vector<std::complex<double>> fft(std::vector<double> const& data);
namespace Nebulite::Math::Fft {
/**
* @brief Computes the Fast Fourier Transform (FFT) of the given sound data.
* @param data The sound data to transform.
* @return A vector of complex numbers representing the FFT of the sound data.
*/
std::vector<std::complex<double>> fft(std::vector<double> const& data);

/**
* @brief Computes the Inverse Fast Fourier Transform (IFFT) of the given frequency-domain data.
* @param xValues The frequency-domain data to transform back to the time domain.
* @return A vector of complex numbers representing the IFFT of the input data, which can be converted back to audio samples.
*/
static std::vector<std::complex<double>> fftInverse(std::vector<std::complex<double>> const& xValues);
/**
* @brief Computes the Inverse Fast Fourier Transform (IFFT) of the given frequency-domain data.
* @param xValues The frequency-domain data to transform back to the time domain.
* @return A vector of complex numbers representing the IFFT of the input data, which can be converted back to audio samples.
*/
std::vector<std::complex<double>> fftInverse(std::vector<std::complex<double>> const& xValues);

/**
* @brief Applies a transfer function defined by the given numerator and denominator coefficients to the input sound data in the frequency domain.
* @param data The input sound data to which the transfer function will be applied.
* @param num The coefficients of the numerator of the transfer function, starting with the highest order.
* @param den The coefficients of the denominator of the transfer function, starting with the highest order.
* @return A vector of doubles representing the sound data after applying the transfer function in the frequency domain.
* @throws std::domain_error if the leading coefficient of the denominator is zero, which is not supported.
*/
static std::vector<double> applyTransferFunctionFrequencyDomain(std::vector<double> const& data, std::vector<double> const& num, std::vector<double> const& den);
/**
* @brief Evaluates the transfer function defined by the given numerator and denominator coefficients at a specific angular frequency omega.
* @param omega The angular frequency (in radians per second) at which to evaluate the transfer function.
* @param num The coefficients of the numerator of the transfer function, starting with the highest order.
* @param den The coefficients of the denominator of the transfer function, starting with the highest order.
* @return A complex number representing the value of the transfer function at the specified frequency.
*/
std::complex<double> evalTransfer(double omega,std::vector<double> const& num,std::vector<double> const& den);

private:
/**
* @brief Evaluates the transfer function defined by the given numerator and denominator coefficients at a specific angular frequency omega.
* @param omega The angular frequency (in radians per second) at which to evaluate the transfer function.
* @param num The coefficients of the numerator of the transfer function, starting with the highest order.
* @param den The coefficients of the denominator of the transfer function, starting with the highest order.
* @return A complex number representing the value of the transfer function at the specified frequency.
*/
static std::complex<double> evalTransfer(double omega,std::vector<double> const& num,std::vector<double> const& den);
};
} // namespace Nebulite::Math
/**
* @brief Applies a transfer function defined by the given numerator and denominator coefficients to the input sound data in the frequency domain.
* @param data The input sound data to which the transfer function will be applied.
* @param num The coefficients of the numerator of the transfer function, starting with the highest order.
* @param den The coefficients of the denominator of the transfer function, starting with the highest order.
* @return A vector of doubles representing the sound data after applying the transfer function in the frequency domain.
* @throws std::domain_error if the leading coefficient of the denominator is zero, which is not supported.
*/
std::vector<double> applyTransferFunctionFrequencyDomain(std::vector<double> const& data, std::vector<double> const& num, std::vector<double> const& den);
} // namespace Nebulite::Math::Fft
#endif // NEBULITE_MATH_FFT_HPP
10 changes: 10 additions & 0 deletions include/Nebulite/Module/Domain/GlobalSpace/FeatureTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class FeatureTest final : public Base::DomainModule<Core::GlobalSpace> {
"Usage: feature-test find-parent-key <key>\n"
"Using no argument will treated as an empty key.\n";

// Benchmarks

[[nodiscard]] Constants::Event largeFft(std::span<std::string_view const> args) const ;
static auto constexpr largeFftName = "feature-test large-fft";
static auto constexpr largeFftDesc = "Tests the FFT implementation with a large dataset.\n"
"Usage: feature-test large-fft <size>\n";

//------------------------------------------
// Categories

Expand All @@ -85,6 +92,9 @@ class FeatureTest final : public Base::DomainModule<Core::GlobalSpace> {
// Keys
bindFunction(&FeatureTest::keyCombination, keyCombinationName, keyCombinationDesc);
bindFunction(&FeatureTest::findParentKey, findParentKeyName, findParentKeyDesc);

// Benchmarks
bindFunction(&FeatureTest::largeFft, largeFftName, largeFftDesc);
}

struct Key : Data::KeyGroup<""> {
Expand Down
Loading
Loading