from Digital Guitar Tuner by Farhat Masood
This program plays the fundamental guitar strings sounds so that one could tune the respective guita

note(keynum, dur)
function tone = note(keynum, dur)
%tone = note(keynum, dur)
%
%note  Produces sinusoidal signal corresponding to a 
%      piano key.
%
%usage:
%      tone = output signal
%      keynum = the piano key number of the desired note
%               (C_4, "middle C" = #40)
%      dur = time duration of the signal
%  (1st, 2nd and 3rd octave harmonics added for extra 
%   brightness of tone).
fs=11025; % Sample rate
tt=[0:1/fs:dur];
freq = 440*2^( (keynum-49)/12); % calulating frequency.
tone = sumcos([freq 2*freq 3*freq 4*freq 5*freq],[1 .5 .5 -.3 .2],fs,dur);

% This block provides linear attenuation to the signal at the beginning of 
% the signal and at the end to minimize the discontinuity noise.
step_size=0.03; 
% The step_size variable controls the ramp up rate of the attenuation:
%    "1" is for no attuation. 
%    "0.03" is near optimal.  
%    "0.005" clearly audible ramping.
a=[ 0 : step_size : (1-step_size) ];
att=[a ones(1, length(tone)-2*length(a)) fliplr(a)];
tone=att.*tone;

if (keynum==0)
   tone = zeros(1,length(tone));
end   
%----------- END note.m -------------

Contact us at files@mathworks.com