Skip to main content

Crate ppsd_rs

Crate ppsd_rs 

Source
Expand description

Seismic PPSD (Probabilistic Power Spectral Density) computation.

A pure-Rust implementation of the McNamara & Buland (2004) PPSD algorithm, matching ObsPy’s PPSD output within 0.5 dB tolerance. Uses stationxml_rs::Response directly for instrument response evaluation — no intermediate types needed.

§Algorithm

The PPSD pipeline for each time segment:

  1. Welch’s method — overlap-averaged periodogram with cosine taper and linear detrend
  2. Instrument response removal — evaluates PAZ, FIR, and Coefficients stages from stationxml_rs::Response, then divides PSD by |H(f)|²
  3. Velocity→acceleration correction — multiplies by ω² = (2πf)²
  4. dB conversion — 10 × log₁₀(PSD)
  5. Period binning — averages dB values into octave-spaced period bins

§Quick Start

use ppsd_rs::process_segment;

// Load inventory (FDSN StationXML or SC3ML — auto-detected)
let inv = stationxml_rs::read_from_file("IA.JAGI.xml").unwrap();
let channel = &inv.networks[0].stations[0].channels[0];
let response = channel.response.as_ref().unwrap();
let sample_rate = channel.sample_rate;

// Compute PSD for one segment
let result = process_segment(
    &samples, sample_rate, nfft, nlap,
    response, &psd_periods, &bin_left, &bin_right,
).unwrap();

§Response Evaluation

eval_response walks all stages in a stationxml_rs::Response and computes the combined |H(f)|²:

Stage typeTypeMethod
Sensorstationxml_rs::PolesZerosLaplace transfer function × gain
ADCstationxml_rs::Coefficients (Digital)DTFT of numerators × gain
FIR filterstationxml_rs::FIRDTFT with DC normalization × gain
Gain-only(none of above)gain²

FIR coefficients are DC-normalized to match evalresp behavior. stationxml_rs::Symmetry expansion is handled automatically (None = all coefficients, Even = mirror, Odd = mirror with negation).

Enums§

PpsdError
Errors that can occur during PSD computation.

Functions§

cosine_taper
Cosine taper (Tukey window) matching ObsPy’s cosine_taper(npts, p).
eval_response
Evaluate full instrument response |H(f)|² at given frequencies.
fft_power
Compute one-sided power spectrum via real FFT.
konno_ohmachi_smooth
Konno-Ohmachi log-frequency spectral smoothing.
period_bin_average
Bin PSD values into period bins by averaging (ObsPy style).
process_segment
Process one PPSD segment, replicating ObsPy’s PPSD.__process exactly.
setup_period_binning
Compute period binning edges matching ObsPy PPSD._setup_period_binning.
welch_psd
Compute PSD using Welch’s method matching ObsPy/matplotlib’s mlab.psd.

Type Aliases§

Result
Result type for ppsd operations.