pub fn wp_reconstruct(
tree: &WaveletPacketTree,
basis_nodes: &[WaveletPacketNode],
) -> Result<Vec<f64>, FFTError>Expand description
Reconstruct the signal from a set of wavelet packet nodes forming a basis.
The nodes must constitute a valid partition of the time-frequency plane
(e.g. those returned by best_basis). Mixed-level bases (where some nodes
are at depth 2 and others at depth 3, etc.) are fully supported.
§Arguments
tree– The original packet tree (provides wavelet & signal length).basis_nodes– A valid wavelet packet basis (partition of the root).
§Errors
Returns FFTError::InternalError if reconstruction encounters a missing node.
§Example
use scirs2_fft::wavelet_packets::{wpd, best_basis, wp_reconstruct, shannon_entropy, Wavelet};
let signal: Vec<f64> = (0..64).map(|i| (i as f64 * 0.1).sin()).collect();
let tree = wpd(&signal, Wavelet::Haar, 3).expect("decomp");
let basis = best_basis(&tree, shannon_entropy).expect("basis");
let recon = wp_reconstruct(&tree, &basis).expect("recon");
assert_eq!(recon.len(), signal.len());
// Perfect reconstruction (approx)
for (a, b) in signal.iter().zip(recon.iter()) {
assert!((a - b).abs() < 1e-10, "mismatch: {} vs {}", a, b);
}