0001 function [note_name] = note_labels(freq)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 name_list = ['a '
0012 'ash'
0013 'b '
0014 'c '
0015 'csh'
0016 'd '
0017 'dsh'
0018 'e '
0019 'f '
0020 'fsh'
0021 'g '
0022 'gsh'];
0023
0024
0025
0026 the_notes = 27.5*2 .^ ((0:108)/12);
0027
0028 diffs = abs(the_notes-freq);
0029 note_index = find(fix(diffs*1000)/1000 <= 1E-3);
0030
0031 if isempty(note_index)
0032 sprintf('Could not match frequency (%3.3f) to note name\n', freq)
0033 note_name = '';
0034 return
0035 end
0036
0037 octave_offset = fix((note_index-1)/12)+1;
0038 range_str = int2str(octave_offset);
0039
0040 note_offset = rem((note_index-1),12)+1;
0041
0042 note_name = [deblank(name_list(note_offset,:)) range_str];
0043
0044 return
0045