Mercurial > hg > aimmat
view aim-mat/tools/fre2note.m @ 0:74dedb26614d
Initial checkin of AIM-MAT version 1.5 (6.4.2011).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 12:32:31 +0100 |
parents | |
children | 20ada0af3d7d |
line wrap: on
line source
% support file for 'aim-mat' % % This external file is included as part of the 'aim-mat' distribution package % http://www.pdn.cam.ac.uk/cnbh/aim2006 % $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $ % $Revision: 585 $ function [str,oct,nr_note]=fre2note(fre) % translates the fre to the nearest real note in a-g if fre==0 str='no'; oct=0; nr_note=-1; return end note_names=['A ';'A#';'B ';'C ';'C#';'D ';'D#';'E ';'F ';'F#';'G ';'G#']; lowest_note=27.5; % Hz =A1 440 Hz= a4 for i=1:length(fre) if fre(i)>0 cent(i)=fre2cent(lowest_note,fre(i)); % how many octaves? nr_octs(i)=round(cent(i)/1200)-1; oct(i)=nr_octs(i)+1; % how many tones? cento(i)=mod(cent(i),1200)/100; nr_note(i)=round(cento(i)+1); if nr_note(i)>12 nr_note(i)=1; end % nr_note(find(nr_note>12))=1; else nr_note(i)=0; end end % compansate for that the octave changes at C for i=1:length(fre) if nr_note(i) > 3 && nr_note(i) < 7 nr_octs(i)=nr_octs(i)+1; end end for i=1:length(fre) if nr_note(i)==0 str{i}=['00']; elseif strcmp(note_names(nr_note(i),2),' ') if nr_octs(i)<0 str{i}=[note_names(nr_note(i)) '0']; else str{i}=[note_names(nr_note(i)) num2str(nr_octs(i))+1]; end else if nr_octs(i)<0 str{i}=[note_names(nr_note(i),1:2) '0']; else str{i}=[note_names(nr_note(i),1:2) num2str(nr_octs(i))+1]; end end end