analyzeAlpha.py clarifications

Hi,
 I'm analyzing Alpha and Theta brain waves, mainly their mean values.
 I'm inspired by this @chipaudette code,
 (https://github.com/chipaudette/EEGHacker/blob/master/Data/2014-10-03 V3 Alpha/analyzeAlpha.py)
  I'm still learning signal processing, but can someone help me clarifying some parts?


1)  After the spectrogram, he does the "mean" of the PSD per bin, and then the square root.
 And calls it the ROOT-MEAN-SQUARE micro-Volts per sqrt of bin. I think I
get that because the PSD is already squared (amplitude^2 / Hz) right?

------
# find spectra that are in our time span
foo_spec = spec_PSDperBin
...
# get the mean spectra and convert from PSD to uVrms
mean_spectra_PSDperBin = np.mean(foo_spec, 1);
mean_spectra_uVrmsPerSqrtBin = np.sqrt(mean_spectra_PSDperBin)
-----


2) In order to find the mean maximum value and it's corresponding frequency
among the Alpha band, he uses the "bool_inds" variable.
 So far, so good. But I don't get this block:
 
----------------
df_Hz = freqs[2]-freqs[1]
alpha_Hz = np.array([foo_Hz[max_ind],  foo_Hz[max_ind]])
if (NFFT == int(fs_Hz)):
    units_txt = 'uVrms'
if 0:
    # refine by computing the amplitude based on the total power around the peak
    #alpha_Hz = np.array([7.5, 11])
    #bool_alpha = (freqs > alpha_Hz[0]) & (freqs < alpha_Hz[1])
    #alpha_spectrum_PSDperBin = mean_spectra_PSDperBin[bool_alpha]
    inds = np.where(bool_inds) # find the non-zero indices
    inds = inds[0]  # get rid of tuple...why, I don't know I need to do this
    inds = inds[max_ind] + np.array([-1, 0, 1]) # include one index to each side
    alpha_spectrum_PSDperBin = mean_spectra_PSDperBin[inds] # ge the values
    alpha_PSD = np.sum(alpha_spectrum_PSDperBin) # sum the power in each bin
    signal_rms = np.sqrt(alpha_PSD) # convert from power to voltage
    units_txt = "uVrms"  # clarify the units
    
    # compute power-weighted average frequency in the alpha
    weight_fac = alpha_spectrum_PSDperBin / np.sum(alpha_spectrum_PSDperBin)
    #signal_freq_Hz = np.sum(freqs[bool_alpha] * weight_fac)
    signal_freq_Hz = np.sum(freqs[inds] * weight_fac)
    alpha_Hz = freqs[[inds[0], inds[-1]]] + df_Hz*np.array([-0.5, 0.5])
-------------

Questions by order of appearance:
- uVrms or uVrms per sqrt(bin)?
- why find the non-zero indices?
- signal_rms = np.sqrt( np.sum(mean_spectra_PSDperBin[inds]) ) ??
- And why "compute power-weighted average frequency in the alpha" ?


Thanks in advance.

Comments

Sign In or Register to comment.