Added computing of gain function