function [pitch, octave] = findpitch(freq) %%%% Function takes in a frequency and returns the musical pitch of the frequency %%%% and its octave relative to the octave above middle C. %%%% Notes of the musical scale are assigned the following numerical values: %%%% C = 1 %%%% C# = 2 %%%% D = 3 %%%% D# = 4 %%%% E = 5 %%%% F = 6 %%%% F# = 7 %%%% G = 8 %%%% G# = 9 %%%% A = 10 %%%% A# = 11 %%%% B = 12 %%%% Octaves relative to the 12 notes of the "middle-C octave" are assigned a number %%%% corresponding to the number of octaves above or below the middle-C octave. %%%% For example a B two octaves above the B in the middle-C octave is assigned (12, 2), %%%% while a B two octaves below the middle-C octave is assigned (12, -2). octave = helpfindoctave(freq, 0); pitch = choosepitch(freq/2^octave);