I have the following code:
JavaScript
x
7
1
sampling_rate=128
2
N = sampling_rate
3
_f, t, Sxx = signal.spectrogram(_signal, sampling_rate, nperseg=N, nfft=N, noverlap=N-1, mode="complex")
4
cm = plt.pcolormesh(t, _f, np.log(np.abs(Sxx)), cmap="viridis")
5
plt.savefig('Spectogram.png', dpi=300, frameon='false')
6
7
which is giving me the following plot:
What is the correct way to define the correct parameters, namely: nperseg, nfft and noverlap to obtain a correct and smooth plot?
Thank you!
Advertisement
Answer
I was able to solve this issue by normalising the input signal and doing:
JavaScript
1
6
1
t, f, Sxx = signal.spectrogram(filt_signal[sampleIDX], fs=128,
2
nperseg=200, noverlap=180, return_onesided=True)
3
Sxx = np.log(Sxx)
4
Sxx = (Sxx - np.min(Sxx)) / (np.max(Sxx) - np.min(Sxx))
5
image_Sxx = Image.fromarray(np.uint8(cm.viridis(Sxx)*255))
6