CSL  6.0
fft_N.h
Go to the documentation of this file.
1 /*
2  * Free FFT and convolution (C)
3  *
4  * Copyright (c) 2018 Project Nayuki. (MIT License)
5  * https://www.nayuki.io/page/free-small-fft-in-multiple-languages
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  * - The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  * - The Software is provided "as is", without warranty of any kind, express or
16  * implied, including but not limited to the warranties of merchantability,
17  * fitness for a particular purpose and noninfringement. In no event shall the
18  * authors or copyright holders be liable for any claim, damages or other
19  * liability, whether in an action of contract, tort or otherwise, arising from,
20  * out of or in connection with the Software or the use or other dealings in the
21  * Software.
22  */
23 
24 #pragma once
25 
26 #include <stdbool.h>
27 #include <stddef.h>
28 
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define CFTTYPE float
35 
36 void Fft_setup(size_t n); // setup
37 
38 /*
39  * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
40  * The vector can have any length. This is a wrapper function. Returns true if successful, false otherwise (out of memory).
41  */
42 bool Fft_transform(CFTTYPE real[], CFTTYPE imag[], size_t n);
43 
44 
45 /*
46  * Computes the inverse discrete Fourier transform (IDFT) of the given complex vector, storing the result back into the vector.
47  * The vector can have any length. This is a wrapper function. This transform does not perform scaling, so the inverse is not a true inverse.
48  * Returns true if successful, false otherwise (out of memory).
49  */
50 bool Fft_inverseTransform(CFTTYPE real[], CFTTYPE imag[], size_t n);
51 
52 
53 /*
54  * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
55  * The vector's length must be a power of 2. Uses the Cooley-Tukey decimation-in-time radix-2 algorithm.
56  * Returns true if successful, false otherwise (n is not a power of 2, or out of memory).
57  */
58 bool Fft_transformRadix2(CFTTYPE real[], CFTTYPE imag[], size_t n);
59 
60 
61 /*
62  * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
63  * The vector can have any length. This requires the convolution function, which in turn requires the radix-2 FFT function.
64  * Uses Bluestein's chirp z-transform algorithm. Returns true if successful, false otherwise (out of memory).
65  */
66 bool Fft_transformBluestein(CFTTYPE real[], CFTTYPE imag[], size_t n);
67 
68 
69 /*
70  * Computes the circular convolution of the given real vectors. Each vector's length must be the same.
71  * Returns true if successful, false otherwise (out of memory).
72  */
73 bool Fft_convolveReal(const CFTTYPE x[], const CFTTYPE y[], CFTTYPE out[], size_t n);
74 
75 
76 /*
77  * Computes the circular convolution of the given complex vectors. Each vector's length must be the same.
78  * Returns true if successful, false otherwise (out of memory).
79  */
80 bool Fft_convolveComplex(const CFTTYPE xreal[], const CFTTYPE ximag[], const CFTTYPE yreal[], const CFTTYPE yimag[], CFTTYPE outreal[], CFTTYPE outimag[], size_t n);
81 
82 
83 #ifdef __cplusplus
84 }
85 #endif
void Fft_setup(size_t n)
Definition: fft_N.c:42
bool Fft_convolveComplex(const CFTTYPE xreal[], const CFTTYPE ximag[], const CFTTYPE yreal[], const CFTTYPE yimag[], CFTTYPE outreal[], CFTTYPE outimag[], size_t n)
bool Fft_inverseTransform(CFTTYPE real[], CFTTYPE imag[], size_t n)
Definition: fft_N.c:87
bool Fft_transformRadix2(CFTTYPE real[], CFTTYPE imag[], size_t n)
Definition: fft_N.c:91
#define CFTTYPE
Definition: fft_N.h:34
bool Fft_transformBluestein(CFTTYPE real[], CFTTYPE imag[], size_t n)
bool Fft_convolveReal(const CFTTYPE x[], const CFTTYPE y[], CFTTYPE out[], size_t n)
bool Fft_transform(CFTTYPE real[], CFTTYPE imag[], size_t n)
Definition: fft_N.c:72