Zero crossing in audio signal signal processing

조회 수: 12 (최근 30일)
Darryl
Darryl 2013년 4월 13일
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
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
Darryl 2013년 4월 13일
Thanks for the help. I tried replacing y(i) = []; with y(i) = NaN, but I just end up with a row vector full of NaN's and no zeros. I've noticed that 'x' (my wav read) is in fact a column vector, so maybe that's why I'm getting the results I am.
Wayne King
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by