【发布时间】:2019-07-17 08:38:22
【问题描述】:
我正在编写一个实时检测 Alpha 波的函数。我的函数接收 256 个单通道样本值作为参数。 之后,必须找到它的 fft,然后将其分类为 alpha 、 beta 和 gamma 范围。然后我必须找到 SNR 来检查是否存在 alpha 波,即在 10 hz 频率下是否存在任何峰值。所以我需要找到 10hz 处的值幅度的平方除以 8-12hz 的 b/w 范围内所有值的平方和除以 N 值。
SNR = 10hz 时的安培值平方/(8-12hz 中静止值的平方/这些值的数量)
然后是 20 log SNR 和检查阈值。
所以基本上如何获得 10 hz 值的 Amp 平方,然后排除该值并除以其余值。
我在下面编写了启动代码,有人可以指导或帮助完成代码以完成所需的工作。 非常感谢。
def分类(标志,数据=[]):
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])
【问题讨论】:
标签: python math pycharm signal-processing