PowerBASIC Users Meeting Point
FFTW - Attn Dan Soper - Printable Version

+- PowerBASIC Users Meeting Point (http://pump.richheimer.de)
+-- Forum: User to User Discussions (http://pump.richheimer.de/forumdisplay.php?fid=3)
+--- Forum: Programming (http://pump.richheimer.de/forumdisplay.php?fid=7)
+--- Thread: FFTW - Attn Dan Soper (/showthread.php?tid=129)



FFTW - Attn Dan Soper - Ian Vincent - 19.05.2026

Dan, I saw your post on the pbusers.org site. I am not registered there.
I have played with FFTW in the past. 
It was a long time ago though, so not sure if everything you need is here, but it might get you started.
I could never make sense of the licencing for FFTW so moved to the Intel IPP, now OneAPI lib.
It includes a lot of other useful functions, but it takes a while to get into it


Here are my Declares:

Code:
%FFTW_FORWARD =-1
%FFTW_BACKWARD =1
%FFTW_ESTIMATE =64  '(1U << 6)  in c(rap)/c(razy) notation. IE bit 6 is set
Enum R2RTransformKinds
    HalfComplexDFT = 0
    HalfComplexIDFT = 1
    DHT = 2
    DCT1 = 3
    DCT2 = 5
    DCT3 = 4
    DCT4 = 6
    DST1 = 7
    DST2 = 9
    DST3 = 8
    DST4 = 10
End Enum

#If %DEF(%FFTW_Double)
Type complex
    real As Double
    Imag As Double
End Type


Declare Function fftw_plan_dft Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft" (ByVal DimCount As Long, ByRef DimSizes As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Sign As Long, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_1d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_1d" (ByVal Dim1Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Sign As Long, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_2d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_2d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Sign As Long, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_3d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_3d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByVal Dim3Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Sign As Long, ByVal Flags As Long) As Long

Declare Function fftw_plan_dft_r2c Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_r2c" (ByVal DimCount As Long, ByRef DimSizes As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_r2c_1d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_r2c_1d" (ByVal Dim1Size As Long, ByRef Src As Double, ByRef Dest As complex, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_r2c_2d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_r2c_2d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_r2c_3d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_r2c_3d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByVal Dim3Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Flags As Long) As Long

Declare Function fftw_plan_dft_c2r Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_c2r" (ByVal DimCount As Long, ByRef DimSizes As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_c2r_1d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_c2r_1d" (ByVal Dim1Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_c2r_2d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_c2r_2d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_c2r_3d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_dft_c2r_3d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByVal Dim3Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Flags As Long) As Long

Declare Function fftw_plan_r2r Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_r2r" (ByVal DimCount As Long, ByRef DimSizes As Long, ByRef Src As Double, ByRef Dest As Double, ByRef TransformKinds As Long, ByVal Flags As Long) As Long
Declare Function fftw_plan_r2r_1d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_r2r_1d" (ByVal Dim1Size As Long, ByRef Src As Double, ByRef Dest As Double, ByVal Dim1TransformKind As Long, ByVal Flags As Long) As Long

Declare Function fftw_plan_r2r_2d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_r2r_2d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByRef Src As Double, ByRef Dest As Double, _
ByVal Dim1TransformKind As Long, ByVal Dim2TransformKind As Long, ByVal Flags As Long) As Long

Declare Function fftw_plan_r2r_3d Lib "libfftw3-3.dll" CDecl Alias "fftw_plan_r2r_3d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByVal Dim3Size As Long, ByRef Src As Double, _
ByRef Dest As Double, ByVal Dim1TransformKind As Long, ByVal Dim2TransformKind As Long, ByVal Dim3TransformKind As Long, ByVal Flags As Long) As Long

Declare Sub fftw_execute Lib "libfftw3-3.dll" CDecl Alias "fftw_execute" (ByVal Plan As Long)
Declare Sub fftw_execute_dft Lib "libfftw3-3.dll" CDecl Alias "fftw_execute_dft" (ByVal Plan As Long, ByRef Src As Double, ByRef Dest As Double)
Declare Sub fftw_execute_dft_r2c Lib "libfftw3-3.dll" CDecl Alias "fftw_execute_dft_r2c" (ByVal Plan As Long, ByRef Src As Double, ByRef Dest As Double)
Declare Sub fftw_execute_dft_c2r Lib "libfftw3-3.dll" CDecl Alias "fftw_execute_dft_c2r" (ByVal Plan As Long, ByRef Src As Double, ByRef Dest As Double)
Declare Sub fftw_execute_r2r Lib "libfftw3-3.dll" CDecl Alias "fftw_execute_r2r" (ByVal Plan As Long, ByRef Src As Double, ByRef Dest As Double)

Declare Sub fftw_destroy_plan Lib "libfftw3-3.dll" CDecl Alias "fftw_destroy_plan" (ByVal Plan As Long)
Declare Sub fftw_cleanup Lib "libfftw3-3.dll" CDecl Alias "fftw_cleanup" ()
#EndIf

#If %DEF(%FFTW_Single)
Type complex
    real As Single
    Imag As Single
End Type

                                   
Declare Function fftw_plan_dft Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft" (ByVal DimCount As Long, ByRef DimSizes As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Sign As Long, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_1d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_1d" (ByVal Dim1Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Sign As Long, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_2d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_2d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Sign As Long, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_3d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_3d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByVal Dim3Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Sign As Long, ByVal Flags As Long) As Long

Declare Function fftw_plan_dft_r2c Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_r2c" (ByVal DimCount As Long, ByRef DimSizes As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_r2c_1d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_r2c_1d" (ByVal Dim1Size As Long, ByRef Src As Single, ByRef Dest As complex, ByVal Flags As Long) As Long

Declare Function fftw_plan_dft_r2c_2d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_r2c_2d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_r2c_3d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_r2c_3d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByVal Dim3Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Flags As Long) As Long

