Here’s a little analysis plug-in for detecting the pitch notes.
In most cases the default settings should work pretty well.
The default frequency range is 100 to 2000 Hz.
For detecting very low frequencies (less than a few hundred Hz) the plug-in should be set to the low frequency range (20 to 1000 Hz).
For detecting very high frequencies (several kHz) the plug-in should be set to the high frequency range (1 kHz to 10 kHz)
By default, the plug-in detects the pitch by analysing the first 0.2 seconds of the selection. In most cases this should work well.
If required the analysed section can be set to the first part of the selection ranging from the first 10th of a second (0.1 seconds) up to one second.
Limitations:
Extremely high frequencies may not be detected very accurately, especially if the sample rate is not very high. The plug-in will often detect very high frequencies better if the sample rate is 96000 Hz rather than 44100 Hz.
This plug-in is intended to detect single notes - you may get strange results if you try to analyse chords.
The plug-in should usually be able to detect pitches of single notes to within a few percent of the actual frequency. Don’t expect the frequency in Hz to be exact. The most accurate measure of frequency in Audacity is to use “Plot Spectrum” and set the “Size” setting to a high value.
Original version: pitch-detect.ny (3.77 KB)
This plug-in is now available on the Audacity wiki
The frequency in Hz is the value of the variable “f0” which is calculated by the function “bestguess” (line 86). The function is called at line 100:
(bestguess (getyin s dur))
This returns the “note” (equivalent to a MIDI note value) or NIL if a confident guess cannot be found.
To convert a “note” value to a frequency, use the function “step-to-hz”
So to get just the frequency value you could use:
(step-to-hz (bestguess (getyin s dur)))
However if (bestguess …) returns NIL, then (step-to-hz (bestguess …)) will produce an error, so you would want to check that it is not NIL before converting to Hz.
This is done in the last section of code (from line 98).
If you just want to set a variable (for example “f0”) to the Hz value, then you can delete from line 98 to the end and replace it with something like:
(setq f0 (bestguess (getyin s dur)))
(if f0 (setq f0 (step-to-hz f0))
(setf err "Frequency not foundn"))
Before running further code, check that (length err) is 0.
Your code works great.
Thanks, you have saved me a looot of time !
How precise is the frequency - I mean - if I have a singele frequency to analyze not centered to a note ?
For example with a readout from the standard FFT analyze tool I get the peak at say 3.133Hz and the pitch detected says 3.157Hz.