You could try Darrel's averaging include file.

http://sites.picbasic.net/index.php?option=com_uhp2&Itemid=6&task=viewpage&user_id=70&pageid=25