Fix: ensure impulse response returns at least one bin when width < dt… #914
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bugfix-for-issue #851: Ensure Non-Zero Impulse Response by robustly handling computation for Small Widths in
simple_ir
Summary
This pull request addresses an edge case in the
simple_ir
method where passing a smallwidth
value—specifically, one smaller thanself.dt
—results in a zero-length impulse response. This occurs because the number of bins is computed using integer division, which truncates the result to zero forwidth < self.dt
. Along with a fine-tuning of rounding off of the (width/ self.dt), initially, we were truncating it to the nearest lower int, but for robust handling of all casesmath.ceil()
can be used.🔧 Fix
Original Code:
Updated Code:
This ensures that for any non-zero
width
, there will always be at least one non-zero bin in the impulse response.Bug Description
The impulse response was being generated using:
If the
width
is smaller thanself.dt
, this computation yields zero bins, effectively omitting the impulse response entirely, despite the user intending to generate a small impulse.Sample Input
Current Output:
Expected Output:
The expected behavior is that even a short width (e.g., 0.6) should produce a visible impulse response (at least one non-zero value) after the delay.
🔍 Fix and Rationale
📊 Output Comparison Table
width
)dt
num_bins
int(width / dt)
[0. 0. 0.]
ceil(width / dt)
[0. 0. 0. 1.]
This change ensures accuracy across a broader range of valid
width
values.❓ Open Question for Reviewers
I would like to know if the rounding off to a lower integer is intentional or is it fine that we round off the (width/self.dt) to the next larger integer.
✅ Benefits
✅ Checklist
width >= dt
Let me know if further refinements or configuration support is required!