MATLAB: How to maintain sync in conv()

convmoving average

I'm filtering a signal with a moving-average filter implemented by conv(). But there is some kind of sync error in the conv(), how it works I didn't quite understand. But I heard there is something with an overlap.
This is the code I use so far:
function E=calc_energy(X,winlen)
b=ones(1,winlen)/winlen;
E=conv(b,X);
So I have to do something with the parameters of conv() but since I don't understand how conv() overlaps I'm stuck.
Thankful for any help!

Best Answer

Maybe this is what you want?
E=conv(b,X,'valid');
or this
E=conv(b,X,'same');