我正在编写一个实时检测阿尔法波的函数。我的函数接收256个单个通道的样本值作为参数。在那之后,它的fft必须被发现,然后分类在α,β和伽马范围。然后我要找出信噪比来检查是否存在阿尔法波,即在10赫兹频率下是否存在任何峰值。所以我需要找出10赫兹的振幅平方除以b/w范围内8-12赫兹除以N的所有数值的平方。
SNR =10 No/(8~12 No/ No. )安培值的平方.在这些价值中)
然后记录信噪比并检查阈值。
基本上,如何得到10赫兹的安培值的平方,然后排除这个值,除以其余的数值。
我已经写了启动码,下面可以有人指导或帮助完成代码,以完成所需的工作。非常感谢。
def分类(标志,data=[]):
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])发布于 2019-09-26 10:47:23
该代码已经在使用带通滤波器提取阿尔法频率。现在,要在特定频率上找到信噪比,您只需将该频率上的值平方除以其余的频率,并取20对数的除法。
https://stackoverflow.com/questions/54840842
复制相似问题