Approximated square wave is generated based on the mathematical principle of being equal to a sine wave at the same frequency (50Hz) and infinite sum of odd-multiple frequency sine waves with diminishing amplitude.
square wave = (4/pi)*(1V)*(sine at 50Hz) +
(4/pi)*(1/3V)*(sine at 150Hz) +
(4/pi)*(1/5V)*(sine at 250Hz) +
(4/pi)*(1/7V)*(sine at 350Hz) +
(4/pi)*(1/9V)*(sine at 450Hz) + ...