MATLAB: Optimizing zero-crossing indices

zci()zero crossing

filename='AAA'
load = xlsread(filename,1,'C:C');
extension = xlsread(filename,1,'D:D');
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
zxidx= zci(load);
figure
plot(extension, load)
hold on
plot(s(zxidx),l(zxidx),'o')
Capture.PNG
As you can see from the plot, it generally capture the targeted data well. But they are not correct.
I feel like I need to control the zero-crossing indexing function, but I am challenging how to even fine-tune it further.
Thank you.

Best Answer

I wrote ‘zci’ so I will do my best to help you with it.
It contains no error checking, so there can be a ‘wrap-around’ effect because of circshift, such that if the end of a sequence is on one side of zero and the beginning of the sequence is on the other, ‘zci’ will consider this a true zero-crossing, even though it is not. That may be what you are seeing. The solution is simply to delete the last index.
(I may consider writing a full function version of it as a File Exchange contribution that checks the ends of the sequence, and automatically deletes the end index in that event. The anonymous function version does not have that option.)