Added function to define gain and offset