You're only averaging 99 values. Your loop should go up to j<100, not j<99. Also, dividing by 100 is rounding down. You should add 50 first to implement rounding:
AVGvalue = (AVGvalue+50)/100;
--
The Flexible MIDI Shield: MIDI IN/OUT, stacking headers, your choice of I/O pins