| 1 | #ifndef _NUMFourier_h_ |
| 2 | #define _NUMFourier_h_ |
| 3 | /* NUMFourier.h |
| 4 | * |
| 5 | * Copyright (C) 2025 David Weenink |
| 6 | * |
| 7 | * This code is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or (at |
| 10 | * your option) any later version. |
| 11 | * |
| 12 | * This code is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "Data.h" |
| 22 | |
| 23 | #include "NUMFourierTable_def.h" |
| 24 | |
| 25 | autoNUMFourierTable NUMFourierTable_create (integer n); |
| 26 | |
| 27 | void NUMfft_forward (NUMFourierTable table, VEC data); |
| 28 | /* |
| 29 | Function: |
| 30 | Calculates the Fourier Transform of a set of n real-valued data points. |
| 31 | Replaces this data in array data [1...n] by the positive frequency half |
| 32 | of its complex Fourier Transform, with a minus sign in the exponent. |
| 33 | Preconditions: |
| 34 | data != NULL; |
| 35 | table must have been created with NUMFourierTable_create |
| 36 | Postconditions: |
| 37 | data [1] contains real valued first component (Direct Current) |
| 38 | data [2..n-1] even index : real part; odd index: imaginary part of DFT. |
| 39 | data [n] contains real valued last component (Nyquist frequency) |
| 40 | |
| 41 | Output parameters: |
| 42 | |
| 43 | data r(1) = the sum from i=1 to i=n of r(i) |
| 44 | |
| 45 | If l =(int) (n+1)/2 |
| 46 | |
| 47 | then for k = 2,...,l |
| 48 | |
| 49 | r(2*k-2) = the sum from i = 1 to i = n of r(i)*cos((k-1)*(i-1)*2*pi/n) |
| 50 | |
| 51 | r(2*k-1) = the sum from i = 1 to i = n of -r(i)*sin((k-1)*(i-1)*2*pi/n) |
| 52 | |
| 53 | if n is even |
| 54 | |
| 55 | r(n) = the sum from i = 1 to i = n of (-1)**(i-1)*r(i) |
| 56 | |
| 57 | i.e., the ordering of the output array will be for n even |
| 58 | r(1),(r(2),i(2)),(r(3),i(3)),...,(r(l-1),i(l-1)),r(l). |
| 59 | Or ...., (r(l),i(l)) for n uneven. |
| 60 | |
| 61 | ***** note |
| 62 | this transform is unnormalized since a call of NUMfft_forward |
| 63 | followed by a call of NUMfft_backward will multiply the input sequence by n. |
| 64 | */ |
| 65 | |
| 66 | void NUMfft_backward (NUMFourierTable table, VEC data); |
| 67 | /* |
| 68 | Function: |
| 69 | Calculates the inverse transform of a complex array if it is the transform of real data. |
| 70 | (Result in this case should be multiplied by 1/n.) |
| 71 | Preconditions: |
| 72 | n is an integer power of 2. |
| 73 | data [1] contains real valued first component (Direct Current) |
| 74 | data [2..n-1] even index : real part; odd index: imaginary part of DFT. |
| 75 | data [n] contains real valued last component (Nyquist frequency) |
| 76 | |
| 77 | table must have been created with NUMFourierTable_create |
| 78 | |
| 79 | Output parameters |
| 80 | |
| 81 | data for n even and for i = 1,...,n |
| 82 | |
| 83 | r(i) = r(1)+(-1)**(i-1)*r(n) |
| 84 | |
| 85 | plus the sum from k=2 to k=n/2 of |
| 86 | |
| 87 | 2.0*r(2*k-2)*cos((k-1)*(i-1)*2*pi/n) -2.0*r(2*k-1)*sin((k-1)*(i-1)*2*pi/n) |
| 88 | |
| 89 | for n odd and for i = 1,...,n |
| 90 | |
| 91 | r(i) = r(1) plus the sum from k=2 to k=(n+1)/2 of |
| 92 | |
| 93 | 2.0*r(2*k-2)*cos((k-1)*(i-1)*2*pi/n) -2.0*r(2*k-1)*sin((k-1)*(i-1)*2*pi/n) |
| 94 | |
| 95 | ***** note |
| 96 | this transform is unnormalized since a call of NUMfft_forward |
| 97 | followed by a call of NUMfft_backward will multiply the input |
| 98 | sequence by n. |
| 99 | */ |
| 100 | |
| 101 | |
| 102 | /**** Compatibility with NR fft's */ |
| 103 | |
| 104 | void NUMforwardRealFastFourierTransform (VEC data); |
| 105 | /* |
| 106 | Function: |
| 107 | Calculates the Fourier Transform of a set of n real-valued data points. |
| 108 | Replaces this data in array data [1...n] by the positive frequency half |
| 109 | of its complex Fourier Transform, with a minus sign in the exponent. |
| 110 | Preconditions: |
| 111 | n is an integer power of 2. |
| 112 | data != NULL; |
| 113 | Postconditions: |
| 114 | data [1] contains real valued first component (Direct Current) |
| 115 | data [2] contains real valued last component (Nyquist frequency) |
| 116 | data [3..n] odd index : real part; even index: imaginary part of DFT. |
| 117 | */ |
| 118 | |
| 119 | void NUMreverseRealFastFourierTransform (VEC data); |
| 120 | /* |
| 121 | Function: |
| 122 | Calculates the inverse transform of a complex array if it is the transform of real data. |
| 123 | (Result in this case should be multiplied by 1/n.) |
| 124 | Preconditions: |
| 125 | n is an integer power of 2. |
| 126 | data [1] contains real valued first component (Direct Current) |
| 127 | data [2] contains real valued last component (Nyquist frequency) |
| 128 | data [3..n] odd index : real part; even index: imaginary part of DFT. |
| 129 | */ |
| 130 | |
| 131 | void NUMrealft (VEC data, integer direction); |
| 132 | |
| 133 | #endif /* _NUMFourier_h_ */ |