1 year ago
#384987
Karlo
How to obtain a clear spectrograph of an oversampled sinusoid with increasing frequency?
Consider following example:
import numpy as np
import scipy as scp
import matplotlib.pyplot as plt
#make signal
deltat = 1e-4
t = np.linspace(0,300000,300001) * deltat
y = np.exp(-t/10)*np.sin(np.pi * (t/4)**2)
#plot signal
plt.figure(1)
plt.clf()
plt.plot(t, y)
plt.show()
#calculate spectrogram
f, t, Sxx = scp.signal.spectrogram(y, 1/deltat)
#plot spectrogram
plt.figure(2)
plt.clf()
plt.pcolormesh(t, f, Sxx)
plt.ylim([0, 100])
plt.show()
A sine with increasing frequency and decreasing amplitude is created and its spectrogram is plotted. Note that the sine is oversampled (it represents a measurement at fixed time step deltat
).
The spectrogram should be an increasing line (increasing frequency) of decreasing color (decreasing amplitude). How can I obtain the correct spectrogram?
- Trying to include the
nperseg
andnoverlap
keywords in thespectrogram
function does only give me other wrong spectrograms. - Should I use an alternative Python function instead of
spectrogram
? Update: I have also tried usinglibrosa.stft
without success. - Is the problem related to the oversampling?
python
scipy
spectrogram
frequency-analysis
0 Answers
Your Answer