<commit_before># What is pitch detection?

>A pitch detection algorithm (PDA) is an algorithm designed to estimate the pitch or fundamental frequency of a quasiperiodic or oscillating signal, usually a digital recording of speech or a musical note or tone. This can be done in the time domain, the frequency domain, or both.

- https://en.wikipedia.org/wiki/Pitch_detection_algorithm

In short, I have a recording of a guitar note, and I want to recognize what the pitch is - what the note being played is.

Musical notes map to frequency in Hz. Integer multiples of a frequency are known as octaves - e.g., E is 20.6, 41.2, 82.4 (open low E on guitar), 164.8, 329.6 (open high E on guitar), ...

# The McLeod Pitch Method

The McLeod Pitch Method is a method for pitch detection for musical instruments and voices. Naive autocorrelation may be tripped up by overtones:

>Most oscillators, from a guitar string to a flute, will naturally vibrate at a series of distinct frequencies known as normal modes. The lowest normal mode frequency is known as the fundamental frequency, while the higher frequencies are called overtones. Often, when an oscillator is excited — for example, by plucking a guitar string — it will oscillate at several of its modal frequencies at the same time. So when a note is played, this gives the sensation of hearing other frequencies (overtones) above the lowest frequency (the fundamental).
- https://en.wikipedia.org/wiki/Overtone


The paper describing the McLeod Pitch Method is: _A Smarter Way to Find Pitch_ by <NAME> and <NAME>.

I'll display examples of using naive autocorrelation on an 83Hz sine wave, and an 82.4Hz open low E string on a guitar in standard EADGBE tuning, and introduce the various improvements from the McLeod Pitch Method to show how it's better at detecting the pitch of the guitar string.

The code in this repository implements various formulae presented in the paper, piecemeal. The plots presented here are all generated with `cargo test -- --nocapture` to print the samples to stdout and plotted using gnuplot.

# 2 - Autocorrelation<commit_msg>fun link to dsp.stackexchange.com<commit_after># What is pitch detection?

>A pitch detection algorithm (PDA) is an algorithm designed to estimate the pitch or fundamental frequency of a quasiperiodic or oscillating signal, usually a digital recording of speech or a musical note or tone. This can be done in the time domain, the frequency domain, or both.

- https://en.wikipedia.org/wiki/Pitch_detection_algorithm

In short, I have a recording of a guitar note, and I want to recognize what the pitch is - what the note being played is.

Musical notes map to frequency in Hz. Integer multiples of a frequency are known as octaves - e.g., E is 20.6, 41.2, 82.4 (open low E on guitar), 164.8, 329.6 (open high E on guitar), ...

Surprise tidbit: https://dsp.stackexchange.com/questions/19379/improving-an-auto-correlation-based-guitar-pitch-detector

# The McLeod Pitch Method

The McLeod Pitch Method is a method for pitch detection for musical instruments and voices. Naive autocorrelation may be tripped up by overtones:

>Most oscillators, from a guitar string to a flute, will naturally vibrate at a series of distinct frequencies known as normal modes. The lowest normal mode frequency is known as the fundamental frequency, while the higher frequencies are called overtones. Often, when an oscillator is excited — for example, by plucking a guitar string — it will oscillate at several of its modal frequencies at the same time. So when a note is played, this gives the sensation of hearing other frequencies (overtones) above the lowest frequency (the fundamental).
- https://en.wikipedia.org/wiki/Overtone


The paper describing the McLeod Pitch Method is: _A Smarter Way to Find Pitch_ by <NAME> and <NAME>.

I'll display examples of using naive autocorrelation on an 83Hz sine wave, and an 82.4Hz open low E string on a guitar in standard EADGBE tuning, and introduce the various improvements from the McLeod Pitch Method to show how it's better at detecting the pitch of the guitar string.

The code in this repository implements various formulae presented in the paper, piecemeal. The plots presented here are all generated with `cargo test -- --nocapture` to print the samples to stdout and plotted using gnuplot.

# 2 - Autocorrelation
{'fraction_non_alphanumeric': 0.04910509407985315, 'fraction_numerical': 0.011702615878843506, 'mean_word_length': 4.3288508557457215, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '620755', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1095, 'n_words': 669}