Code covered by the BSD License  

Highlights from
Guitar Tuner

from Guitar Tuner by Jeff Vipperman
Plays tones through the computer sound card to to tune a 6-string guitar.

guitar.m
%
% Guitar tuner code...
%
% Plays 4 seconds of E,A,D,G,B,E 
% 
% -jsv
%

clear

Fs = 20000; % sampling rate
tau = 4;    % tone duration
t=linspace(0, 4, Fs*4+1); % Create time vector

%%% Assign the six string frequencies, based upon A-220 (Hz)
wA3 = 220 * 2 * pi;     % circular frequency of 220 Hz A...
wE3 = wA3 / 2^(5/12); % E is a fourth below A220
wD3 = wA3 * 2^(5/12); % D is a fourth above A220
wG4 = wD3 * 2^(5/12); % G is a fourth above D
wB4 = wG4 * 2^(4/12); % B is a third above G
wE5 = wB4 * 2^(5/12); % E is a fourth above B

%%% Create sine waves for each freq.

xE3  = sin( t * wE3 );   % is a fourth (4/12) below A
xA3  = sin( t * wA3 );   % circular frequency of 220 Hz A...
xD3  = sin( t * wD3 );   % is a fourth (4/12) above A 
xG4  = sin( t * wG4 );   % is another fourth above A
xB4  = sin( t * wB4 );   % is a third above G
xE5  = sin( t * wE5 );   % is a fourth above B

%%% Tried to use while loop and wait for keystroke to end each note, 
%%% but wouldn't work to keep sending a shorter sine vector to the sound card...

wavplay( xE3, Fs )
wavplay( xA3, Fs )
wavplay( xD3, Fs )
wavplay( xG4, Fs )
wavplay( xB4, Fs )
wavplay( xE5, Fs )

%chord = sin(t*wA3) + sin(t*wA3*2^(4/12)) + sin(t*wA3*2^(7/12)) + sin(t*wA3*2);
%wavplay(chord,Fs)

Contact us at files@mathworks.com