Skip to main content

Pitch Detector

An external musical note detector.

info

Author: Ana-Alexia Alecu
GitHub Project Link: https://github.com/UPB-FILS-MA/project-aleqbee

Description

This Raspberry Pi Pico project is designed to showcase the estimated frequency and corresponding musical note produced by an electronic keyboard or piano app. In this setup, I use the digital output of the Ky-038 microphone sound sensor module, transmitting it to one of the Raspberry Pi Pico's input pins. The process involves applying auto-correlation, weight calculations and tuning algorithms to identify the fundamental frequency using the initial three periods. This determined fundamental frequency is then compared against frequencies in octaves 3, 4 and 5 to detect the nearest pitch frequency. Finally, the identified musical note corresponding to the closest frequency is displayed on the LCD screen.

Motivation

I saw this project as an opportunity to combine my two passions: music and technology. As a logical person, who finds Maths to be one of her favourite subjects, I knew that this kind of technical pursuit would allow me to use mathematics and physics. I quite enjoy signals and data processing, so alongside music, which is one of my hobbies, it seemed like it would make a perfect project for me. What is more, I have always been amazed by the vocal range finder applications, how they so accurately perceive and display the exact note you are singing, in a very fast manner and I would say this has been my main inspiration, which came to light when I was scrolling through the list of projects done in the previous years.

Architecture

The architecture components are the following:

  • Raspberry Pi Pico WH: The Raspberry Pi Pico acts as the main microcontroller board for the project. It runs the Rust program that interfaces with the peripherals and handles the pitch detection algorithm.
  • Microphone Sound Sensor: The microphone sound sensor captures audio input (sound) from the environment, in my case, from the speakers.
  • Speakers: The speakers output audio signals, such as generated piano notes corresponding to the detected pitch, from a piano app.
  • Piano app: It is an application used for playing some musical notes from given octave ranges to be registered by the speakers.
  • LCD: Connected to the Raspberry Pi Pico via I2C, the LCD1602 provides an interface for displaying the musical note detected, as well as the corresponding frquency.

Schematic

Log

Week 6 - 12 May

I started implementing the ideas of the project, starting with the hardware. The actual hardware build took me one day. I got started on writing the software as well, by testing different microphone modules and deciding which type of signal output should I use: the analog or digital output (AO or DO) and setting up the LCD. I had spent a lot of time searching for signal processing crates that could make my life easier, but none were no_std, so I let go of the idea and stuck to implementing lots of mathematics.

Week 7 - 19 May

This week was the hardest, as I was battling choosing the most facile and efficient algorithm for signal processing and beetween Fast Fourier Transform and Autocorellation, I had chosen the latter. Why? Because it allowed me to remove the DC component (the baseline noise) of a signal and retreive its periodicty, which made my computations easier in order to detect the fundamental frequency of the signal.

Week 20 - 26 May

During the previous week I had encountered many errors, most of which were related to data type miscorrelations, and this week I tackled these issues. Here, Rust was not merciful on me, but with patience I had managed to surpass these problems. Additionally, most intensive testing was done during this last week before the PM Fair Presentation, as I was trying to make the pitch detection as accurate as possible, but in the end it did not turn out quite as expected. This is due to the the fact that audio signals can have harmonic components (multiples of the fundamental frequency) and these harmonics can introduce secondary peaks in the autocorrelation function, leading to ambiguity in identifying the correct fundamental frequency. However, when I played the note C via a piano app on my phone, for example, the pitch detector displayed the note D, which is right next to C. So, even though it is not very accurate, it is pretty close.

Hardware

The Raspberry Pi Pico microcontroller is perfect for this Pitch Detection project, as it requires a lot of computational power due to the signal processing. The Ky-038 microphone sound sensor module is used for capturing the sounds, emitted by a Piano App, through some PC Speakers. Although the hardware part of this project is not complex, as this technological endeavour does not rely on the hardware part, but rather on the software one, I believe it is still a challenging programming project that will help me develop my technical skills needed for my carrer.

The whole setup Pic3

The LCD 1602 I2C Module Pic1

The Ky-038 Sound Sensor Module Pic2

Schematics

KiCAD Schematic1 KiCAD Schematic2

Bill of Materials

DeviceUsagePrice
Raspberry Pi Pico WHThe microcontroller - used for its processing power57 RON
1602 LCD with I2C InterfaceUsed for displaying the musical notes or pitches17 RON
Ky-038 Microphone Sound SensorUsed for capturing the sound6 RON
Kit Plusivo MicrocontrollerThe breadboard, jumper wires and male to female wires)75 RON
MB102 Breadboard Power Supply Module 3.3V/5VThe power supply5 RON
PC SpeakersUsed for emitting a powerful sound[-]

Software

LibraryDescriptionUsage
embassy-rsRust framework for embedded programmingUsed for programming the behavior of the Raspberry Pi Pico and for streamlining specific concepts within embedded programming
embassy-executorAsynchronous executor for Rust embedded systemsUsed for task scheduling and asynchronous programming
embassy-timeTime management libraryUsed for time-based operations such as delays
embassy-rpPeripheral access libraryUsed for initializing and interacting with peripherals
ag-lcdRust port of the LiquidCrystal libraryUsed for writing to the lcd1602
  1. My Weekend Project: Musical Note Detector Using An Arduino
  2. Voice Detection with Raspberry Pi Pico W
  3. PM Projects 2023
  4. Vocal Range Finder Tool ...