Zero crossing in audio signal signal processing
이전 댓글 표시
I am trying to work out the zero crossing on a short audio sample of some random tom toms. I've written this script in order to capture the zero crossings:
% Zero Crossing Script
x = wavread('toms.wav');
plot(x)
hold on
for i = 1:length(x)
if(x == 0)
y(i) = x;
plot(y(i), 'ro')
else
y(i) = [];
end
end
After running the script, I seem to be getting an error:
Index of element to remove exceeds matrix dimensions.
Error in zeroCrossing (line 16)
y(i) = [];
I was hoping the line that gives the error would create an empty cell when the value was other than zero. This way I could overlay exactly where the zero's occur.
Thanks in advance.
답변 (1개)
Wayne King
2013년 4월 13일
I don't think this is the way to do zero crossing, but at any rate, you can use NaN in the above to do the plotting you are trying to do. And you don't need a for loop. Look at this example.
x = randi([-3 3],50,1);
y = NaN(size(x));
y(x==0) = 0;
plot(x,'b'); hold on;
plot(y,'ro','markerfacecolor',[1 0 0])
댓글 수: 2
Darryl
2013년 4월 13일
Wayne King
2013년 4월 13일
편집: Wayne King
2013년 4월 13일
I think the problem may be that testing for actual equality to 0 is not going to work with floating point numbers. That's why I suggested that was not the way to implement a zero-crossing detector.
카테고리
도움말 센터 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!