# The extraction of five frequency waves of EEG is correct or not alpha, beta, gamma, theta, delta?

**URL:** <https://mne.discourse.group/t/the-extraction-of-five-frequency-waves-of-eeg-is-correct-or-not-alpha-beta-gamma-theta-delta/8469>\
**Category:** Support & Discussions\
**Tags:** eeg\
**Created:** [March 12, 2024, 10:05am UTC](https://mne.discourse.group/t/the-extraction-of-five-frequency-waves-of-eeg-is-correct-or-not-alpha-beta-gamma-theta-delta/8469 "2024-03-12T10:05:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhivya\_Bharkavi](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/dhivya_bharkavi/32/3037_2.png) [@Dhivya\_Bharkavi](https://mne.discourse.group/u/Dhivya_Bharkavi)\
**Post date:** [March 12, 2024, 10:05am UTC](https://mne.discourse.group/t/the-extraction-of-five-frequency-waves-of-eeg-is-correct-or-not-alpha-beta-gamma-theta-delta/8469/1 "2024-03-12T10:05:17Z")

</div>

I used one channel EEG devices has powerspec.csv file

Time 0 0.25 0.5 0.75 1 1.25 1.5 1.75 2 … 61.5 61.8 62 62.3 62.5 62.8 63 63.3 63.5 63.8  
0 22:50:34 26.40 140.0 52.40 27.30 61.00 12.5 29.1 34.3 6.14 … 3.780000e-13 3.770000e-13 3.540000e-13 3.080000e-13 3.130000e-13 2.970000e-13 2.840000e-13 2.760000e-13 2.700000e-13 2.670000e-13  
2481 rows × 257 columns

\*Is the below code was python code power spectral feature extraction is correct or not?

import numpy as np  
import pandas as pd

# Load your preprocessed data

data = pd.read\_csv(‘/content/drive/MyDrive/EEG Dataset/SSN\_fwdvideoreadings/181112225542.powerspec.csv’)

# Reshape the data to (samples, time\_steps, channels)

data\_values = data.drop(columns=[‘Time’]).values  
data\_reshaped = np.reshape(data\_values, (len(data), 256, -1))

# Sampling frequency

fs = 256

# Get real amplitudes of FFT (only in positive frequencies)

fft\_vals = np.absolute(np.fft.fft(data\_reshaped, axis=1))

# Get frequencies for amplitudes in Hz

fft\_freq = np.fft.fftfreq(data\_reshaped.shape[1], 1.0 / fs)

# Define EEG bands

eeg\_bands = {‘Delta’: (0.5, 4),  
‘Theta’: (4.1, 8),  
‘Alpha’: (8.1, 12),  
‘Beta’: (12.1, 30),  
‘Gamma’: (30.1, 120)}

# Initialize dictionaries to store aggregated wave data

aggregated\_data = {band: for band in eeg\_bands.keys()}  
time\_dict = {}

# Take the mean of the FFT amplitude for each EEG band across all time steps

for i in range(len(data)):  
timestamp = data[‘Time’][i]  
if timestamp not in time\_dict:  
time\_dict[timestamp] = len(time\_dict)  
time\_idx = time\_dict[timestamp]  
for band, (low, high) in eeg\_bands.items():  
freq\_ix = np.where((fft\_freq \>= low) & (fft\_freq \<= high))[0]  
aggregated\_data[band].append(np.mean(fft\_vals[i, freq\_ix]))

# Create DataFrame

result\_df = pd.DataFrame(aggregated\_data)

# Add the Time column back to the DataFrame

result\_df[‘Time’] = data[‘Time’]

# Group by Time and take the mean

result\_df = result\_df.groupby(‘Time’).mean().reset\_index()

# Reorder columns

result\_df = result\_df[[‘Time’, ‘Alpha’, ‘Beta’, ‘Delta’, ‘Theta’, ‘Gamma’]]

# Save the DataFrame to a CSV file

#result\_df.to\_csv(‘extracted\_waveforms\_reduced.csv’, index=False)  
result\_df

The results also  
Time Alpha Beta Delta Theta Gamma  
0 22:50:34 307.858865 328.737738 926.303834 491.416773 211.999118  
1 22:50:35 349.872691 367.122390 720.928035 462.434233 198.847660  
2 22:50:36 650.277401 571.233902 1052.908029 790.054977 250.895087  
3 22:50:37 2071.023165 1641.168546 2757.112038 2440.801969 613.760081  
4 22:50:38 6812.422723 4970.802084 8072.064257 7597.704078 1043.839759  
… … … … … … …  
304 22:55:38 135.733638 178.732464 566.884751 245.447899 89.462139  
305 22:55:39 157.473915 150.729884 439.677633 200.039832 80.212311  
306 22:55:40 410.353346 298.445394 810.049615 466.847896 170.234903  
307 22:55:41 909.313430 693.503189 1345.535591 1029.820925 265.058099  
308 22:55:42 1264.562631 865.893222 1618.648096 1325.605290 288.059167

309 rows × 6 columns  
` Is this code correct or not feature extraction`

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [March 12, 2024, 10:18am UTC](https://mne.discourse.group/t/the-extraction-of-five-frequency-waves-of-eeg-is-correct-or-not-alpha-beta-gamma-theta-delta/8469/2 "2024-03-12T10:18:43Z")

</div>

Please format your code so that others can read it (see [How to correctly format your question - #3](https://mne.discourse.group/t/how-to-correctly-format-your-question/7883/3)).
