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

Add frequency estimators by Jacobsen and Quinn #503

Merged
merged 27 commits into from
Mar 1, 2024
Merged

Add frequency estimators by Jacobsen and Quinn #503

merged 27 commits into from
Mar 1, 2024

Conversation

mbaz
Copy link
Contributor

@mbaz mbaz commented Jun 28, 2023

This commit adds two new frequency estimation algorithms:

* `jacobsen`, a very fast algorithm that performs a three-point
  curve fit around the DFT peak. Not super accurate.
* `quinn`, a very accurate iterative algorithm based on ARMA(2,2).
  It requires an initial frequency estimate (which may be
  provided by `jacobsen`).

Both algorithms work with real and complex signals.

    This commit adds two new frequency estimation algorithms:

    * `jacobsen`, a very fast algorithm that performs a three-point
      curve fit around the DFT peak. Not super accurate.
    * `quinn`, a very accurate iterative algorithm based on ARMA(2,2).
      It requires an initial frequency estimate (which may be
      provided by `jacobsen`).

    Both algorithms work with real and complex signals.
src/estimation.jl Outdated Show resolved Hide resolved
Miguel Bazdresch added 4 commits September 20, 2023 22:03
The `quinn` functions now only return a tuple with two values;
the first is the estimated frequency, and the other is a boolean
which is true if the algorithm ran for the maximum allowed number
of iterations. The `converged` return value is somewhat redundant
(and unavailable in the complex case).
@ViralBShah ViralBShah closed this Jan 20, 2024
@ViralBShah ViralBShah reopened this Jan 20, 2024
@ViralBShah
Copy link
Contributor

Is this good to merge?

@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.63%. Comparing base (10a7c1e) to head (64058c6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #503      +/-   ##
==========================================
+ Coverage   97.58%   97.63%   +0.05%     
==========================================
  Files          18       18              
  Lines        3147     3216      +69     
==========================================
+ Hits         3071     3140      +69     
  Misses         76       76              

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

@mbaz
Copy link
Contributor Author

mbaz commented Jan 20, 2024

Added a couple of tests to include the two lines that were missing coverage.

@ViralBShah
Copy link
Contributor

ViralBShah commented Jan 20, 2024

Perhaps good to wait for a bit for @martinholters to take a look.

src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
mbaz and others added 7 commits January 23, 2024 14:00
Co-authored-by: Martin Holters <[email protected]>
Co-authored-by: Martin Holters <[email protected]>
Co-authored-by: Martin Holters <[email protected]>
Co-authored-by: Martin Holters <[email protected]>
Co-authored-by: Martin Holters <[email protected]>
Co-authored-by: Martin Holters <[email protected]>
Co-authored-by: Martin Holters <[email protected]>
@mbaz
Copy link
Contributor Author

mbaz commented Jan 23, 2024

@martinholters Thank you for the review!

src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
test/estimation.jl Outdated Show resolved Hide resolved
test/estimation.jl Outdated Show resolved Hide resolved
test/estimation.jl Outdated Show resolved Hide resolved
Copy link
Member

@martinholters martinholters left a comment

Choose a reason for hiding this comment

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

Some more nit-picking...

src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
test/estimation.jl Outdated Show resolved Hide resolved
Miguel Bazdresch added 3 commits January 26, 2024 16:02
Before this commit, the `jacobsen` function did not perform any
interpolation when the DFT peak occurred at frequencies 0 or
Nyquist (`fs/2`).

Using the symmetry of the DFT, the estimation formula can be both
improved (by interpolating in all cases, with no exceptions), and
simplified (since the DFT values around the peak are (often) complex
conjugates).

This is slightly tricky because, in order to save computation
effort, we use the `rfft` instead of the `fft`. The formula can
be simplified when the peak occurs at 0, and when it occurs at
Nyquist and `N` is even.

The result is overall improved error performance near zero and
near Nyquist, even though in some frequency ranges the error
increases.
@ViralBShah
Copy link
Contributor

@mbaz In preparation for a 0.8 release, would it be possible for you to get this PR ready?

@mbaz
Copy link
Contributor Author

mbaz commented Feb 7, 2024

@ViralBShah I'm still actively working on it. Two things happened: (1) I realized applying Jacobsen to real signals requires a bit of care, and (2) my work load peaked the past two weeks.

My plan at the moment is to have a single Jacobsen estimator based on the DFT. If/when I work out the issues with an RFFT-based estimator, I'll make another PR. How does that sound?

What is the timeline for 0.8? I will try to finish up this PR in the next couple of days.

@ViralBShah
Copy link
Contributor

Thank you. There is no tight deadline, and we can always add new features in new releases. I am just thinking out aloud, but if we can get as much of the backlog of PRs in as we can in the next 2 weeks or so - that will make for a nice 0.8 release.

@martinholters I would of course defer to you on that.

@martinholters
Copy link
Member

Agree on the 0.8 release. Would be nice to get of bunch of things done for it which are (and some of them have been for while) in an almost-ready state. OTOH, I don't want to release 0.8 too hastily in case we discover something else that requires a breaking change. My gut feeling is that 2 to 4 weeks from now might be a good time.

@wheeheee wheeheee added this to the 0.8 milestone Feb 8, 2024
@ViralBShah
Copy link
Contributor

@mbaz Just a gentle nudge to see if possible to finish this PR. 0.8 may be in a week or two. But of course, if you are busy, there's always 0.9!

Miguel Bazdresch added 2 commits February 20, 2024 18:21
Jacobsen is sub-optimal for real signals. While the algorithm's
complexity can be reduced, compared to the complex case, by taking
advantage of the `rfft` transform, it is not really worth it given
the large estimation error involved.
@mbaz
Copy link
Contributor Author

mbaz commented Feb 20, 2024

The test failure seems to be related to codecov.

test/estimation.jl Outdated Show resolved Hide resolved
src/estimation.jl Outdated Show resolved Hide resolved
mbaz and others added 6 commits February 21, 2024 14:51
* Add explanation/warning about using Jacobsen with real signals
  to Jacobsen's docstring.
* Also document that, if input is real, the frequency estimate
  will be positive.
* Add tests for Jacobsen with real signals. The signal's frequency
  in these tests is close to Fs/4, where the estimation error is
  at its lowest.
When the frequency peak occurs at one of the spectrum extremes,
use the fact that the DFT is periodic to obtain the correct
spectrum values.
Copy link
Member

@martinholters martinholters left a comment

Choose a reason for hiding this comment

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

Thanks for your patience. I think it was worth it.

@mbaz
Copy link
Contributor Author

mbaz commented Feb 26, 2024

Thank you too, @martinholters -- the code is much better now than it was in the original PR.

@martinholters martinholters merged commit a38ae74 into JuliaDSP:master Mar 1, 2024
14 checks passed
@mbaz mbaz deleted the quinn-jacobsen branch March 1, 2024 13:55
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.

6 participants