No peaks found when using findpeaks

clc;
clear all;
% Read the tone and listen to it once
[tones, Fs] = audioread('pin_9.wav');
Error using audioread>readaudio (line 167)
The filename specified was not found in the MATLAB path.

Error in audioread (line 160)
[y, Fs] = readaudio (filename, range, datatype);
audid = audiodevinfo(0, Fs, 16, 1);
%if audid ~= -1
%p = audioplayer(tones, Fs, 16, audid);
% play(p);
%end
% Visualize the spectrum
N = numel(tones);
t = (0:N-1) / Fs;
% Iterate over each frequency bin and find peaks
for i = 1:size(tones, 2)
tone = tones(:, i);
% get the estimate of peak in time interval 1sec to 2sec of tone
tones_1 = tones(t>1 & t<2);
n_1 = length(tones_1);
t_1 = (0:n_1-1)/Fs;
p = abs(fft(tones_1));
f = (0:n_1-1)*(Fs/n_1);
figure
title(['FFT spectrum for tone ', num2str(i)]);
% Check if the input vector is non-empty before calling findpeaks
if ~isempty(p)
[pks, locs] = findpeaks(p);
peak = f(locs);
else
disp('No peaks found.');
peak = NaN;
end
plot(f, p);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
axis tight;
end
The result for this code is that it couldnt find any peaks. What do i do with this?

댓글 수: 5

Dyuman Joshi
Dyuman Joshi 2024년 4월 2일
Please attach the audio file so we can run your code.
Also, have you tried plotting that signal and see if there are any peaks in it?
Mathieu NOE
Mathieu NOE 2024년 4월 2일
hello
seems the file you're trying to open does not exist in the current path
look at your error message again :
Error using audioread>readaudio (line 167)
The filename specified was not found in the MATLAB path.
Dyuman Joshi
Dyuman Joshi 2024년 4월 2일
@Mathieu NOE, That's because I edited the problem description and ran that code in MATLAB Answers Live Editor.
Mathieu NOE
Mathieu NOE 2024년 4월 2일
yes , of course !
we need the OP to share his wav file
Mathieu NOE
Mathieu NOE 2024년 4월 3일
hello @ALIA
problem solved or you still need some help ?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

질문:

2024년 4월 2일

댓글:

2024년 4월 3일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by