Improved referencing code

Added ability to reference to multiple channels
Added common average reference