Zero crossing in audio signal signal processing
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(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 个评论
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!