Python FFT API
High-performance 1-D and 2-D FFT backed by the native C dp_fft_*
functions.
Source:
python/dsp/doppler/fft/__init__.py
fft
doppler.fft — Fast Fourier Transform interface.
Wraps the C dp_fft_* functions. A single global plan is
maintained inside the C layer; call :func:setup (or the one-shot
:func:fft) before executing any transform.
Supported backends
- PocketFFT — bundled header-only library, always available.
- FFTW3 — used when the library is compiled with FFTW support. Enables planner effort levels and wisdom save/load.
Examples:
>>> import numpy as np
>>> import doppler.fft as nfft
>>>
>>> x = np.random.randn(1024).astype(np.complex128)
>>>
>>> # One-shot (setup + execute):
>>> X = nfft.fft(x)
>>>
>>> # Or explicit setup then execute:
>>> nfft.setup((1024,))
>>> X = nfft.execute1d(x)
setup
setup(shape, sign=-1, nthreads=1, planner='estimate', wisdom=None)
Set up (or reuse) the global FFT plan for the given shape.
Plans are cached by shape inside the C layer; subsequent calls with the same shape are effectively free.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
tuple of int
|
Dimensions of the transform. Use |
required |
sign
|
int
|
Transform direction. |
-1
|
nthreads
|
int
|
Number of threads. Only effective with FFTW3; PocketFFT is
single-threaded. Default |
1
|
planner
|
str
|
FFTW planner effort: |
'estimate'
|
wisdom
|
str or None
|
Path to an FFTW wisdom file, or |
None
|
Warning
High-effort planners overwrite data!
Heavier planners ("measure", "patient", etc.) time
transforms on your actual buffers — this erases the input
array. For one-shot transforms on live data, use the default
"estimate" planner.
Examples:
>>> import doppler.fft as nfft
>>> nfft.setup((1024,)) # 1-D plan, forward FFT
>>> nfft.setup((64, 64), sign=-1) # 2-D forward plan
execute1d
execute1d(x)
Execute an out-of-place 1-D FFT.
Uses the plan from the most recent :func:setup with a 1-D shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
1-D |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
1-D |
Examples:
>>> import numpy as np
>>> import doppler.fft as nfft
>>> nfft.setup((8,))
>>> X = nfft.execute1d(np.array([1, 0, 0, 0, 0, 0, 0, 0], dtype=complex))
execute1d_inplace
execute1d_inplace(x)
Execute a 1-D FFT in-place, overwriting the input array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
1-D |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The same array x after the transform. |
Examples:
>>> import numpy as np
>>> import doppler.fft as nfft
>>> nfft.setup((8,))
>>> x = np.array([1, 0, 0, 0, 0, 0, 0, 0], dtype=complex)
>>> nfft.execute1d_inplace(x) # x is modified
array([1.+0.j, ...])
execute2d
execute2d(x)
Execute an out-of-place 2-D FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
2-D |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
2-D |
Examples:
>>> import numpy as np
>>> import doppler.fft as nfft
>>> nfft.setup((64, 64))
>>> X = nfft.execute2d(np.zeros((64, 64), dtype=complex))
execute2d_inplace
execute2d_inplace(x)
Execute a 2-D FFT in-place, overwriting the input array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
2-D |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The same array x after the transform. |
Examples:
>>> import numpy as np
>>> import doppler.fft as nfft
>>> nfft.setup((64, 64))
>>> x = np.zeros((64, 64), dtype=complex)
>>> nfft.execute2d_inplace(x)
array([[0.+0.j, ...]])
execute
execute(x)
Execute a 1-D or 2-D FFT out-of-place (shape-dispatched).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
1-D or 2-D |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
FFT output of the same shape. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
execute_inplace
execute_inplace(x)
Execute a 1-D or 2-D FFT in-place (shape-dispatched).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
1-D or 2-D |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The same array x after the transform. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
fft
fft(x, sign=-1, nthreads=1, planner='estimate', wisdom=None)
Set up and execute a 1-D or 2-D FFT in a single call.
Equivalent to :func:setup followed by :func:execute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
1-D or 2-D |
required |
sign
|
int
|
|
-1
|
nthreads
|
int
|
Thread count (FFTW only). |
1
|
planner
|
str
|
FFTW planner effort. Default |
'estimate'
|
wisdom
|
str or None
|
FFTW wisdom file path, or |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
FFT output of the same shape. |
Examples:
>>> import numpy as np
>>> import doppler.fft as nfft
>>> X = nfft.fft(np.random.randn(1024).astype(complex))