Error using findpeaks Expected Y to be a vector.
조회 수: 17 (최근 30일)
이전 댓글 표시
%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
답변 (2개)
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
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.)
.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!