Frequency quantization for stable pitch detection

Just Evan's icon

Hello! I have tried many times to achieve stable tone/pitch detection of the input audio using fzero~ or MUBU pipo.yin/psy, but every time I got small jumps from note to note, where it seemed that the ableton tuner behaves quite calmly, or any spectrum analyzer displays the desired frequency without any problems.

And now the thought has crossed my mind, what if I specify “anchor” frequencies within the radius of which the input value will be equated to it (“anchor” key frequency)...

I'm not sure how to do this yet, just sharing my thoughts....

Perhaps someone knows a better way?

Or will give a useful hint, while I'm trying to figure out how to do it myself )

Just Evan's icon

UPD: Here's what GPT thinks about it. Some of the ways seem interesting.

1. Smoothing values: You can use filters (e.g., low-pass filters) to smooth the output values from fzero~ or other analyzers. This will help reduce spikes and make the detection smoother.

2. Frequency quantization: you can create an array of “anchor” frequencies (e.g., frequencies of notes in an octave) and equate the output value to the nearest “anchor” frequency. This can be done with a simple algorithm that will find the nearest frequency from the array and return it.

3.Use Thresholds: Set thresholds to determine when a value is considered stable enough. For example, if the output value is within ±5-10 Hz of the “anchor” frequency, you can consider it equal to that frequency.

4. time window analysis: Instead of analyzing each value in real time, you can use time windows (e.g., 100-200 ms) to analyze and determine a stable frequency. This can help avoid abrupt changes.

5. Combining methods: Try combining several methods to achieve the best result. For example, use smoothing together with frequency quantization.

TFL's icon

These are all valid suggestions.

For smoothing, you could use [slide~] or [rampsmooth~], or if you're in the data rate domain: [slide] or a [p smoov] that you can find by searching in the forum.

For the other, it really depends on what you really want to do, as usual. What is this pitch detection for? A tuner? Pitch correction? Driving other events? Generating some partitions from the audio?

Roman Thilenius's icon

when analyzing audio, such as for intonation or dynamic transients information, the first thing you should include is a bandpassfilter, a noise gate and a peak gate for preprocessing.

then suddenly even the fzero methods or the good old fiddle suddenly output useful data for complex, spectral rich input.

Roman Thilenius's icon

apropos quantization: simply [ftom~] [+~ 0.5] [trunc~] [mtof~] (at least for equal temperament)

Jean-Francois Charles's icon

Also compare [fzero~] with [retune~ @pitchdetection 1]