waterfall_mesh

Function waterfall_mesh 

Source
pub fn waterfall_mesh<T>(
    x: &[T],
    fs: Option<f64>,
    nperseg: Option<usize>,
    noverlap: Option<usize>,
    log_scale: Option<bool>,
    db_range: Option<f64>,
) -> FFTResult<(Array2<f64>, Array2<f64>, Array2<f64>)>
where T: NumCast + Copy + Debug,
Expand description

Generate data for a mesh grid waterfall plot from a time-domain signal.

This function computes a spectrogram and organizes the data as separate time, frequency, and amplitude arrays suitable for mesh or surface plotting.

§Arguments

  • x - Input signal array
  • fs - 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:
    • Time mesh grid (T) - 2D array of time values
    • Frequency mesh grid (F) - 2D array of frequency values
    • Amplitude data (Z) - 2D array of amplitude values

§Errors

Returns an error if the computation fails or if parameters are invalid.

§Examples

use scirs2_fft::waterfall_mesh;
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 waterfall mesh data
let (time_mesh, freq_mesh, amplitudes) = waterfall_mesh(
    &chirp,
    Some(fs),
    Some(128),
    Some(64),
    Some(true),
    Some(80.0),
).unwrap();

// Verify dimensions are consistent
assert_eq!(time_mesh.shape(), freq_mesh.shape());
assert_eq!(time_mesh.shape(), amplitudes.shape());