Error using findpeaks Expected Y to be a vector.

15 ビュー (過去 30 日間)
Mark Gman
Mark Gman 2020 年 4 月 21 日
コメント済み: cezayir 2024 年 1 月 13 日
%Parameters
% Read in audio file
[y,Fs] = audioread('Happy Birthday Lower.wav');
info = audioinfo('Happy Birthday Lower.wav');
sound(y,Fs) % Play the sound
% plot the data
% Create a time component using info
t = 0:seconds(1/Fs):seconds(info.Duration);
t = t(1:end-1);
figure(1)
plot(t,y)
xlabel('Time (s)')
ylabel('Audio Signal')
% Detect peaks from y
[pk_Fs, locs_Fs] = findpeaks(y,Fs, 'MinPeakDistance',0.03, 'MinPeakHeight',0.01);
I used this code to try and find the peaks of the given audio signal, the audio signal is extremly simple with no overlapping audio. But this error comes up:
Error using findpeaks
Expected Y to be a vector.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 136)
= parse_inputs(isInMATLAB,Yin,varargin{:});
Error in SeperatePeaks (line 19)
[pk_Fs, locs_Fs] = findpeaks(y,Fs, 'MinPeakDistance',0.03, 'MinPeakHeight',0.01);

回答 (2 件)

Image Analyst
Image Analyst 2020 年 4 月 21 日
y is probably stereo, so it's a 2-by-N matrix. Try extracting just one channel:
oneChannel = y(1, :); % Or y(:, 1) depending on the shape of y
[pk_Fs, locs_Fs] = findpeaks(oneChannel, Fs, 'MinPeakDistance',0.03, 'MinPeakHeight',0.01);
  2 件のコメント
Saeeid Khalili
Saeeid Khalili 2020 年 5 月 8 日
it worked thank you!
cezayir
cezayir 2024 年 1 月 13 日
thank you

サインインしてコメントする。


Star Strider
Star Strider 2020 年 4 月 21 日
The findpeaks function only operates on vectors, and ‘y’ is apparently a (Nx2) matrix.
Try this:
for k =1:size(y,2)
[pk_Fs{k}, locs_Fs{k}] = findpeaks(y(:,k),Fs, 'MinPeakDistance',0.03, 'MinPeakHeight',0.01);
end
That should work. (It generalises in the even that ‘y’ is a vector, as occasionally occurs.)
.

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by