The algo consists in two blocks :
- the first block takes the input samples and create a fifo list of maximas.
- the second block evaluates the periodicity of the signal based on the information in this list.
The first step of the first block consist in a lowpass filter to limit the number of maximas and to reject noise. A 50Hz or 60Hz rejecting filter can be added to prevent some problems.
Based on this signal, the first block detects maximas:

The amplitudes and "dates" of the maxima are interpolated by parabolic interpolation. (for convenience the dates are integers in the examples but they must be floats in the algo to obtain precise pitch detection).
They are put in the fifo list :


for each maximum, a "force" coefficient is calculated, it corresponds to the amplitude difference between the maximum and surrounding maxima. A "strong" maximum (for example 4) is not likely to disappear from one cycle to the other, a weak one can easily disappear because the maxima can "fuse" together (here 6 and 7).
Now, we are finished with the per-sample block that creates the maxima list. We switch to the pitch evaluation block.
Based on the last say 10 maxima, we select the stronger one (based on the force parameter).


This is the REFERENCE maximum.
Now, based on this REFERENCE maximum, we are looking for CANDIDATES. Many candidates will be evaluated and the best will be elected...
FOR EACH CANDIDATE :
Candidates can be pre-selected based on their amplitude compared to the REFERENCE :


Two maxima sublists are extracted from the REFERENCE and the CANDIDATE. The dates are set relative to the reference and to the candidate.


The two lists are merged and a flag describes the source (Reference or Candidate).

Now, maxima are processed by pairs:

A "distance" evaluation is performed
for each pair of maxima we accumulate the distance evaluator :
- When the sources (RC or CR) of the pair are different we add the absolute difference of their amplitudes.
- When the sources are equal (CC or RR) we add the forces of the two maxima.
Based on the distances of the candidates, the best candidate is elected. The difference of the dates of the elected candidate and of the reference is the period of the signal.
Here it is.
As far as I remember many other things were implemented in Ongaku to prevent octaviation. This patent only describes the basics.
Paul
PS I will not be online next week.

