frequency meter

charles-jean oliot's icon

charles-jean oliot

Jan 9, 2022, 6:30 PM

How make a frequency meter ? (sorry for my english, I,m Frensch )
Thanks

charles-jean oliot's icon

charles-jean oliot

Jan 9, 2022, 6:32 PM

How to get the fundamental frequency of a signal in a CERTAIN way?

Roman Thilenius's icon

Roman Thilenius

Jan 9, 2022, 8:12 PM


"fundamental frequency" is a matter of human recognition, so you can not measure or track it in a perfect way.

Peter Ostry's icon

Peter Ostry

Jan 10, 2022, 1:24 PM

Look for [pitch~] and [fiddle~] or, if you are on a Mac, for [sigmund~].
I've never used them but what you are looking for is a technique similar to audio-to-midi and tuning devices. If you are going for an audio-to-midi technique you may not want the stage where the result gets mapped to a note grid.

One can build such a thing from scratch but it is complicated. Basically you use FFT (Fast Fourier transform) plus filters depending on the application and dynamics analysis. You set the overall frequency range you want to listen to, measure a certain time (frequency-, source- and application-dependent), find the root frequency (remove overtones and sympathetic resonances), detect the transient (depends on source and frequency) and finally average the hopefully narrow result to get a single value.

As Roman said, no technical device can reliably find the fundamental frequency. Unless you bind the analysis to some specific algorithm (like AI can do), you only measure the loudest frequency. Your chances also depend on the sound source. Examples: For a string with multiple standing waves you can find the two lowest frequencies which are one octave apart and call the lower one the fundamental. From a horn you should get nice and long sustain for relatively convenient measurement.

Note: In case you are more interested in the result than in building such a sophisticated patch, have a look at Blue Cat's FreqAnalyst Pro. This is a frequency analyser plugin that can output automation data for further processing. Center frequency, min, max, etc. Adjustable precision and speed and a graphical display of output data. I use it in Max in the vst~ object.

charles-jean oliot's icon

charles-jean oliot

Jan 13, 2022, 5:42 PM

Hello Peter, thanks for your reply. I will study it as soon as possible and I will keep you posted.
Good evening. (7 p.m. in France)

mzed's icon

mzed

Jan 14, 2022, 10:03 AM

Or fzero~

Peter Ostry's icon

Peter Ostry

Jan 14, 2022, 12:07 PM

fzero~ Ha! Seems to be working fine. This object hid well from me. Who gave it that name... :-)

mzed's icon

mzed

Jan 14, 2022, 12:37 PM

That was me. All the good names, like pitch~, were taken.

Peter Ostry's icon

Peter Ostry

Jan 14, 2022, 2:27 PM

I see. Will watch out for fone, ftwo, fthree etc.
Looks like a plan.

charles-jean oliot's icon

charles-jean oliot

Jan 16, 2022, 11:20 AM

Hello,
I already tried fzero but the result is not stable;
I will check your other suggestions.
Good day to you ;

Peter Ostry's icon

Peter Ostry

Jan 16, 2022, 12:22 PM

The result is only stable if you measure 100% stable frequencies. In the music world such frequencies may come from synthetic sources like single oscillators. All other sources deliver drifting frequencies.

For very coarse measurement you can put [ftom] after fzero~, this rounds the result to MIDI notes.

For normal measurement try [slide ...] and [round ...] after [fzero~] until you get the precision you want to see.

If fzero~ is not enough, the frequency drifts too much or you have disturbing transients or interferences. Then you have to process the signal until you can detect the frequency with the precision and smoothness you want. Finally you can use fzero~ to display the result.

This is a complex playground, there is no free lunch by just throwing in some object.

Pedro Santos's icon

Pedro Santos

Jan 16, 2022, 2:12 PM

Also see the Help File of "retune~", in the "Pitch Detection" tab.

Max Patch
Copy patch and select New From Clipboard in Max.

Wil's icon

Wil

Jan 18, 2022, 12:10 PM

I just started using pitch detection as well.
Plan to do a lot with it.

