jags802
Newbie level 1
guitar tuner matlab
Hi all im currently trying to design a guitar tuner in MATLAB and am new to this. Currently I record my string using the following code then bandpass filter it and then FFT it. I get the right result but I now need how to detect my peak so that I can look if it is on tune or not as my code just loops and records agian if the detection is high enough. I need some kind of break or if statement to go on and look at the peak. Any one any ideas please. Im only concentrating on the A string to start.
Many thanks in advance
Gareth
My code is as follows
s=1;
max_s=0;
while s==1
while max_s < .3 % if maximum sound recorded is higher than 0.3 then process
E= wavrecord(2000,10000); %record sound for 2 seconds
y=filter(AFILTER,E);
max_s = max(E); % works out maximum value in the recording
endmax_s=0; %reset max sound
nt=1024; %look
T=.1024; % nt times 1/sampling rate
dt=T/nt;
df=1/T;
fmax=(nt/2)*df;
f=0:dfnt/2-1)*df;
ef=fft(y(300:300+nt-1));
yp=zeros(1,(nt/2));
yp(1:nt/2)=(2/nt)*ef(1:nt/2);
subplot(2,1,1);
plot; grid on
subplot(2,1,2);
plot(f,abs(yp))
axis([0 fmax 0 max(abs(yp))])
xlabel('freq Hz')
grid
pause(0.5)
end
Hi all im currently trying to design a guitar tuner in MATLAB and am new to this. Currently I record my string using the following code then bandpass filter it and then FFT it. I get the right result but I now need how to detect my peak so that I can look if it is on tune or not as my code just loops and records agian if the detection is high enough. I need some kind of break or if statement to go on and look at the peak. Any one any ideas please. Im only concentrating on the A string to start.
Many thanks in advance
Gareth
My code is as follows
s=1;
max_s=0;
while s==1
while max_s < .3 % if maximum sound recorded is higher than 0.3 then process
E= wavrecord(2000,10000); %record sound for 2 seconds
y=filter(AFILTER,E);
max_s = max(E); % works out maximum value in the recording
endmax_s=0; %reset max sound
nt=1024; %look
T=.1024; % nt times 1/sampling rate
dt=T/nt;
df=1/T;
fmax=(nt/2)*df;
f=0:dfnt/2-1)*df;
ef=fft(y(300:300+nt-1));
yp=zeros(1,(nt/2));
yp(1:nt/2)=(2/nt)*ef(1:nt/2);
subplot(2,1,1);
plot; grid on
subplot(2,1,2);
plot(f,abs(yp))
axis([0 fmax 0 max(abs(yp))])
xlabel('freq Hz')
grid
pause(0.5)
end