BRL-CAD
fft.h
Go to the documentation of this file.
1/* F F T . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2023 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20/** @addtogroup libfft
21 *
22 * @brief
23 * The Fast-Fourier Transform library is a signal processing
24 * library for performing FFTs or inverse FFTs efficiently.
25 */
26#ifndef FFT_H
27#define FFT_H
28
29#include "common.h"
30
31#include <math.h>
32
33__BEGIN_DECLS
34
35/* NOTE: intentionally not using vmath.h to avoid dependency */
36#ifndef M_PI
37# define M_PI 3.14159265358979323846264338328
38#endif
39#ifndef M_SQRT1_2
40# define M_SQRT1_2 0.70710678118654752440084436210
41#endif
42
43#ifndef FFT_EXPORT
44# if defined(FFT_DLL_EXPORTS) && defined(FFT_DLL_IMPORTS)
45# error "Only FFT_DLL_EXPORTS or FFT_DLL_IMPORTS can be defined, not both."
46# elif defined(FFT_DLL_EXPORTS)
47# define FFT_EXPORT COMPILER_DLLEXPORT
48# elif defined(FFT_DLL_IMPORTS)
49# define FFT_EXPORT COMPILER_DLLIMPORT
50# else
51# define FFT_EXPORT
52# endif
53#endif
54
55/** @addtogroup libfft */
56/** @{ */
57/** @file fft.h */
58
59/* The COMPLEX type used throughout */
60typedef struct {
61 double re; /* Real Part */
62 double im; /* Imaginary Part */
63} COMPLEX;
64
65/**
66 * Generates Real Split Radix Decimation in Time source files
67 */
68FFT_EXPORT extern void splitdit(int N, int M);
69
70/**
71 * Generates Real Split Radix Decimation in Freq Inverse FFT source files
72 *
73 * @param n [in] length
74 * @param m [in] n = 2^m
75 */
76FFT_EXPORT extern void ditsplit(int n, int m);
77
78/**
79 * @brief
80 * Real valued, split-radix, decimation in time FFT.
81 *
82 * Data comes out as: [ Re(0), Re(1), ..., Re(N/2), Im(N/2-1), ..., Im(1) ]
83 */
84FFT_EXPORT extern void rfft(double *X, int N);
85
86/**
87 * @brief
88 * Split Radix, Decimation in Frequency, Inverse Real-valued FFT.
89 *
90 * Input order: [ Re(0), Re(1), ..., Re(N/2), Im(N/2-1), ..., Im(1) ]
91 *
92 * @param X [in] ?
93 * @param n [in] length
94 *
95 */
96FFT_EXPORT extern void irfft(double *X, int n);
97
98/**
99 * @brief
100 * Forward Complex Fourier Transform
101 *
102 * "Fast" Version - Function calls to complex math routines removed.
103 * Uses pre-computed sine/cosine tables.
104 *
105 * The FFT is:
106 *
107 * N-1
108 * Xf(k) = Sum x(n)(cos(2PI(nk/N)) - isin(2PI(nk/N)))
109 * n=0
110 */
111FFT_EXPORT extern void cfft(COMPLEX *dat, int num);
112
113/**
114 * Inverse Complex Fourier Transform
115 */
116FFT_EXPORT extern void icfft(COMPLEX *dat, int num);
117
118/**
119 * Complex divide (why is this public API when none of the other
120 * complex math routines are?)
121 */
122FFT_EXPORT extern void cdiv(COMPLEX *result, COMPLEX *val1, COMPLEX *val2);
123
124/* These should come from a generated header, but until
125 * CMake is live we'll just add the ones used by our current code */
126FFT_EXPORT extern void rfft256(register double X[]);
127FFT_EXPORT extern void irfft256(register double X[]);
128
129__END_DECLS
130
131/** @} */
132#endif /* FFT_H */
133
134/*
135 * Local Variables:
136 * mode: C
137 * tab-width: 8
138 * indent-tabs-mode: t
139 * c-file-style: "stroustrup"
140 * End:
141 * ex: shiftwidth=4 tabstop=8
142 */
Header file for the BRL-CAD common definitions.
void float float int * n
Definition: tig.h:74
void icfft(COMPLEX *dat, int num)
void rfft(double *X, int N)
Real valued, split-radix, decimation in time FFT.
void splitdit(int N, int M)
void irfft256(register double X[])
void cfft(COMPLEX *dat, int num)
Forward Complex Fourier Transform.
void ditsplit(int n, int m)
void cdiv(COMPLEX *result, COMPLEX *val1, COMPLEX *val2)
void irfft(double *X, int n)
Split Radix, Decimation in Frequency, Inverse Real-valued FFT.
void rfft256(register double X[])
@ X
Definition: vmath.h:397
Definition: fft.h:60
double re
Definition: fft.h:61
double im
Definition: fft.h:62