A new method for derivation of phase-shifting algorithms is presented. The cost function is defined and it is minimized using descending gradient method. The family of algorithms is derived as the result. The properties of the algorithms do not change within the family. Examples of algorithms for constant phase-step as well as for randomly disturbed phase- steps are given and analyzed.