Skip to main content

process_segment

Function process_segment 

Source
pub fn process_segment(
    segment: &[f64],
    sample_rate: f64,
    nfft: usize,
    nlap: usize,
    response: &Response,
    psd_periods: &[f64],
    bin_left: &[f64],
    bin_right: &[f64],
) -> Result<Vec<Option<f64>>>
Expand description

Process one PPSD segment, replicating ObsPy’s PPSD.__process exactly.

Performs the full pipeline:

  1. Welch PSDmlab.psd with cosine taper and linear detrend
  2. Reorder — skip DC bin, reverse to period order
  3. Response removal — divide by |H(f)|² and multiply by ω² (velocity→acceleration)
  4. dB conversion — 10 × log₁₀(PSD)
  5. Period bin averaging — octave-spaced bins

Takes stationxml_rs::Response directly — no intermediate types needed.

§Arguments

  • segment — Time-domain samples for one PPSD segment.
  • sample_rate — Sampling rate in Hz.
  • nfft — FFT length for Welch’s method.
  • nlap — Overlap samples for Welch’s method.
  • response — Instrument response from stationxml_rs::Channel.
  • psd_periods — Period values (seconds) from the Welch FFT.
  • bin_left — Left edges of period bins (seconds).
  • bin_right — Right edges of period bins (seconds).

§Returns

Vector of Option<f64> — dB values per period bin. None for empty bins.

§Errors

Returns PpsdError if response evaluation fails (see eval_response).