spkit.wpa_coeff_win

spkit.wpa_coeff_win(x, winsize=128, overlap=None, wv='db3', mode='symmetric', maxlevel=None, verticle_stacked=True, pad=False, verbose=0)

Wavelet Packet Decomposition - window-wise

Wavelet Packet Decomposition - for each window and stacked together

Parameters:
x: 1d signal array
wvwavelet type, default = ‘db3’
winsize: int, default=128
  • window size, samples at the end will be discarded, if len(x)%overlap is not eqaul to 0, to avoid, pad the signal

overlap: int, default=None,
  • if None, overlap= winsize//2

  • shift of window

mode: {‘symmetric’, ..}, default=’symmetric’
maxlevel: int, or None, default=None
  • maximum levels of decomposition will result in 2**maxlevel packets

verticle_stacked: bool, default=True
  • if True, coefficients are vertically stacked - good for temporal alignment

pad: bool, default=False,
  • if True, signal will be padded with last value to make len(x)%overlap==0

verbose: bool, deault=False
  • Verbosity mode

Returns:
WK_seq: 2D array, (N,K),
  • N = 2**maxlevel, number of packets

  • K, number of coefficients in each packet

Notes

wpa_coeff_win improves the time resolution of the WPA, compared to wpa_coeff for long sequence

References

Examples

#sp.wpa_coeff_win
import numpy as np
import matplotlib.pyplot as plt
import spkit as sp
x,fs,lead_names = sp.data.ecg_sample_12leads(sample=2)
x = x[:int(fs*5),5]
x = sp.filterDC_sGolay(x, window_length=fs//3+1)
t = np.arange(len(x))/fs
WK = sp.wpa_coeff_win(x,wv='db3',winsize=512,overlap=256,mode='symmetric',maxlevel=3, verticle_stacked=True,pad=False)
plt.figure(figsize=(10,5))
plt.subplot(211)
plt.plot(t,x)
plt.xlim([t[0],t[-1]])
plt.xlabel('time (s)')
plt.ylabel('ECG Signal')
plt.grid()
plt.subplot(212)
plt.imshow(np.log(np.abs(WK)+0.01),aspect='auto',cmap='jet',)
plt.ylabel('Wavelet Packets')
plt.xlabel('time (n)')
plt.tight_layout()
plt.show()
../../_images/spkit-wpa_coeff_win-1.png