% project1_example.m
% Example for Engin 100 Project 1 transcriber
% Use this only if you find it helpful
clear
load victors_tone.mat % get signal x from the Lab 2 file for this example.
xx = reshape(x, 3000, 26); % reshape into a 3000 by 26 array.
n = 1500; % pick some n
disp(x(n)) % make sure signal is not zero at that n!
ratio = (xx(n-1,:) + xx(n+1,:)) ./ xx(n,:) / 2;
% Apply the formula from Lab 2 to each column of xx:
F = acos(ratio)*8192/2/pi; % finish applying formula.
midi = round(12*log2(F/440)) + 69; % Convert Hertz to MIDI
index = midi - 63; % index into following vertical position array
% Now make table for translating (shifted) MIDI into musical staff notation:
V = [0 .5 .75 1 1.25 1.5 1.75 2 2.5 2.75 3 3.2 3.5 4 4.25 4.5];
% [E F F# G G# A A# B C C# D D# E F F# G]
% stem-plot using V(index), which maps midi values to staff heights.
subplot(311), stem(V(index),'filled'), axis([0 26 0 4])
% Make stem plot look more like musical staff notation:
set(gca, 'YGrid', 'on', 'XTick', [0 26], 'YTick', [0:4])
% Now adapt this to the output of your synthesizer.
% Need to handle different number of notes, and accidentals.