fn denoise_value(new_val: u32, prev_val: u32, margin: f64) -> u32