| 5 |
| 6 | ## Scratch buffer |
| 7 | The caller can optionally provide a scratch buffer. When not provided, VLA is used to provide a thread-safe option. |
| 8 | However, it is recommended to write a C++ wrapper which allocates its own scratch buffer. |
| 9 | Note that the scratch buffer has the same memory alignment requirements of the input and output vectors. |
| 10 |
| 11 | ## Output layout |
| 12 | PFFFT computes the forward transform with two possible output layouts: |
| 13 | 1. ordered |
| 14 | 2. unordered |
| 15 |
| 16 | ### Ordered layout |
| 17 | Calling `pffft_transform_ordered` produces an array of **interleaved real and imaginary parts**. |
| 18 | The last Fourier coefficient is purely real and stored in the imaginary part of the DC component (which is also purely real). |
| 19 |
| 20 | ### Unordered layout |
| 21 | Calling `pffft_transform` produces an array with a more complex structure, but in a more efficient way than `pffft_transform_ordered`. |
| 22 | Below, the output produced by Matlab and that produced by PFFFT are compared. |
| 23 | The comparison is made for a 32 point transform of a 16 sample buffer. |
| 24 | A 32 point transform has been chosen as this is the minimum supported by PFFFT. |
| 25 |
| 26 | Important notes: |
| 27 | - In Matlab the DC (Matlab index 1 [R1, I1]]) and Nyquist (Matlab index 17 [R17, I17]) values are not repeated as complex conjugates. |
| 28 | - In PFFFT the Nyquist real and imaginary parts ([R17, I17]) are omitted entirely. |
| 29 | - In PFFFT the final 8 values (4 real and 4 imaginary) are not in the same order as all of the others. |
| 30 | - In PFFFT all imaginary parts are stored as negatives (like second half in Matlab). |
| 31 |
| 32 | ``` |
| 33 | +-------+-----------+-------+-------+ |
| 34 | | Index | Matlab | Index | PFFFT | |
| 35 | +-------+-----------+-------+-------+ |
| 36 | | 1 | R1 + I1 | 0 | R1 | |
| 37 | | 2 | R2+ I2 | 1 | R2 | |
| 38 | | 3 | R3 + I3 | 2 | R3 | |
| 39 | | 4 | R4 + I4 | 3 | R4 | |
| 40 | | 5 | R5 + I5 | 4 | -I1 | |
| 41 | | 6 | R6 + I6 | 5 | -I2 | |
| 42 | | 7 | R7 + I7 | 6 | -I3 | |
| 43 | | 8 | R8 + I8 | 7 | -I4 | |
| 44 | | 9 | R9 + I9 | 8 | R5 | |
| 45 | | 10 | R10 + I10 | 9 | R6 | |
| 46 | | 11 | R11 + I11 | 10 | R7 | |
| 47 | | 12 | R12 + I12 | 11 | R8 | |
| 48 | | 13 | R13 + I13 | 12 | -I5 | |
| 49 | | 14 | R14 + I14 | 13 | -I6 | |
| 50 | | 15 | R15 + I15 | 14 | -I7 | |
| 51 | | 16 | R16 + I16 | 15 | -I8 | |
| 52 | | 17 | R17 + I17 | 16 | R9 | |
| 53 | | 18 | R16 - I16 | 17 | R10 | |
| 54 | | 19 | R15 - I15 | 18 | R11 | |
| 55 | | 20 | R14 - I14 | 19 | R12 | |
| 56 | | 21 | R13 - I13 | 20 | -I9 | |
| 57 | | 22 | R12 - I12 | 21 | -I10 | |
| 58 | | 23 | R11 - I11 | 22 | -I11 | |
| 59 | | 24 | R10 - I10 | 23 | -I12 | |
| 60 | | 25 | R9 - I9 | 24 | R13 | |
| 61 | | 26 | R8 - I8 | 25 | R16 | |
| 62 | | 27 | R7 - I7 | 26 | R15 | |
| 63 | | 28 | R6 - I6 | 27 | R14 | |
| 64 | | 29 | R5 - I5 | 28 | -I13 | |
| 65 | | 30 | R4 - I4 | 29 | -I16 | |
| 66 | | 31 | R3 - I3 | 30 | -I15 | |
| 67 | | 32 | R2 - I2 | 31 | -I14 | |
| 68 | +-------+-----------+-------+-------+ |
| 69 | ``` |
| 70 |