GithubHelp home page GithubHelp logo

tmolteno / template-fft Goto Github PK

View Code? Open in Web Editor NEW
11.0 5.0 0.0 156 KB

Fast Header only C++ FFT and Inverse FFT using templates

License: GNU General Public License v2.0

C++ 96.75% Makefile 3.25%

template-fft's Introduction

Template-FFT

Fast Header only C++ FFT and Inverse FFT using templates.

Here is the source code for a complex FFT algorithm that uses template metaprogramming. It is quite fast (nearly as fast as fftw) and can be specialized to any type. We will be creating a fixed-point friendly FFT as well in the near future.

Using the C++ template

Create the file below, and compile it with your favourite C++ compiler. Requires Eigen for handling vectors and matrices.

#include "fft_complex.h"
#include <Eigen/Dense>
using namespace std;

#define LOG_LENGTH 13
#define N (1<<LOG_LENGTH)

typedef complex<double> fft_complex;

#include <iostream>

int main()
{
    CFFT<N,double> cfft;
    Matrix<complex<double>, N, 1> cdata;
    cdata.setRandom();

    std::cout << "Perform 1000 FFT and INVERSE FFT " << endl;
    std::cout << "FFT Length= " << N << endl;
    
    for (int i=0;i<1000;i++) {
        cfft.fft(cdata);
        cfft.ifft(cdata);
    }
return 0;
}

Copyright

Author: Tim Molteno, [email protected]

Based on the article "A Simple and Efficient FFT Implementation in C++" by Volodymyr Myrnyy with an inverse FFT modification.

Licensed under the GPL v3.

template-fft's People

Contributors

tmolteno avatar

Stargazers

The xD avatar Lauro Oyen avatar John Z. Li avatar Sreekumar Thaithara Balan avatar  avatar sunnycase avatar MeiHui FAN avatar Markus Otto avatar Matthieu Poullet avatar Stephen Berry avatar Albert Tavares de Almeida avatar

Watchers

Matthieu Poullet avatar  avatar  avatar Chatchai Daecha avatar  avatar

template-fft's Issues

Adding constraints.

I thought I'd contribute a tiny snippet of code to constrain the integer values used for template specialization to powers of two using the new c++20 requires feature.

#include <concepts>

constexpr bool is_power_of_two(std::integral auto value) {
    return (value > 0) && ((value & (value - 1)) == 0);
}

template<std::integral auto i>
requires (is_power_of_two(i))
struct Foo{

};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.