# How to Extract frequency bands from Short-time Fourier Transform?

I am reproducing the results reported by the author in a research paper. In which he takes the STFT of EEG signals. The input data has a shape of (1 X500) and I used Scipy library built-in function to calculate STFT and the output has shape (257 x32) I need to extract the data between two frequency bands (6-13 Hz) and (17-30 Hz). The author reports the extracted bands to be of the size of (16 X 32) and (23 X 32) but in none of the setting, I am getting this frequency resolution. I tried contacting the author but no response so far. I hope some of you could direct me in the right direction. Thank you very much.

wlen=64
nfft=1024
temp=S1_769_test[3,0,:]
win=signal.get_window(window='blackman',Nx=wlen, fftbins=True)

f, t, Zxx = signal.stft(temp,fs=500,window=win,noverlap=50,nfft=nfft,nperseg=wlen,

dat=np.abs(Zxx)/250

if  (nfft % 2):  # odd nfft excludes Nyquist point
dat[2:,:] = dat[2:,:]*2

else:            # even nfft includes Nyquist point
dat[2:-1,:]= dat[2:-1,:]*2

band1=np.where((f >= 6) & (f <=13))
band2=np.where((f >= 17) & (f <=30))

extracted1=np.squeeze(dat[band1,:])
extracted2=np.squeeze(dat[band2,:])

extracted2 = cv2.resize(extracted2, dsize=(32,15), interpolation=cv2.INTER_CUBIC)
Combined=np.vstack([extracted1,extracted2])
print (len(band2))
print (len(band1))

• did the author specify they are using an STFT? It wouldn't be the thing I'd use – simply filter for the bands you need. – Marcus Müller Mar 9 at 0:15
• yes, the author has specified it that they are using stft to preserve the temporal and spectral information. – Ali Raza Mar 9 at 9:07
• did they specify their temporal resolution? I have serious doubts about their methodology. an STFT gives you equidistant sampling of a (windowed) signal's power spectral density – and that's really not what they use it for. Your code illustrates this nicely: you use an unsuitable algorithm to extract the bands, and then have to recombine and interpolate. Also, are you sure about the 500 Hz sampling rate? That's ... solid overkill for a signal only reaching up to 30 Hz. – Marcus Müller Mar 9 at 12:08
• Thanks Marcus for the comment. Yes they did as you can see the window size is 64 and step size is 14 so on 500 points it will produce (257 x 32). They did not mention the sampling frequency but my data is sampled at 250Hz I just experimented with different nfft and sampling frequency. Only 100 Hz Sampling frequency did provide a bit better results. But my real problem is still there. Doesnt matter which sampling frequency and nfft I use I never get exact band sizes as the author has reported. The best I got so far is 27 x32 for 17-30 Hz and 14 x32 for 6-13 Hz. – Ali Raza Mar 9 at 13:05
• Why are you using fs=500 if your sampling rate is fs=250? Do you understand what the STFT does, and what the function you're calling does? – Marcus Müller Mar 9 at 13:12