Octave error - STFT parameters when detecting pitch in guitar audio signals
The octave error is because you are using a spectral frequency estimator (STFT), not a psychoacoustic pitch detection or estimation method.  The spectral frequency peaks in the sound are often not the pitch frequency, but instead often one of the many harmonics.  As you found, the fundamental pitch frequency can even be completely missing.  This is especially true for guitar notes, voices, and sounds from other large stringed instruments.

The solution is not to play with sample rate and STFT FFT window parameters, but to look up more reliable pitch detection and estimation algorithms.