PyWavelets / pywt

PyWavelets - Wavelet Transforms in Python
http://pywavelets.readthedocs.org
MIT License
2.04k stars 470 forks source link

Extracting specific frequency range from Wavelet Packet #588

Open itsciccio opened 3 years ago

itsciccio commented 3 years ago

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!

li-dinmo commented 1 year ago

你好,通过这样的方法重构出的小波信号它的长度比实际ERP诱发信号的长度更短,虽然可以得到对应频率段的信号但是会存在信号失真的情况,我也遇到了某些这样的问题