The invention relates to a respiratory gas analyzer for analyzing a respiratory gas, which is configured to determine at least one sleep stage from the respiratory gas and to determine a sleep quality based on the sleep stage. Furthermore, the invention relates to a respirator which comprises such a respiratory gas analyzer, to a device for carrying out a polygraph and/or polysomnograph, which comprises such a respiratory gas analyzer, and to a method for controlling a respirator which comprises such a respiratory gas analyzer.