问题
I want to get delta, theta, alpha, beta and gamma waves from a set of signals. And this is how, till now I am doing it:-
fs = 256
data=copy.deepcopy(features[:100])
data=np.reshape(data,(len(data),256,64))
# Get real amplitudes of FFT (only in postive frequencies)
fft_vals=[]
for d in data:
fft_vals.append(np.absolute(np.fft.fft2(d)))
fft_vals = np.array(fft_vals)
print(fft_vals.shape)
# Get frequencies for amplitudes in Hz
fft_freq = np.fft.fftfreq(len(data), 1.0/fs)
print(fft_freq.shape) #(100)
# Define EEG bands
eeg_bands = {'Delta': (0, 4),
'Theta': (4, 8),
'Alpha': (8, 12),
'Beta': (12, 30),
'Gamma': (30, 45)}
delta=[]
theta=[]
alpha=[]
beta=[]
gamma=[]
delta_labels=[]
theta_labels=[]
alpha_labels=[]
beta_labels=[]
gamma_labels=[]
delta_real=[]
theta_real=[]
alpha_real=[]
beta_real=[]
gamma_real=[]
# 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]) &
(fft_freq <= eeg_bands[band][1]))[0]
print(freq_ix.shape) #prints first value of shape of each wave
if band=='Delta':
delta_real=data[freq_ix]
delta_labels=labels[freq_ix]
delta=fft_vals[freq_ix]
elif band=='Theta':
theta_real=data[freq_ix]
theta_labels=labels[freq_ix]
theta=fft_vals[freq_ix]
elif band=='Alpha':
alpha_real=data[freq_ix]
alpha_labels=labels[freq_ix]
alpha=fft_vals[freq_ix]
elif band=='Beta':
beta_real=data[freq_ix]
beta_labels=labels[freq_ix]
beta=fft_vals[freq_ix]
elif band=='Gamma':
gamma_real=data[freq_ix]
gamma_labels=labels[freq_ix]
gamma=fft_vals[freq_ix]
eeg_band_fft[band] = np.mean(fft_vals[freq_ix])
print(delta.shape)
print(theta.shape)
print(alpha.shape)
print(beta.shape)
print(gamma.shape)
But I am getting this as output as the output of all waves' shape:-
(2,256,64)
(2,256,64)
(1,256,64)
(7,256,64)
(6,256,64)
SO why am I getting just 18 values where as my data has 100 values? I have seen butter worth for getting all 5 waves but it isn't also working as expected so I am sure I am not understanding it right, can anyone please tell me how can I get 5 waves when a dataset of signals is passed? Any help will be much appreciated.
The range of my initial data is between -19 to +30 almost. And after applying fft2 it goes from 0-30K etc. I am really confused how can I get those 5 waves from my data.
来源:https://stackoverflow.com/questions/52837997/extract-delta-theta-alpha-beta-and-gamma-waves-from-signals