Zero crossing in audio signal signal processing
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Wayne King
on 13 Apr 2013
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 Comments
Wayne King
on 13 Apr 2013
Edited: Wayne King
on 13 Apr 2013
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!