I am trying to predict epilepsy using spectrograms and a convolutional neural network.
So far I have achieved a validation accuracy of 86% which i feel like is pretty good. Lots of the papers doing similar deep learning are using an very high frequency resolution in their spectrograms.
However I keep reading that when creating spectrogram one should be aware of the uncertainty principle. Is it correct that the frequency resolution is dependent on the length of the window? and how does the overlap then affects this. Assume I have a very large window but also a high overlap? Do I get high time and frequency resolution?
I have a sample plot showing two identical spectrograms but different window lengths. The sampling rate is 500 Hz and i have 2000 samples = 4 seconds of data:
#However we can create some manual configuration which increases the visibility of each frequency.
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10,5), sharey=True)
normalize_color= matplotlib.colors.Normalize(vmin=new_min + (new_min/4), vmax=new_max)
ax1.set_title("Increase in frequency resolution")
f, t, Sxx = signal.spectrogram(np.array(sz_win[0][0]), fs=500, nperseg=500, noverlap=int(500*0.99), nfft=1024, scaling='density', return_onesided=True)
pcm = ax1.pcolormesh(t, f, nanpow2db(Sxx), cmap='jet', norm=normalize_color)
ax2.set_title("Increase in time resolution")
f, t, Sxx = signal.spectrogram(np.array(sz_win[0][0]), fs=500, nperseg=int(500/7), noverlap=int((500/7)*0.99), nfft=1024, scaling='density', return_onesided=True)
pcm2 = ax2.pcolormesh(t, f, nanpow2db(Sxx), cmap='jet', norm=normalize_color)
fig.suptitle('Time vs Frequency domains')
fig.tight_layout()
plt.savefig("timevsfreg")
plt.show()