A minimal Delphi/FireMonkey demonstration of how to use the fast Fourier transform library FFTW [1] from Delphi. A complex-valued random-walk signal is regenerated every 10 ms, transformed by a double-precision complex-to-complex FFT, and both the time-domain waveform and its raw spectrum are plotted in real time.
- LUX :Foundational mathematics library for the LUXOPHIA projects.
- LUX.Chart :Chart-plotting library providing the
TChartViewerframe. - LUX.FFTW :Delphi binding and object-oriented wrapper for the FFTW 3 library.
- Raw FFTW 3 binding —
fftw3.pastranslates the FFTW C API to Delphi: plan creation (basic / advanced / guru interfaces), complex-to-complex, real-to-complex/complex-to-real and real-to-real plans, wisdom import/export, threading, andfftw_malloc-family allocators, for both the double-precision (libfftw3-3.dll) and single-precision (libfftw3f-3.dll) libraries. - Object-oriented wrapper —
LUX.FFTWwraps plans in generic classes (TDFT<...>,TDFT1D<...>) whose input/output buffers are grid objects; resizing a grid automatically re-creates the plans. - Ready-made presets —
TSingleDFTcc1D/TDoubleDFTcc1Dprovide 1-D complex-to-complex transforms out of the box (2-D and 3-D preset units are also included in the library). - Live demo app — a FireMonkey form animates a Metropolis-type complex random walk, executes the forward transform each timer tick, and displays both domains with
TChartViewer; the transform length is adjustable at run time.
The discrete Fourier transform (DFT) of a length-$N$ complex sequence
and its inverse is
Evaluating (1) directly costs
FFTW's normalization convention. FFTW_FORWARD computes exactly the unnormalized sum (1), and FFTW_BACKWARD computes the sum in (2) without the TransTF) and plots the unnormalized spectrum
The demo signal. TDoubleRandWalkC (from the LUX library) maintains
Class hierarchy and data flow of the wrapper:
・TForm1 (Main.pas)
┣・_Wave :IDoubleRandWalkC ・・・ Metropolis complex random walk
┣・_FFT :IDoubleDFTcc1D ・・・ 1-D c2c double-precision DFT
┗・ChartViewerT / ChartViewerF ・・・ time/frequency plots [LUX.Chart]
Data flow (one timer tick)
・_Wave
┗・_FFT.Times ・・・ (x[n])
┣・ChartViewerT ・・・ time-domain plot
┗・TransTF ・・・ fftw_execute_dft via _PlanTF
┗・_FFT.Freqs ・・・ (X[k])
┗・ChartViewerF ・・・ frequency-domain plot
Class hierarchy
・IDFT
┗・TDFT<_TItem_,_TTimes_,_TFreqs_> ・・・ LUX.FFTW.pas
┣・_Times / _Freqs ・・・ grid buffers
┣・_PlanTF / _PlanFT ・・・ plans, run by TransTF/TransFT
┗・TDFT1D<...> ・・・ LUX.FFTW.D1.pas
┣・grid resize
┃ ┗・RecreaPlans ・・・ destroy + re-create plans
┗・TSingleDFTcc1D / TDoubleDFTcc1D ・・・ LUX.FFTW.D1.Preset.pas
Binding layers (call chain)
・TSingleDFTcc1D / TDoubleDFTcc1D
┗・fftw(f)_plan_dft_1d( N, in, out, direction, flags )
┗・fftw3.pas
┗・cdecl imports
┗・libfftw3-3.dll / libfftw3f-3.dll
File layout:
・FFTW/
┣・FFTW.dpr / FFTW.dproj ・・・ FireMonkey demo project
┣・Main.pas / Main.fmx ・・・ main form: charts, 10 ms timer, N scrollbar
┣・Win64/ ・・・ build output with FFTW DLLs (Debug/Release)
┣・--------/_SCREENSHOT/ ・・・ screenshot
┗・_LIBRARY/LUXOPHIA/ ・・・ git-subtree copies of library repositories
┣・LUX/ ・・・ core math & utilities (complex numbers etc.)
┣・LUX.Chart/ ・・・ TChartViewer plotting frame
┗・LUX.FFTW/ ・・・ FFTW binding and wrapper classes
┣・fftw3.pas ・・・ raw FFTW 3 API translation
┣・LUX.FFTW.pas ・・・ generic TDFT base classes
┗・D1/ D2/ D3/ ・・・ 1-D/2-D/3-D wrappers and presets
Library repositories: LUX, LUX.Chart, LUX.FFTW.
The animation starts automatically; a timer advances the random walk and re-runs the FFT every 10 ms.
| Control | Function |
|---|---|
| Upper chart | Time domain |
| Lower chart | Frequency domain |
| Vertical scrollbar (right) | Transform length |
| Label (top right) | Current value of |
Changing Times/Freqs grids, which automatically re-creates the FFTW plans.
- IDE: RAD Studio / Delphi (project format 19.5 = RAD Studio 11 Alexandria; later versions can upgrade the project).
- Framework: FireMonkey (FMX).
- Platforms: Win64 is the working target —
fftw3.paslinks against the Windows FFTW DLLs. - Required DLLs:
libfftw3-3.dll(double precision) andlibfftw3f-3.dll(single precision) must reside next toFFTW.exe. Copies of the FFTW 3.3.11 build from the MSYS2 mingw-w64-fftw package — including thelibfftw3_threads-3.dll/libfftw3f_threads-3.dllcompanions — are already bundled inWin64\Debug|Release.
Open FFTW.dproj, select the Win64 platform, and run. All library units are referenced directly from _LIBRARY\ — no search-path setup is needed.
- M. Frigo and S. G. Johnson, "The Design and Implementation of FFTW3", Proceedings of the IEEE, vol. 93, no. 2, pp. 216–231, 2005.
- Wikipedia: Discrete Fourier transform.
- J. W. Cooley and J. W. Tukey, "An Algorithm for the Machine Calculation of Complex Fourier Series", Mathematics of Computation, vol. 19, pp. 297–301, 1965.
- Wikipedia: Fast Fourier transform.
Integrated Development Environment (IDE) for Creating Native Cross-Platform Apps.
