Amplitude-Frequency plots

Hi everyone, below is a toy data

import numpy as np
import mne
from   copy       import deepcopy as dpcpy

np.random.seed(10)

data = np.random.rand(24,1024)
data1 = np.random.rand(24,251)

data_ = np.concatenate((data, data1),axis=1)

ch_names = ["Fp1", "Fp2", "F3", "F4", "C3", "C4", "P3", "P4", "O1", "O2", "F7", "F8", "T7", "T8", "P7", "P8", "Fz", "Cz", "Pz", "M1", "M2", "AFz", "CPz", "POz"]

montage = mne.channels.make_standard_montage('standard_1020')
info = mne.create_info(ch_names=ch_names, sfreq=1000, ch_types='eeg').set_montage(montage, match_case=False)

raw = mne.io.RawArray(data_,info, copy='data', verbose=False)
raw.set_eeg_reference(projection=True)

EEG_bands    = {'delta':(1, 4),
                'theta':(4, 8),
                'alpha':(8, 13),
                'beta':(13, 32),
                'gamma':(32, 125)}

for bandName in list(EEG_bands.keys())[1:6]:
    eeg_data = raw.copy().filter(l_freq=EEG_bands[bandName][0],h_freq=EEG_bands[bandName][1], verbose=False)

    # FFT Amplitude-Frequency Plots
    psd, freqs = mne.time_frequency.psd_array_welch(eeg_data._data,eeg_data.info["sfreq"],n_fft=256,n_per_seg=None, average='mean')
    spectrum   = mne.time_frequency.SpectrumArray(data=psd,freqs=freqs, info=eeg_data.info)

    fig_spec = spectrum.plot(spatial_colors=False, amplitude=True)

The outputs:



  1. My question is in the output plots isn’t the curve suppose to drift towards zeros after their frequency range? why does do that after several frequency values?

  2. Is it possible for the gamma band to have negative psd? and why?

  3. Is there another method in mne I could use to get the amplitude frequency plot?

Thanks. Answers and corrections are welcome

1 Like

The y-axis shows amplitude in dB, which is a normalized unit and computed as 20 log10(A/A0) (we use A0 = 1 as a baseline). This is why you can get negative values (log10 of a number less than 1 is negative). You can change the units on the y-axis by setting dB=False.

Because no real-world filter is ideal, the amplitude (power) is not exactly zero, but just (much) smaller than originally (depending on the filter properties).

3 Likes

That worked fine!. Thanks alot

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.