dspectra: 2D Fast Fourier Transform (FFT) DTM Bedform Wavelength & Azimuth Analysis
Overview & Purpose
dspectra (dspectra.c / dspectra.h, 1,251 lines) is a 2D spatial frequency-domain processing library authored by Danar G. Pratomo in October 2012 for analyzing submarine sand waves, ripples, and periodic bedforms in Digital Terrain Models (DTMs). Given a square power-of-two ($N \times N$) bathymetric grid patch, dspectra provides the complete signal conditioning and 2D spectral analysis pipeline:
- Mean Removal & Detrending: Strips mean depth (
d_remove_patch_average) or regional planar/quadratic seafloor tilt (d_detrend_patchviadmatrix). - Radial Edge Tapering: Applies a radially symmetric cosine/sine taper window (
d_taper_patch) to suppress spectral leakage from patch boundaries. - 2D Forward & Inverse FFT: Wraps the Numerical Recipes multidimensional FFT (
fournfromfour1.c) to compute 2D complex spectra, centered amplitude/power spectra (d_fft_shift,d_spectral_dB), phase spectra (d_fft_phase), and spatial reconstructions (d_fft_inverse). - Directional & Wavenumber Filtering: Supports bandpass/lowpass/highpass radial wavenumber filtering (
d_patch_filter,d_patchfilter) and directional wedge filtering (d_azimuthfilter). - Automated Bedform Crest Extraction: Identifies dominant spectral peaks (
d_get_patch_maxima_lamda_azimuth,d_getmax) to extract bedform wavelength ($\lambda$, in meters) and crest orientation azimuth (degrees), and extracts 1D directional profiles (get_azi_profile).
Key Constants & Data Structures
Spectral Peak & Cluster Structures (d_wave_cluster, d_spectra_analysis)
#define MAX_CLUSTERS 10
#define MAX_FFT_WIDTH 1024
typedef struct {
int peak_x, peak_y; /* 2D FFT grid coordinates of the spectral peak */
float peak_frequency; /* Spatial frequency (cycles per meter) */
float peak_wavelength_m; /* Dominant bedform wavelength (meters) */
float peak_azimuth_deg; /* Dominant propagation azimuth (degrees, 0..360) */
float peak_amplitude; /* Spectral peak magnitude */
float wavelength_variance; /* Cluster variance in wavelength */
float azimuth_variance; /* Cluster variance in azimuth */
} d_wave_cluster;
typedef struct {
int no_clusters;
d_wave_cluster cluster[MAX_CLUSTERS];
} d_spectra_analysis;
1D Azimuthal Slice Structure (custom_slices)
typedef struct {
float dtm_peak_azi[MAX_FFT_WIDTH]; /* DTM profile along dominant peak azimuth */
float dtm_user_azi[MAX_FFT_WIDTH]; /* DTM profile along user-selected azimuth */
float fft_peak_azi[MAX_FFT_WIDTH]; /* FFT spectrum profile along peak azimuth */
float fft_user_azi[MAX_FFT_WIDTH]; /* FFT spectrum profile along user azimuth */
float wavelength[MAX_FFT_WIDTH]; /* Wavelength axis for slice */
float frequency[MAX_FFT_WIDTH]; /* Spatial frequency axis for slice */
float step_size; /* Spatial step size along slice (meters) */
int dimension; /* Number of samples in slice */
} custom_slices;
extern custom_slices slice;
Public Functions & Signatures
Spatial Pre-Conditioning (Detrending & Windowing)
int d_remove_patch_average(int rows, int cols, float *indata, float *outdata)Computes the mean of all non-zero pixels inindataand subtracts it to produce a zero-mean patch inoutdata.int d_detrend_patch(int rows, int cols, float *indata, float *detrend_data, float *residual_data, int trendtype)Promotesindatato double precision and callsdTrend(trendtype == 1, planar) ordTrendPoly(trendtype == 2, quadratic dome/trough) fromdmatrix.c, outputting the detrended bathymetry indetrend_dataand the fitted regional trend surface inresidual_data.int d_taper_patch(int rows, int cols, float frac_OK, float *indata, float *outdata)Applies a circular window of radiusrows / 2: pixels within normalized radius $r < \text{frac_OK}$ retain weight1.0, pixels in $\text{frac_OK} \le r < 1.0$ are smoothly tapered to zero with a half-sine roll-off, and corners outside $r \ge 1.0$ are zeroed.
2D FFT & Spectral Transformation Functions
int d_do_patch_spectra(int rows, int cols, float *indata, float *ampdata, float *phasedata, float *invdata, int doinverse)Executes a 2D forward (doinverse == 1) or inverse (doinverse == -1) FFT viafourn(indata - 1, nn, 2, doinverse)and quadrants-shifts the normalized magnitude spectrum intoampdata.int d_fft_forward(int rows, int cols, float *indata, float *outdata1, float *outdata2)Interleaves real arrayindatainto complex pairs (d_spaced), runsfourn(..., 1), writes the 2D amplitude spectrum tooutdata1(d_fft_amplitude), and preserves the raw complex spectrum inoutdata2for frequency-domain filtering.int d_fft_inverse(int rows, int cols, float *indata, float *outdata)Executes inverse 2D FFTfourn(indata - 1, nn, 2, -1)and scales the real part by $1 / (\text{rows} \times \text{cols})$.int d_fft_amplitude(...),int d_fft_phase(...),int d_fft_shift(...),int d_spectral_dB(...)Extracts magnitude, phase angle, DC-centered quadrant shift, and $20 \log_{10}$ decibel spectra.
Spectral Filtering & Bedform Peak Picking
int d_patch_filter(...)/int d_patchfilter(int rows, int cols, float frac_filter, float *indata, float *outdata, int dofilt)Applies radial frequency-domain lowpass or highpass masks.int d_azimuthfilter(int rows, int cols, float azimuth, float frac_azi, float *indata, float *outdata)Filters the 2D spectrum within an angular sector (frac_azi) aroundazimuthto isolate bedforms propagating in a specific direction.int d_get_patch_maxima_lamda_azimuth(int rows, int cols, float wave_len, float size_pixel, float *amp_data, d_spectra_analysis *spec_anal)&int d_getmax(...)Searches the upper half-plane of the shifted 2D amplitude spectrumamp_datafor local maxima, converting peak wavenumber coordinates $(k_x, k_y)$ and grid cell sizesize_pixelinto wavelength $\lambda$ (meters) and propagation azimuth (degrees).int get_azi_profile(float *indata, float azimuth, int xdim, int ydim, float *theslice)&int calc_wavelength_or_period(custom_slices *slices)Extracts a 1D cross-sectional slice through the DTM or 2D FFT alongazimuth.
How It Fits Into the OMG Architecture
dspectra powers the interactive 2D FFT analysis window in jview (code/JV/JV_FFT2D.h) and the command-line spectral tool fft2dimage (code/image/fft2dimage.c), allowing researchers to select a DTM sub-patch, inspect its 2D wavenumber spectrum, filter directional artifacts or sand waves, and automatically measure sand-wave wavelengths and migration directions.