Hi!
- MNE version: 1.7.0
- operating system: Windows 10
I am trying to analyze the data from the EEG, namely, to determine which brainwave prevails in each epoch. I use FFT for this.
raw = mne.io.read_raw_edf('0000_1_002603844.edf', preload=True)
#Network filtering
raw.notch_filter(freqs=50, notch_widths=1)
# Low-frequency data filtering
raw.filter(l_freq=0.5, h_freq=None)
raw.set_eeg_reference(ref_channels='average', projection=True)
events = mne.make_fixed_length_events(raw, duration=1.0)
epochs = mne.Epochs(raw, events, tmin=0, tmax=1, baseline=None, preload=True)
Here I add all the received maximum wave powers to the list, which I then output:
for i in range(len(epochs)):
epoch_data = epochs[i].get_data(copy=True)[0]
# FFT
fft_values = np.fft.fft(epoch_data)
freqs = np.fft.fftfreq(epoch_data.shape[-1], d=1 / raw.info['sfreq'])
psd = np.abs(fft_values) ** 2
waves = {'delta': (0.5, 4),
'theta': (4, 8),
'alpha': (8, 12),
'beta': (12, 30),
'gamma': (30, 50)}
max_power_band = None
max_power = 0
for band, (low, high) in waves.items():
band_ix = (freqs >= low) & (freqs < high)
power = np.mean(psd[:, band_ix], axis=1)
if np.any(power > max_power):
max_power = power
max_power_band = band
And it works, but the problem is that there are too many gamma waves! And I think there’s some kind of filtering problem, but I can’t figure out what’s the matter.
Look at this:
[‘delta’, ‘theta’, ‘beta’, ‘gamma’, ‘delta’, ‘gamma’, ‘gamma’, ‘delta’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘delta’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘gamma’, ‘delta’]
My raw.info:
<RawEDF | 0000_1_002603844.edf, 129 x 15360 (30.0 s), ~15.2 MB, data loaded>
<Info | 9 non-empty values
bads: []
ch_names: AF3h, AF4h, AF5h, AF6h, AF7, AF8, AFF1h, AFF2h, AFF3h, AFF4h, ...
chs: 129 EEG
custom_ref_applied: False
highpass: 0.5 Hz
lowpass: 256.0 Hz
meas_date: 2024-04-27 11:30:24 UTC
nchan: 129
projs: Average EEG reference: off
sfreq: 512.0 Hz
subject_info: 3 items (dict)
>