Efficient calculation of exact frequency from a broad frequency range (1 Hz - 1000 Hz)
Thanks for citing my blog article on frequency calculation.  Based on your emphasis on efficiency I am going to recommend a different approach which should get you equivalent or superior results with way fewer calculations.

The first thing you should do is smooth your signal heavily with exponential smoothing.  This will squash your harmonics and mitigate noise.  You can carry your results forward buffer by buffer so it is extremely efficient.  While you are doing the smoothing, you can also check for zero crossings.  The signal need not be a "nearly perfect sine curve" for zero crossings to give you a good estimate of the frequency.  After heavy smoothing, the zero crossing should correspond to your fundamental frequency.

If your signal is sufficiently sine like, you can calculate the frequency quite accurately by using the three point (simplest case) formula with the appropriate spacing that you can find here:  Exact Near Instantaneous Frequency Formulas Best at Peaks (Part 1).  You will want to select the center point at the peak (or trough) and the other two points at the nearest zero crossings.  This formula will give you as good results as if you did interpolation at the zero crossings and calculated the frequency from there.  You can then calculate the frequency at every peak and trough, that is every half cycle, and generate a new sequence of values.  You can then apply a best polynomial fit on intervals of this sequence to give you very good calculations of the frequency and how it is varying.

A more accurate, but slightly more computationally expensive approach would be to calculate two bins of the DFT and use the formula found in my article: Two Bin Exact Frequency Formulas for a Pure Real Tone in a DFT.  For the best result the frequency should fall halfway between the bins so you want to select a frame interval of a whole number of cycles and a half.  Two and a half would be a good compromise between getting an accurate reading with a varying frequency and getting a better reading with multiple cycles.  Point spacing is key for saving calculations.  Four points per cycle will give the best results, so you want to be close to that.  For two and a half cycles, that means ten points, which is not many.  Since you are calculating the bin values separately, there is no advantage to a power of two.  You can build lookup tables for the ten points for the two bin and three bin ahead of time to make it even more efficient.  Pick a uniform spacing parameter that gets you as close to two and a half cycles as you can.  Your calculations result in a cycles per frame value, then use your spacing value to convert to cycles per whatever your measure is.

Feel free to add any followup questions in your question and I will respond with an edit on my own.



I'm glad to hear you find my blog articles useful.

"How do you "heavy smooth" second harmonic when the base frequency could be 100x higher? "

Exponential smoothing has the property that the higher the frequency the more the tone will be attenuated.  If you are still getting multiple zero crossing then you still have higher harmonics present with significant amplitude.  Increase your smoothing parameter even more.  If you are working in floating point, you don't have to worry about destroying your fundamental frequency.  It will always be less dampened than the higher frequencies.

Since you have such a high sampling rate, you may also want to downsample your signal some as well.  There are many ways to do this, but since this is not an area of expertise for me, I will hold off on recommendations.  I can say the lowest calculation method is to just sample every nth point, but this does nothing to mitigate alias frequencies.  Another simple method is average intervals to get a new sequence.

The nice thing about picking a whole plus a half number of cycles for your frame is that the second harmonic (twice the fundamental frequency), and all even harmonics above it, are a whole (or very close to) number of cycles in the frame so they will be orthogonal to your basis vectors.  If there are a lot of harmonics present, you may want to increase the number of points above four per cycle to push the Nyquist frequency up for your frame length.

You can find my email address on my profile page.  Feel free to contact me there.

P.S.  Thanks to the upvoters.