Here are some early tests using retune~, fzero~, yin~, and Sigmund~. (fiddle didn't work very well for me and I ran out of space on my laptop screen!)

The point here is to find out how they each react to the exact same process, using kSlider, and my upright electric bass.

Both retune~ and fzero~ seem to work best.

The C that I am testing is in thumb position on the bass - easier to detect. When I play lower in the bass area it gets really messy. Working on some frequency carving on the lower pitches.

Anyway, as I mentioned this is early testing. Any advice on the following would be helpful:
1. I used split and calculated the maximum C could be between B and C#. But if I want to do this for every note, that will be a lot of calculation and code for every note . There must be a better way.
2. I used modulo (thank you Andrzej Kopeć, 2015) to reduce to one octave, but as you can see the toggles are blinking when a note is played. I would like it to sustain while I am playing, then turn off when I stop playing.

Here is the patch. Only the C that is labeled controls the volume slider.

Max Patch
Copy patch and select New From Clipboard in Max.

Thanks
Wil

Source Audio's icon

Source Audio

Jan 18, 2022, 3:29 PM

A bang toggles toggle's state.
You want something else - to turn on if note played matches set pitch,
and to turn off if it does not.

To really test and compare pitch detection objects,
one has to set parameters to optimal values for what on wants to detect.

here one simple yin~ example

Max Patch
Copy patch and select New From Clipboard in Max.

Peter Ostry's icon

Peter Ostry

Jan 18, 2022, 4:22 PM

I am not a pitch detection specialist, just testet a while a couple of years ago. My knowledge is very limited and based on experience with MIDI guitar software and tuners. But in the descriptions of Charles-Jean as well as in the patch of Wil, I detect (pun intended) the same problem: Not processing the input but rather relying on some magic object and trying to suppress flickering output numbers to make the result more stable. I don't think that this method can work in a reliable way.

Please look at the patch below. It is a quick 'n' dirty example that works reasonably well with my 6-string electric bass and has an accuracy better than 1 Hz at the lowest tone (~ 30 Hz). I believe that the three stages are necessary. Basically. And dependent on the input source of course.

The time to detect the lowest tones can go up to almost half a second, this is about the same as with a Peterson Strobo Stomp HD, one of the best portable tuners available. By reducing the rampsmooth~ samples you can make it faster at the expense of stability. Of course, the patch doesn't work as good as a well-designed bass detector, but the result isn't bad for a quick one.

@Wil:
The parameters of [slide ...] are not ms but rather part of a formula you find in the reference page. Be careful, too high values can make your result less stable than it is or even lead to a wrong readout.

Wil's icon

Wil

Jan 20, 2022, 10:58 AM

@SOURCE AUDO. Thanks for the info and the patch. Routing audio using matrix will come in very handy.

@PETER OSTRY. Thanks for the source code for stabilizing lower frequencies. I finally tested it and works really well. I added a gate the cuts off the sound very close to zero amplitude. This eliminates any residual sound that I am getting when I am not playing a note.

Max Patch
Copy patch and select New From Clipboard in Max.


I made a patch that automatically finds the half way point (in Hz) between each note (one in octaves and one chromatic) and then splits the difference. This way, you can make copies of this patch, set all the C's, then set all of the C#'s etc. - or chromatically C - B and change octaves.

This works well with @PETER OSTRY patch above.

Max Patch
Copy patch and select New From Clipboard in Max.

charles-jean oliot's icon

charles-jean oliot

Jan 25, 2022, 6:36 PM

@PETER OSTRY @SOURCE AUDO @Wil @PEDRO SANTOS @MZED
Good evening, thank you for your various answers: I don't always have time to look at your resolution proposals but I try as soon as I can: in fact, I want to find out which note I play when I only play the mouthpiece (I am a trombonist);
I already note that the amplitude must be significant and the stability is not always there: I imagine that there is the attack of the note, the establishment of the sound which must "disturb" the search for the base note.

So, a tuner does this research easily?

I tried Peter's last idea, it's still not stable yet...
a very selective filter before the search might be an idea?
In any case, good evening to you (7:30 p.m. in France)

in attached file, the mouthpiece sounds for which I am looking for the note (each sound is preceded by the identical note made by a piano)

Peter Ostry's icon

Peter Ostry

Jan 25, 2022, 11:36 PM

@Charles-Jean

Yes, depending on the sound source the attack can influence the measurement a lot. Standard tuners don't care much about the attack because the musician looks at the display and interprets the readout while the display is more or less stable. But for further processing you may need filters (maybe even auto-adjusting) and time control can also be helpful to measure only the relevant part of the sound.

Regarding your mouthpiece sound demonstration: Of course, the measured value is not stable, you can easily hear that the frequency fluctuates considerably.