Refer this link for calculation of Energy and Power of signal: http://www.mathworks.com/matlabcentral/fileexchange/11202-automatic-gain-control