getting multiple values for same frequency when calculating power spectral density

Hi,
I have 5 subjects and 4 tasks. The data is in bids format. I am using following code to read data:


task = ['AUDI','LEC2', 'MOTO', 'MVIS']
subject = ['071','073','076','077', '079']
suffix= 'ieeg'

raw = {}
for tsk in task:
    for sub in subject:
        bids_path = BIDSPath(subject=sub, task=tsk, acquisition = 'f8f24ds8sm0', suffix=suffix, root='iEEG_data_sample')
        raw[(tsk,sub)] = read_raw_bids(bids_path=bids_path, verbose=False)

I am using the following code to find PSD for each raw data object:

psds_df = {}

for  key, val in raw.items():
    psds, freqs = mne.time_frequency.psd_multitaper(val, low_bias=True)
    psds_df[key] = pd.DataFrame(psds.T, index=pd.Index(np.round(freqs, 2), name="frequencies"), columns=val.ch_names)

If I see the dataframe for (“AUDI”, “071”), I get the following dataframe:


Thanks for the help.

  • MNE version: e.g. 0.24.0
  • operating system: Windows 11

What is your question? If you don’t know what the columns represent, I assume these are the channels?

1 Like

Thanks.

Yes the columns represent channels.

My question is why I am getting so many values for 1 frequency. If I read eeg file one by one (one subject and one task), I get the PSD dataframe where each row represent data for one frequency (as expected).

Hm, I don’t know either. What are the values of freqs? What is the sampling frequency of your signals?

One guess is that it’s because calling pd.Index casts the frequency to an integer. I don’t think pandas support floats as indices.

EDIT: The pandas version I have (1.4.1) does support float indexing but perhaps yours is out of data and this might be solved by upgrading pandas.

1 Like