<commit_before>/**
 * @file Dft.cpp
 *
 * A reference implementation of the Discrete Fourier Transform.
 *
 * Note - this is a direct application of the DFT equations and as such it
 * surely isn't optimal. The implementation here serves only as a reference
 * model to compare with.
 *
 * This file is part of the Aquila DSP library.
 * Aquila is free software, licensed under the MIT/X11 License. A copy of
 * the license is provided with the library in the LICENSE file.
 *
 * @package Aquila
 * @version 3.0.0-dev
 * @author <NAME>
 * @date 2007-2013
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 * @since 3.0.0
 */

#include "Dft.h"
#include <algorithm>
#include <cmath>
#include <complex>

namespace Aquila
{
    /**
     * Complex unit.
     */
    const ComplexType Dft::j(0, 1);

    /**
     * Applies the transformation to the signal.
     *
     * @param x input signal
     * @param spectrum output spectrum
     */
    void Dft::fft(const SampleType x[], ComplexType spectrum[])
    {
        ComplexType WN = std::exp((-j) * 2.0 * M_PI / static_cast<double>(N));
        for (unsigned int k = 0; k < N; ++k)
        {
            ComplexType sum(0, 0);
            for (unsigned int n = 0; n < N; ++n)
            {
                sum += x[n] * std::pow(WN, n * k);
            }
            spectrum[k] = sum;
        }
    }

    /**
     * Applies the inverse transform to the spectrum.
     *
     * @param spectrum input spectrum
     * @param x output signal
     */
    void Dft::ifft(ComplexType spectrum[], double x[])
    {
        // TODO
    }
}
<commit_msg>Added real-valued inverse DFT.<commit_after>/**
 * @file Dft.cpp
 *
 * A reference implementation of the Discrete Fourier Transform.
 *
 * Note - this is a direct application of the DFT equations and as such it
 * surely isn't optimal. The implementation here serves only as a reference
 * model to compare with.
 *
 * This file is part of the Aquila DSP library.
 * Aquila is free software, licensed under the MIT/X11 License. A copy of
 * the license is provided with the library in the LICENSE file.
 *
 * @package Aquila
 * @version 3.0.0-dev
 * @author <NAME>
 * @date 2007-2013
 * @license http://www.opensource.org/licenses/mit-license.php MIT
 * @since 3.0.0
 */

#include "Dft.h"
#include <algorithm>
#include <cmath>
#include <complex>

namespace Aquila
{
    /**
     * Complex unit.
     */
    const ComplexType Dft::j(0, 1);

    /**
     * Applies the transformation to the signal.
     *
     * @param x input signal
     * @param spectrum output spectrum
     */
    void Dft::fft(const SampleType x[], ComplexType spectrum[])
    {
        ComplexType WN = std::exp((-j) * 2.0 * M_PI / static_cast<double>(N));
        for (unsigned int k = 0; k < N; ++k)
        {
            ComplexType sum(0, 0);
            for (unsigned int n = 0; n < N; ++n)
            {
                sum += x[n] * std::pow(WN, n * k);
            }
            spectrum[k] = sum;
        }
    }

    /**
     * Applies the inverse transform to the spectrum.
     *
     * @param spectrum input spectrum
     * @param x output signal
     */
    void Dft::ifft(ComplexType spectrum[], double x[])
    {
        ComplexType WN = std::exp((-j) * 2.0 * M_PI / static_cast<double>(N));
        for (unsigned int k = 0; k < N; ++k)
        {
            ComplexType sum(0, 0);
            for (unsigned int n = 0; n < N; ++n)
            {
                sum += spectrum[n] * std::pow(WN, -n * k);
            }
            x[k] = std::abs(sum);
        }
    }
}

{'fraction_non_alphanumeric': 0.1261918115535614, 'fraction_numerical': 0.01514301738642737, 'mean_word_length': 2.0331632653061225, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '480928', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1105, 'n_words': 382}