通过 SNR 检测 EEG 数据中的 Alpha 波? python
Detecting Alpha waves in EEG data through SNR? python
我正在编写一个实时检测阿尔法波的函数。我的函数接收单通道的 256 个样本值作为参数。
之后,必须找到它的 fft,然后将其分类为 alpha 、 beta 和 gamma 范围。然后我必须找到 SNR 来检查是否存在 alpha 波,即是否存在 10 赫兹频率处的峰值。所以我需要找到 10hz 值的幅度平方除以 b/w 8-12hz 范围内所有值的平方和除以 N 值。
SNR = 10hz 时放大器值的平方/(8-12hz 中静止值的平方/这些值的数量)
然后 20 记录 SNR 和检查阈值。
所以基本上如何获得 10 赫兹的值的安培平方,然后排除该值并除以其余值。
我在下面编写了启动代码,有人可以指导或帮助完成代码以完成所需的工作。
非常感谢。
定义分类(标志,数据=[]):
fs = 200 # Sampling rate (512 Hz)
# Get real amplitudes of FFT (only in postive frequencies)
fft_vals = np.absolute(np.fft.rfft(data)) #these are my fft values rfft returns only the part of the result that corresponds to nonpositive frequences. (Avoids complex conjugaes) faster and for plotting
# Get frequencies for amplitudes in Hz
fft_freq = np.fft.rfftfreq(len(data), 1.0 / fs) # that might be fixed (window length n , and sample spacing) inverse of the sampling rate returns sample freq of length n .
# Define EEG bands
eeg_bands = {'Delta': (0, 4),
'Theta': (4, 8),
'Alpha': (8, 12),
'Beta': (12, 30),
'Gamma': (30, 45)}
# Take the mean of the fft amplitude for each EEG band
eeg_band_fft = dict()
for band in eeg_bands:
freq_ix = np.where((fft_freq >= eeg_bands[band][0]) & #np.where is like asking "tell me where in this array, entries satisfy a given condition".
(fft_freq <= eeg_bands[band][1]))[0] #for fft_frreq at all point where it satisfies it returns the index (in array)
#if fftfreq[np.where bla bla] will give values array
eeg_band_fft[band] = np.mean(fft_vals[freq_ix])
此代码已在使用带通滤波器提取 alpha 频率。现在要找到特定频率的 SNR,您只需将该频率的值除以其余频率的平方和,然后取除法的 20 对数。
我正在编写一个实时检测阿尔法波的函数。我的函数接收单通道的 256 个样本值作为参数。 之后,必须找到它的 fft,然后将其分类为 alpha 、 beta 和 gamma 范围。然后我必须找到 SNR 来检查是否存在 alpha 波,即是否存在 10 赫兹频率处的峰值。所以我需要找到 10hz 值的幅度平方除以 b/w 8-12hz 范围内所有值的平方和除以 N 值。
SNR = 10hz 时放大器值的平方/(8-12hz 中静止值的平方/这些值的数量)
然后 20 记录 SNR 和检查阈值。
所以基本上如何获得 10 赫兹的值的安培平方,然后排除该值并除以其余值。
我在下面编写了启动代码,有人可以指导或帮助完成代码以完成所需的工作。 非常感谢。
定义分类(标志,数据=[]):
fs = 200 # Sampling rate (512 Hz)
# Get real amplitudes of FFT (only in postive frequencies)
fft_vals = np.absolute(np.fft.rfft(data)) #these are my fft values rfft returns only the part of the result that corresponds to nonpositive frequences. (Avoids complex conjugaes) faster and for plotting
# Get frequencies for amplitudes in Hz
fft_freq = np.fft.rfftfreq(len(data), 1.0 / fs) # that might be fixed (window length n , and sample spacing) inverse of the sampling rate returns sample freq of length n .
# Define EEG bands
eeg_bands = {'Delta': (0, 4),
'Theta': (4, 8),
'Alpha': (8, 12),
'Beta': (12, 30),
'Gamma': (30, 45)}
# Take the mean of the fft amplitude for each EEG band
eeg_band_fft = dict()
for band in eeg_bands:
freq_ix = np.where((fft_freq >= eeg_bands[band][0]) & #np.where is like asking "tell me where in this array, entries satisfy a given condition".
(fft_freq <= eeg_bands[band][1]))[0] #for fft_frreq at all point where it satisfies it returns the index (in array)
#if fftfreq[np.where bla bla] will give values array
eeg_band_fft[band] = np.mean(fft_vals[freq_ix])
此代码已在使用带通滤波器提取 alpha 频率。现在要找到特定频率的 SNR,您只需将该频率的值除以其余频率的平方和,然后取除法的 20 对数。