This MATLAB script performs pitch recognition on a given audio file containing musical notes. The script identifies individual notes, extracts their frequency information, and recognizes the corresponding pitch and octave. Additionally, a helper function is included to parse the input data into distinct note windows.
- Clone the repository:
git clone https://github.com/yourusername/your-repository.git
-
Ensure you have MATLAB installed on your system.
-
Place your audio file (e.g.,
piano_A0.wav
) in the same directory as the script. -
Open the script in MATLAB.
-
Modify the script to use your audio file:
[data, Fs] = audioread('your_audio_file.wav');
Execute the script in MATLAB to perform pitch recognition on the provided audio file. The script will display the recognized pitches and octaves for each note in the console.
run your_script_name.m
-
The script begins by reading the audio file and obtaining note windows using the
notewindows
function. -
It then iterates through each note, performs Fast Fourier Transform (FFT) to extract frequency information, and filters out noisy notes.
-
The
noteparse
function is utilized to find division points between distinct notes. -
Finally, the
findpitch
function is employed to recognize the pitch and octave of each note based on its frequency.
divs = noteparse(data);
This function takes a double array data
as input and outputs a vector of division points representing the start and end of individual notes.
w = notewindows(data);
A wrapper function for noteparse
that returns the midpoint of the end and beginning points of each note window.
[pitch, octave] = findpitch(freq);
Given a frequency freq
, this function returns the musical pitch and its octave relative to the octave above middle C.
-
Ensure that your audio file is in the acceptable frequency range for accurate pitch recognition (between 20 Hz and 20,000 Hz).
-
The script may need further adjustments based on your specific use case or audio characteristics.
Feel free to explore and adapt the script for your own projects!