Skip to content

Commit

Permalink
add constant time exp avg
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Sep 28, 2023
1 parent 9f3ad77 commit 03ef6dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Opts {
#[arg(short, long, default_value_t = 1.0f32)]
fs: f32,

/// Exponential averaging
/// Exponential averaging alpha, negative for constant time, positive for constant noise
#[arg(short, long)]
avg: Option<f32>,
}
Expand Down
9 changes: 8 additions & 1 deletion src/psd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,14 @@ impl<const N: usize> PsdCascade<N> {
stage.set_stage_depth(self.stage_length);
stage.set_detrend(self.detrend);
stage.set_overlap(self.overlap);
stage.set_avg(self.avg);

stage.set_avg(self.avg.map(|avg| {
if avg < 0.0 {
(-avg * (1 << (self.stage_length * i)) as f32).min(1.0)
} else {
avg
}
}));
self.stages.push(stage);
}
&mut self.stages[i]
Expand Down

0 comments on commit 03ef6dc

Please sign in to comment.