Error using findpeaks Expected Y to be a vector.

16 vues (au cours des 30 derniers jours)
Mark Gman
Mark Gman le 21 Avr 2020
Commenté : cezayir le 13 Jan 2024
%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);

Réponses (2)

Image Analyst
Image Analyst le 21 Avr 2020
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 commentaires
Saeeid Khalili
Saeeid Khalili le 8 Mai 2020
it worked thank you!
cezayir
cezayir le 13 Jan 2024
thank you

Connectez-vous pour commenter.


Star Strider
Star Strider le 21 Avr 2020
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.)
.

Catégories

En savoir plus sur Measurements and Spatial Audio dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by