Reputation: 23
I'm slightly unsure how to handle this as it's a topic which is new to me so any guidance with my code would be greatly appreciated. I have a set of eeg recordings (18949 EEG records with a sampling rate of 500Hz, where the records are in nV). I'm trying to create a Frequency against Voltage graph from the data but I'm having no luck so far.
My code is as follows:
data = pd.read_csv('data.csv')
data = data['O1']
Fs = 500.0
Ts = 1.0/Fs
t = np.arange(len(data)) / Fs
n = len(data) # length of the signal
k = np.arange(n)
T = n/Fs
frq = k/T # two sides frequency range
frq = frq[range(int(n/2))]
Y = np.fft.fft(data)/n
Y = Y[range(int(n/2))]
fig, ax = plt.subplots(2, 1)
ax[0].plot(t,data)
ax[0].set_xlabel('Time')
ax[0].set_ylabel('Voltage')
ax[1].plot(frq,abs(Y),'r')
ax[1].set_xlabel('Freq (Hz)')
plt.draw()
plt.show()
fig.savefig("graph.png")
And my resulting graph looks like:
Could anyone provide some guidance as to where I may be going wrong with this?
Upvotes: 2
Views: 1861
Reputation: 14577
Your signal has a fairly large (at least relative to the other signal variations) DC offset in the time-domain. In the frequency-domain this would be plotted as a strong line at 0Hz (which is hidden by the plot's axis), then the amplitude of the other frequency components are relatively speaking close to 0.
For better visualization you should plot the frequency spectrum in Decibels (dB) using the formula 20*log10(abs(Y))
, so you could actually see those other frequency components.
Upvotes: 1