Error using findpeaks Expected Y to be a vector.
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
%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);
0 comentarios
Respuestas (2)
Image Analyst
el 21 de Abr. de 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 comentarios
Star Strider
el 21 de Abr. de 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.)
.
0 comentarios
Ver también
Categorías
Más información sobre Measurements and Spatial Audio en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!