# STFT output frequency does not match sin wave frequency

I have the following function and pre definition for producing a sin and its' stft:

fs=48000
nfft=2048
hop_len=nfft/2
win_len=2048
nfft = next_greater_power_of_2(win_len)

def sinus_gen(f):
np.expand_dims(np.sin(2*np.pi*f*np.arange(fs*20)/fs).astype(np.float64)...
,axis=1)


I am trying to generate and plot an 8KHz using the following stft command:

audio=sinus_gen(8000)
s=librosa.core.stft(audio[:, 0], n_fft=nfft, hop_length=hop_len,
win_length=win_len, window='hann')
librosa.display.specshow(librosa.amplitude_to_db(abs(s)),x_axis='time',y_axis='log',cmap='jet')
plt.title('Power spectogram before beamforming')
plt.colorbar(format='%+2.0f dB')
plt.clim(-60,30)
plt.tight_layout()
plt.show()


I am getting the following spectrogram image, which shows 4000KHz for some reason:

Why am I not seeing the expected 8000KHz frequency? what am I doing wrong?

You have to pass sr=fs as well as hop_length=hop_length to the specshow function, as its default values are different from yours.