Home > utils > note_labels.m

note_labels

PURPOSE ^

function [note_name] = note_labels(freq);

SYNOPSIS ^

function [note_name] = note_labels(freq)

DESCRIPTION ^

 function [note_name] = note_labels(freq);
 Returns note name given a frequency
 The frequency variable is matched against a list of frequencies
 that is generated by taking a basis frequency of 110 Hz (a1) and
 computing all higher notes using the formula 110 * 2^(note_number/12)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [note_name] = note_labels(freq)
0002 % function [note_name] = note_labels(freq);
0003 % Returns note name given a frequency
0004 % The frequency variable is matched against a list of frequencies
0005 % that is generated by taking a basis frequency of 110 Hz (a1) and
0006 % computing all higher notes using the formula 110 * 2^(note_number/12)
0007 
0008 % Written 08/08/96 by Petr Janata
0009 % 04/09/05 PJ A1=55 Hz -- American notenames
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 % Create the index of notes
0025 
0026 the_notes = 27.5*2 .^ ((0:108)/12);  % Generate 8 octaves of notes
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

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003