Declare Function fftw_plan_dft_c2r Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_c2r" (ByVal DimCount As Long, ByRef DimSizes As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_c2r_1d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_c2r_1d" (ByVal Dim1Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_c2r_2d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_c2r_2d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Flags As Long) As Long
Declare Function fftw_plan_dft_c2r_3d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_dft_c2r_3d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByVal Dim3Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Flags As Long) As Long

Declare Function fftw_plan_r2r Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_r2r" (ByVal DimCount As Long, ByRef DimSizes As Long, ByRef Src As Single, ByRef Dest As Single, ByRef TransformKinds As Long, ByVal Flags As Long) As Long
Declare Function fftw_plan_r2r_1d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_r2r_1d" (ByVal Dim1Size As Long, ByRef Src As Single, ByRef Dest As Single, ByVal Dim1TransformKind As Long, ByVal Flags As Long) As Long

Declare Function fftw_plan_r2r_2d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_r2r_2d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByRef Src As Single, ByRef Dest As Single, _
ByVal Dim1TransformKind As Long, ByVal Dim2TransformKind As Long, ByVal Flags As Long) As Long

Declare Function fftw_plan_r2r_3d Lib "libfftw3f-3.dll" CDecl Alias "fftwf_plan_r2r_3d" (ByVal Dim1Size As Long, ByVal Dim2Size As Long, ByVal Dim3Size As Long, ByRef Src As Single, _
ByRef Dest As Single, ByVal Dim1TransformKind As Long, ByVal Dim2TransformKind As Long, ByVal Dim3TransformKind As Long, ByVal Flags As Long) As Long

Declare Sub fftw_execute Lib "libfftw3f-3.dll" CDecl Alias "fftwf_execute" (ByVal Plan As Long)
Declare Sub fftw_execute_dft Lib "libfftw3f-3.dll" CDecl Alias "fftwf_execute_dft" (ByVal Plan As Long, ByRef Src As Single, ByRef Dest As Single)
Declare Sub fftw_execute_dft_r2c Lib "libfftw3f-3.dll" CDecl Alias "fftwf_execute_dft_r2c" (ByVal Plan As Long, ByRef Src As Single, ByRef Dest As Single)
Declare Sub fftw_execute_dft_c2r Lib "libfftw3f-3.dll" CDecl Alias "fftwf_execute_dft_c2r" (ByVal Plan As Long, ByRef Src As Single, ByRef Dest As Single)
Declare Sub fftw_execute_r2r Lib "libfftw3f-3.dll" CDecl Alias "fftwf_execute_r2r" (ByVal Plan As Long, ByRef Src As Single, ByRef Dest As Single)

Declare Sub fftw_destroy_plan Lib "libfftw3f-3.dll" CDecl Alias "fftwf_destroy_plan" (ByVal Plan As Long)
Declare Sub fftw_cleanup Lib "libfftw3f-3.dll" CDecl Alias "fftwf_cleanup" ()
#EndIf



And this is how I used it (sinearray is as it suggests an array of samples containing a sinwave):

Local n,Plan As Dword                                                                                         
ReDim amplitudearray(UBound(sinearray))                                                                                                                                                                                               

n=UBound(sinearray)
Plan= fftw_plan_dft_r2c_1d(n,  sinearray(0), amplitudearray(0), %FFTW_ESTIMATE )
fftw_execute (Plan)
fftw_destroy_plan(Plan)
fftw_cleanup()



RE: FFTW - Attn Dan Soper - Dan Soper - 20.05.2026

Hi Ian, 

Thank you for this. Just what I was looking for.

I thought it used an open-source licence though. I'll have to check.


d.