Hi Taylor Grey,
the mistake is in the line when you call the loglog function.
loglog(Fv, 20*log10(abs(FT_af(Iv,2))*2)), xlabel('Frequency, Hz', ylabel('Amplitude, dB'));
you are using the function ylabel as an argument for xlabel, while instead you should separate those commands.
loglog(Fv, 20*log10(abs(FT_af(Iv,2))*2)); xlabel('Frequency, Hz'); ylabel('Amplitude, dB');
Given the fact that you also call xlabel and ylabel later in the script, i would suggest you to just keep the last xlabel and ylabel calls in the following way:
[audio_file, Fs] = audioread("Handgun.wav");
L = size(audio_file,1);
Ts = 1/Fs;
Fn = Fs/2;
FT_af = fft(audio_file)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:numel(Fv);
[PksL,LocsL] = findpeaks(20*log10(abs(FT_af(Iv,2))*2), 'MinPeakHeight',-90, 'MinPeakDistance',50);
[PksR,LocsR] = findpeaks(20*log10(abs(FT_af(Iv,2))*2), 'MinPeakHeight',-90, 'MinPeakDistance',50);
figure(1);
loglog(Fv, 20*log10(abs(FT_af(Iv,2))*2));
hold on
loglog(Fv(LocsR), PksR, '^r', 'MarkerFaceColor','r')
hold off
xlabel('Frequency (Hz)')
ylabel('Amplitude (dB)')
title('Handgun')
Best Answer