Skip to content
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

Deprecate filt/filt! with si parameter #603

Merged
merged 7 commits into from
Dec 6, 2024
Merged

Conversation

martinholters
Copy link
Member

The radical alternative to #599. If you need stateful filtering, use DF2TFilter. After #602, this shouldn't take away any functionality, just restrict the interface to enforce the use of DF2TFilter.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.96%. Comparing base (ade83dd) to head (dbdbb7d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #603      +/-   ##
==========================================
+ Coverage   97.91%   97.96%   +0.05%     
==========================================
  Files          19       19              
  Lines        3262     3248      -14     
==========================================
- Hits         3194     3182      -12     
+ Misses         68       66       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wheeheee
Copy link
Member

wheeheee commented Dec 3, 2024

I noticed that the test against Matlab output (filt_check.txt) was dropped. I think that test could have been modified to use DF2TFilter, so was this because of the decision to phase out testing against Matlab samples, or another reason?

@martinholters
Copy link
Member Author

I noticed that the test against Matlab output (filt_check.txt) was dropped. I think that test could have been modified to use DF2TFilter, so was this because of the decision to phase out testing against Matlab samples, or another reason?

Mostly because I was hoping the DF2TFilter is sufficiently tested. Though I didn't check, so that may be false.

But indeed, I was somewhat satisfied to see another of those tests against Matlab samples go. However, if DF2TFilter is indeed undertested, I'll reinstate it. (I'd prefer a test where it's easier to tell what the correct result is than by invoking another filter implementation, but that's for another day...)

@martinholters
Copy link
Member Author

Re-added that test.

@wheeheee
Copy link
Member

wheeheee commented Dec 3, 2024

I do like this a lot more than returning the state. How well would this be received downstream? i.e. does anyone actually pass si to filt?

@wheeheee
Copy link
Member

wheeheee commented Dec 3, 2024

There are some really weird GC allocations from NTuple and Float64 in _filt_fir! when N=15 but I don't see noticeable performance regressions, so whatever.

@wheeheee
Copy link
Member

wheeheee commented Dec 4, 2024

Added another (simpler?) test back. I think 2 tests using an initial state isn't too much.

@martinholters
Copy link
Member Author

How well would this be received downstream? i.e. does anyone actually pass si to filt?

I don't know. I don't think it's particularly useful in its current form (hence #599 and this PR), so widespread use would surprise me. However, I don't want to rush this PR, so that more people get the chance to stumble upon it and raise any objections they might have. That said, I think I'll add deprecations so that code passing si to filt can continue to function and any users get more time to switch to DF2TFilter. (Or complain loud enough that we can add it back during 0.8.x, potentially with #599 reconsidered.)

@wheeheee
Copy link
Member

wheeheee commented Dec 4, 2024

I have a niggling concern about PolynomialRatio, specifically the calls to coefa and coefb which allocate. If DF2TFilter is used to filter relatively short signals, the overhead might be quite large.
One possible solution would be to decouple the FilterCoefficients type parameter from internal storage inside the DF2TFilter type, and store coefs==(coefb(p), coefa(p)) inside DF2TFilter{PolynomialRatio{:z}}. The filter coefficient object could be retrieved by passing the DF2TFilter to, say, FilterCoefficients or another appropriately named function (relatedly, should we provide a public function to retrieve the state?). But would it be worth the added complexity?

@martinholters
Copy link
Member Author

Hm, that's a bit unfortunate indeed. We could also drop the <:FilterCoefficients{:z} from the DF2TFilter type parameter (or relax it) to allow (b,a)::Tuple{Vector,Vector} to be stored as coef. Or we make coefa/coefb non-allocating. The latter would be nice anyway, but is certainly trickier, too. I see two options:

  • Implement a small AbstractVector subtype that forwards getindex to the underlying LaurentPolynomial after the necessary index transformation. But that would need some benchmarking how bad this index transformation is in tight loops like filtering.
  • Revert PolynomialRatio back to storing the coefficients directly as Vectors. I switched these to LaurentPolynomials a while ago because there was some confusion within DSP.jl how the coefficients had to be interpreted, and by representing them as Polynomials, that was made clear. But I don't think anything critically depends on these being Polynomials.

None of these options strikes me as ideal. But I'm fairly confident there is some way forward, so no reason to block this PR I'd hope.

Copy link
Member

@wheeheee wheeheee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Thought you wanted to add some deprecations and maybe even more documentation/tests, but I suppose that can go in another PR if needed.

@martinholters
Copy link
Member Author

Deprecations are in the works. Stay tuned.

@martinholters martinholters changed the title Drop si parameter from filt/filt! Deprecate filt/filt! with si parameter Dec 4, 2024
@wheeheee
Copy link
Member

wheeheee commented Dec 4, 2024

LGTM. I guess for two AbstractVectors the repeat in the deprecated functions basically just copies, but it's good to be clear like this too.

@martinholters
Copy link
Member Author

I guess for two AbstractVectors the repeat in the deprecated functions basically just copies

That should be covered by the more specific deprecations for that case, or am I misunderstanding?

@wheeheee
Copy link
Member

wheeheee commented Dec 4, 2024

Yeah, I meant to say that e.g. lines 7-10 could be omitted. But it's good as is.

@martinholters martinholters merged commit 16f1ec0 into master Dec 6, 2024
11 checks passed
@martinholters martinholters deleted the mh/no-filt-state branch December 6, 2024 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants