I am utilizing this project to extract features from an EEG signal. That being said, I require the signal from a specific frequency which is 12-32 (beta band). My signal is 128Hz.
By using pywt.WaveletPacket, I am able to decompose the signal into 4 distinct levels with the 'db4' wavelet. However, by the nature of how such a signal is decomposed, my required frequency range is split into 12-16Hz (in level = 4) and 16-32Hz (in level = 2).
My question is: How do I combine these wavelet packet into a single list of coefficients?
This was my attempt:
1) extract the required frequencies, but we need to combine beta 1 and beta 2
wp = pywt.WaveletPacket(data=signal, wavelet='db4', mode='symmetric', maxlevel=4)theta = wp['aaad'].dataalpha = wp['aada'].databeta1 = wp['aadd'].databeta2 = wp['ad'].datagamma = wp['da'].data
2) create a new empty signal, and set all levels to lists of 0
new_wp = pywt.WaveletPacket(data=signal, wavelet='db4', mode='symmetric', maxlevel=4)for i in range(1,5):print(i)for node in new_wp.get_level(i, 'freq'):new_wp[str(node.path)].data = np.zeros_like(new_wp[str(node.path)].data)
3) set corresponding levels to the required values of beta1 and beta2
new_wp['aadd'].data = beta1new_wp['ad'].data = beta2
4) reconstruct the new signal, that only contains frequencies from 12-32Hz
new_wp.reconstruct(update=True)print(new_wp.data)
Although this code works, I am not sure if it is working as required (I have minimal knowledge in the field of signal processing)
Hi!
I am utilizing this project to extract features from an EEG signal. That being said, I require the signal from a specific frequency which is 12-32 (beta band). My signal is 128Hz.
By using
pywt.WaveletPacket
, I am able to decompose the signal into 4 distinct levels with the 'db4' wavelet. However, by the nature of how such a signal is decomposed, my required frequency range is split into 12-16Hz (in level = 4) and 16-32Hz (in level = 2).My question is: How do I combine these wavelet packet into a single list of coefficients?
This was my attempt:
1) extract the required frequencies, but we need to combine beta 1 and beta 2
wp = pywt.WaveletPacket(data=signal, wavelet='db4', mode='symmetric', maxlevel=4)
theta = wp['aaad'].data
alpha = wp['aada'].data
beta1 = wp['aadd'].data
beta2 = wp['ad'].data
gamma = wp['da'].data
2) create a new empty signal, and set all levels to lists of 0
new_wp = pywt.WaveletPacket(data=signal, wavelet='db4', mode='symmetric', maxlevel=4)
for i in range(1,5):
print(i)
for node in new_wp.get_level(i, 'freq'):
new_wp[str(node.path)].data = np.zeros_like(new_wp[str(node.path)].data)
3) set corresponding levels to the required values of beta1 and beta2
new_wp['aadd'].data = beta1
new_wp['ad'].data = beta2
4) reconstruct the new signal, that only contains frequencies from 12-32Hz
new_wp.reconstruct(update=True)
print(new_wp.data)
Although this code works, I am not sure if it is working as required (I have minimal knowledge in the field of signal processing)
Thanks in advance!