0% found this document useful (0 votes)
304 views

Gtcode

1. The document contains code for a guitar tuner program that allows a user to select a guitar string and record an input signal to compare its frequency to the correct frequency for the selected string. 2. The program performs an FFT on the input signal to identify its dominant frequency, then compares this frequency to the correct frequency and indicates whether the string needs to be increased, decreased, or is perfectly tuned. 3. It also calculates the percentage error from the correct frequency and provides feedback to the user to make adjustments and re-record the signal until the string is perfectly tuned.

Uploaded by

akki_9800
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
304 views

Gtcode

1. The document contains code for a guitar tuner program that allows a user to select a guitar string and record an input signal to compare its frequency to the correct frequency for the selected string. 2. The program performs an FFT on the input signal to identify its dominant frequency, then compares this frequency to the correct frequency and indicates whether the string needs to be increased, decreased, or is perfectly tuned. 3. It also calculates the percentage error from the correct frequency and provides feedback to the user to make adjustments and re-record the signal until the string is perfectly tuned.

Uploaded by

akki_9800
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

clear all;

clc;
x=1;
while x==1,
x=isempty (input ('Press enter to start program or press zero to quit.
'));
ghighE=1318.1505;
gB=987.7669;
gG=658.9911;
gD=587.3297;
gA=440;
glowE=329.6277;
guitar=[ghighE,gB,gG,gD,gA,glowE];
if x==1,
p=input ('Which string are you adjusting? 1=e 2=B 3=G 4=D 5=A 6=E');
w=guitar (p)
yw=isempty (input ('Press enter to record input signal or 0 to start
over. '));
while yw==1,
% record input signal
%
load chirp;
load gong;
%
[y Fs] = wavread(filename);
%Fs=44100;
T=0:1:Fs/2-1;

%y1 = y; Fs1 = Fs;


%wavplay(y1,Fs1,'sync') % The chirp signal finishes before the
I=y;
% to compare frequencies of a stored save file
% let's hear the input signal
display ('This is how the input signal sounds. ');
sound (I,Fs);
% fft of input signal
J=fft (I)/size(I,1);
K=0:1:Fs/2-1;
%
%
%
%
%
%
%
%
%
%

if p==6
for i=400:size(J,1)
J(i,1)=0;
end
else
for i=1500:size(J,1)
J(i,1)=0;
end
end
%Plotting
if p==6
axis([ 200 500 -0.01 0.01])
for i=400:size(J,1)
J(i,1)=0;
end
elseif p==5

axis([ 400 550 -0.01 0.01])


for i=550:size(J,1)
J(i,1)=0;
end
elseif p==4
axis([ 450 700 -0.01 0.01])
for i=700:size(J,1)
J(i,1)=0;
end
elseif p==3
axis([ 650 850 -0.01 0.01])
for i=900:size(J,1)
J(i,1)=0;
end
elseif p==2
axis([ 800 1100 -0.01 0.01])
for i=1200:size(J,1)
J(i,1)=0;
end
elseif p==1
axis([ 1200 1400 -0.01 0.01])
for i=1500:size(J,1)
J(i,1)=0;
end
end
subplot(2,1,1);plot(I);
subplot(2,1,2);plot(2*real(J(1:Fs/2)));
xlabel('Frequency(Hz)'),ylabel('Amplitude(V)');
title('input signal');
K=0:1:(Fs/2-1);
(1.0015*w)
K (find (J==max (J)))
(0.9985*w)
z=((K (find (J==max (J)))-w)/w)*100;
if (1.0015*w)>K (find (J==max (J)))&& (0.9985*w)<K (find (J==max
(J))),
display ('Perfect Intonation!!!');
%
display (['The frequency of the input signal is, ',num2str
( (find (J==max (J)))) 'Hz.']);
fprintf ('Percent Error % d %% \n',z)
elseif w>K (find (J==max (J))),
display ('Input frequency should be increased');
%
disp (['The frequency of the input signal is, ',num2str (
(find (J==max (J)))) 'Hz.']);
fprintf ('Percent Error % d %% \n',z)
elseif w<K (find (J==max (J))),
display ('Input frequency should be decreased');
%
disp (['The frequency of the input signal is, ',num2str (
(find (J==max (J)))) 'Hz.']);
fprintf ('Percent Error % d %% \n',z)
end
yw=isempty (input ('Make needed adjustments and press enter to
record a new input signal or 0 to start over. '));

if yw==1,
continue;
else x=1;
end
end
end
end

You might also like