Coder Social home page Coder Social logo

obonac / fft Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gregfjohnson/fft

0.0 0.0 0.0 21 KB

An easy-to-use, simple command-line tool for calculating the Finite Fourier Transform

License: GNU General Public License v2.0

Makefile 1.33% C 63.37% Lua 35.30%

fft's Introduction

Command-line Fast Fourier Transform utility

This tool implements the standard FFT algorithm as a standalone command-line utility. The intention is to fit into the standard linux/unix shell paradigm: standard shell operations (piping inputs and outputs, file etc.), character streams for input and output, etc.

The fft uses a mixed-radix algorithm, so the inputs are not restricted to lengths that are a power of two. The input length is broken into its prime factors, and the fft uses the prime factors as the "fan out" at each recursive step. The fft algorithm is fastest if the largest prime factor of N is small! In the degenerate case that N is prime, the algorithm runs in quadratic time. If your dataset has a length N that happens to have large prime factors, it is worth considering trimming one or two elements off of the dataset. A number near N is likely to have a very different configuration of prime factors, with a smaller maximum prime factor. In that case, the resulting FFT is near the original, and it will be computed much faster.

In some cases, use of this fft tool can avoid the need to use windows (Blackman, Hamming, etc.). A standard use of windows is to minimize leakage around the FFT output frequencies due to the fact that the sample length is not a multiple of the fundamental frequency of the data.

Take the FFT of the original dataset, and deduce the (approximate) fundamental frequency of the data. Then trim the data a little bit, so that the length is an even multiple of the fundamental frequency. The FFT of the modified dataset may have less leakage around the calculated frequencies, because it is the correct length relative to its fundamental frequency.

Here is a simple example:

fft
1
0
1
0
1
0
<eof>
 1.224744871392 0.000000000000
 0.000000000000 0.000000000000
-0.000000000000 0.000000000000
 1.224744871392 0.000000000000
 0.000000000000 0.000000000000
-0.000000000000 0.000000000000

The default input is double-precision real values, and the default output is cartesian complex numbers (X + iY). These input and output formats can be overridden with command-line arguments.

The following operation represents the identity function on its inputs. The second invocation generates the inverse FFT, and takes cartesian complex numbers as input:

fft | fft -b -ic -oa
1
2
3
101
105
<eof>
1.000000000000
2.000000000000
2.999999999999
101.000000000001
105.000000000000

Here are the command-line arguments:

usage:  fft
        [-h]         # help (this message)
        [-check N]   # calculate largest prime factor of N; smaller value => faster fft
        [-b]         # inverse (backward) fft

                     # default input format is real (non-complex) values
        [-ip]        # input complex values in polar (radius, radians)
        [-ic]        # input complex values in cartesian (real, imaginary)

                     # default output format is cartesian (real, imaginary) values
        [-op]        # output complex values in polar (radius, radians)
        [-oa]        # output double-precision amplitudes

        [input_file] # default input is stdin

fft's People

Contributors

gregfjohnson avatar

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.