Get the spectal signal-to-noise ratio for each spatial filter. Spectral ratio measure for best n_components selection See :footcite:`NikulinEtAl2011`, Eq. (24). Returns ------- spec_ratio : array, shape (n_channels) Array with the sprectal ratio value for each component
(ssd_sources, sfreq, n_fft, freqs_signal, freqs_noise)
| 52 | |
| 53 | |
| 54 | def _get_spectral_ratio(ssd_sources, sfreq, n_fft, freqs_signal, freqs_noise): |
| 55 | """Get the spectal signal-to-noise ratio for each spatial filter. |
| 56 | |
| 57 | Spectral ratio measure for best n_components selection |
| 58 | See :footcite:`NikulinEtAl2011`, Eq. (24). |
| 59 | |
| 60 | Returns |
| 61 | ------- |
| 62 | spec_ratio : array, shape (n_channels) |
| 63 | Array with the sprectal ratio value for each component. |
| 64 | sorter_spec : array, shape (n_channels) |
| 65 | Array of indices for sorting spec_ratio. |
| 66 | |
| 67 | References |
| 68 | ---------- |
| 69 | .. footbibliography:: |
| 70 | """ |
| 71 | psd, freqs = psd_array_welch(ssd_sources, sfreq=sfreq, n_fft=n_fft) |
| 72 | sig_idx = _time_mask(freqs, *freqs_signal) |
| 73 | noise_idx = _time_mask(freqs, *freqs_noise) |
| 74 | if psd.ndim == 3: |
| 75 | mean_sig = psd[:, :, sig_idx].mean(axis=2).mean(axis=0) |
| 76 | mean_noise = psd[:, :, noise_idx].mean(axis=2).mean(axis=0) |
| 77 | spec_ratio = mean_sig / mean_noise |
| 78 | else: |
| 79 | mean_sig = psd[:, sig_idx].mean(axis=1) |
| 80 | mean_noise = psd[:, noise_idx].mean(axis=1) |
| 81 | spec_ratio = mean_sig / mean_noise |
| 82 | sorter_spec = spec_ratio.argsort()[::-1] |
| 83 | return spec_ratio, sorter_spec |
| 84 | |
| 85 | |
| 86 | def _ssd_mod( |