pub fn waterfall_mesh_colored<T>(
x: &[T],
fs: Option<f64>,
nperseg: Option<usize>,
noverlap: Option<usize>,
log_scale: Option<bool>,
db_range: Option<f64>,
) -> FFTResult<(Array2<f64>, Array2<usize>, Array2<f64>)>
Expand description
Generate coordinates for a color mesh waterfall plot from a time-domain signal.
This function computes a spectrogram and organizes the data as arrays of vertices, faces, and colors suitable for triangulated surface plots.
§Arguments
x
- Input signal arrayfs
- Sampling frequency of the signal (default: 1.0)nperseg
- Length of each segment (default: 256)noverlap
- Number of points to overlap between segments (default:nperseg // 2
)log_scale
- Whether to use logarithmic (dB) scale for amplitudes (default: true)db_range
- Dynamic range in dB for normalization when using log scale (default: 60.0)
§Returns
- A tuple containing:
- Vertices array - Nx3 array of [x,y,z] coordinates for each vertex
- Faces array - Mx3 array of vertex indices defining triangular faces
- Colors array - Nx3 array of [r,g,b] colors for each vertex (normalized to [0,1])
§Errors
Returns an error if the computation fails or if parameters are invalid.
§Examples
use scirs2_fft::waterfall_mesh_colored;
use std::f64::consts::PI;
// Generate a chirp signal
let fs = 1000.0; // 1 kHz sampling rate
let t = (0..1000).map(|i| i as f64 / fs).collect::<Vec<_>>();
let chirp = t.iter().map(|&ti| (2.0 * PI * (10.0 + 50.0 * ti) * ti).sin()).collect::<Vec<_>>();
// Compute colored mesh data
let (vertices, faces, colors) = waterfall_mesh_colored(
&chirp,
Some(fs),
Some(128),
Some(64),
Some(true),
Some(80.0),
).unwrap();
// Verify dimensions
assert_eq!(vertices.shape()[1], 3); // [x,y,z] coordinates
assert_eq!(faces.shape()[1], 3); // Triangle vertex indices
assert_eq!(colors.shape()[1], 3); // [r,g,b] values
assert_eq!(vertices.shape()[0], colors.shape()[0]); // Same number of vertices and colors