i have a eeg data from .set file which has shape 501293000 that is 50 trials , 129 channels ,3000 samples. i want to calculate mean psd , and then mean alpha, beta , gamma psd over all the trials for a particular one or two channels .
I’m trying to use psd_welch but facing error , can someone please correct my code?
eeg_data_path = 'C/abc.set'
epochs = mne.io.read_epochs_eeglab(eeg_data_path)
# Define the EEG channel name you're interested in
channel_name = 'E70' # Change to the desired channel name
# Select the specific channel
alpha_band = (8, 13)
gamma_band = (30, 40)
# Select the specific channel
eeg_channel = raw.copy().pick_channels([channel_name])
# Calculate PSD for alpha and gamma frequency bands using Welch method
alpha_psd, alpha_freqs = mne.time_frequency.psd_array_welch(eeg_channel, fmin=alpha_band[0], fmax=alpha_band[1], sfreq=1000)
gamma_psd, gamma_freqs = mne.time_frequency.psd_array_welch(eeg_channel, fmin=gamma_band[0], fmax=gamma_band[1], sfreq=1000)
# Calculate the mean PSD values for alpha and gamma bands
mean_alpha_psd = np.mean(alpha_psd, axis=0)
mean_gamma_psd = np.mean(gamma_psd, axis=0)
i tried using it earlier also but same eror comes alpha_psd, alpha_freqs =
mne.time_frequency.psd_array_welch(eeg_channel, fmin=alpha_band[0], fmax=alpha_band[1], sfreq=epochs.info["sfreq"])
TypeError: string indices must be integers, not 'tuple'
As @richard mentioned, please use this interface to compute PSDs. The function you are using requires a NumPy array as its first argument (but you are passing a Raw or an Epochs object).
It should be psd = epochs.compute_psd(). This will give you an EpochsSpectrum object, which you can use for further calculations such as averaging over epochs and averaging specific frequencies.