-
Notifications
You must be signed in to change notification settings - Fork 739
feat: lfilter with batch support #1638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fe29555
f695635
68f551b
537a153
86fcc3d
01b73e1
b4839d5
415362b
ae4f503
dea25c2
cb992a3
a51e1b5
8fe3b7a
81ce039
1a171c7
049599d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -930,6 +930,7 @@ def lfilter( | |
| a_coeffs: Tensor, | ||
| b_coeffs: Tensor, | ||
| clamp: bool = True, | ||
| batching: bool = True | ||
| ) -> Tensor: | ||
| r"""Perform an IIR filter by evaluating difference equation. | ||
|
|
||
|
|
@@ -948,6 +949,10 @@ def lfilter( | |
| Lower delays coefficients are first, e.g. ``[b0, b1, b2, ...]``. | ||
| Must be same size as a_coeffs (pad with 0's as necessary). | ||
| clamp (bool, optional): If ``True``, clamp the output signal to be in the range [-1, 1] (Default: ``True``) | ||
| batching (bool, optional): Activate when coefficients are in 2D. If ``True``, then waveform should be at least | ||
| 2D, and the size of second axis from last should equals to ``num_filters``. | ||
| The output can be expressed as ``output[..., i, :] = lfilter(waveform[..., i, :], | ||
| a_coeffs[i], b_coeffs[i], clamp=clamp, batching=False)``. (Default: ``True``) | ||
|
|
||
| Returns: | ||
| Tensor: Waveform with dimension of either ``(..., num_filters, time)`` if ``a_coeffs`` and ``b_coeffs`` | ||
|
|
@@ -957,7 +962,11 @@ def lfilter( | |
| assert a_coeffs.ndim <= 2 | ||
|
|
||
| if a_coeffs.ndim > 1: | ||
| waveform = torch.stack([waveform] * a_coeffs.shape[0], -2) | ||
| if batching: | ||
| assert waveform.ndim > 1 | ||
| assert waveform.shape[-2] == a_coeffs.shape[0] | ||
| else: | ||
| waveform = torch.stack([waveform] * a_coeffs.shape[0], -2) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shape manipulation looks very complicated, and I wonder if it is because we have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's not related to |
||
| else: | ||
| a_coeffs = a_coeffs.unsqueeze(0) | ||
| b_coeffs = b_coeffs.unsqueeze(0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,. Should I make another MR to fix the docstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have time, please!