fix a bug in calculating gain factor.
fix script not to accept too large sampling frequency.