matousc89 / padasip

Python Adaptive Signal Processing
MIT License
303 stars 51 forks source link

.run not working #14

Closed VegardIversen closed 2 years ago

VegardIversen commented 2 years ago

Hi,

I am working witch some ecg data and want to try and remove some motion artifacts from the signal using the accelerometers data. I am following this paper, which is written in matlab code. What I tried now is this

ecg = [ 5.12  5.28  5.41  5.56  5.71  5.84  6.01  6.14  6.28  6.43  6.6   6.72
  6.85  7.    7.14  7.3   7.43  7.55  7.7   7.82  7.96  8.42  8.74  8.31
  9.03 18.04 21.15 15.04 15.18 21.36 16.89  9.74  8.64 12.59 10.53 12.15
 26.53 40.02 41.19 28.55 20.38 24.8  18.96 10.35 11.43 18.26 13.43  8.16
  8.32 14.92 11.35  8.61  8.77 17.4  17.86 14.32 18.07 25.76 22.75 16.62
 16.55 23.32 18.36 10.54 10.07 16.75 12.41  9.06  9.19 15.95 13.62  9.39
 10.38 18.6  16.83 12.64 15.53 23.85 22.86 18.33 21.35 29.14 28.06 23.31
 24.62 29.94 23.98 16.58 19.56 27.18 25.26 20.2  20.86 27.13 24.88 19.51
 21.61 28.44 26.99 22.29]
a = [61.4        61.1429408  61.1560402  61.355666   61.6        61.7526485
 61.74060948 61.58011501 61.36       61.19293072 61.15967963 61.27348498
 61.48       61.68981649 61.82470523 61.8533976  61.8        61.72347136
 61.68157705 61.69961973 61.76       61.81628039 61.82203364 61.75755968
 61.64       61.51250152 61.41988386 61.3851854  61.4        61.43297464
 61.45036915 61.43613901 61.4        61.369451   61.37121731 61.41355133
 61.48       61.53830016 61.55913501 61.53373826 61.48       61.43333539
 61.42728887 61.47470248 61.56       61.64694723 61.69766599 61.69250612
 61.64       61.57165315 61.52462153 61.52179827 61.56       61.61231643
 61.64294654 61.62627121 61.56       61.46581015 61.37779666 61.32541007
 61.32       61.35153414 61.39621507 61.42994451 61.44       61.42904883
 61.41041332 61.39842472 61.4        61.41216749 61.42625596 61.4353692
 61.44       61.44810346 61.46960493 61.50887311 61.56       61.60805922
 61.6359193  61.6328438  61.6        61.54975208 61.49917066 61.46144961
 61.44       61.42831401 61.41529711 61.39266702 61.36       61.32459801
 61.29654143 61.28215882 61.28       61.28177902 61.27767054 61.26266298
 61.24       61.21947606 61.21145686 61.22012118]
Hd = pa.filters.FilterLMS(n=32, mu=0.0008)
y, e, w = Hd.run(a, ecg)

Where a is a list of the summation of the accelerometer data and ecg is a list of ecg data (added some of it if someone want to test). I keep getting a typeError when running Hd.run(a,ecg) (TypeError: object of type 'numpy.int64' has no len())

I am a bit unsure if it is the paper I have misunderstood or the use of the adaptive filter here, but if someone has any inputs that would be nice.

matousc89 commented 2 years ago

Your a object should be a 2d array, not a 1d array. Please study https://github.com/matousc89/Python-Adaptive-Signal-Processing-Handbook/blob/master/notebooks/padasip_adaptive_filters_basics.ipynb. Especially the chapter: Construction of Input Vectors (Input Matrix) from a Time Series

VegardIversen commented 2 years ago

Your a object should be a 2d array, not a 1d array. Please study https://github.com/matousc89/Python-Adaptive-Signal-Processing-Handbook/blob/master/notebooks/padasip_adaptive_filters_basics.ipynb. Especially the chapter: Construction of Input Vectors (Input Matrix) from a Time Series

But why does it need to be 2d? And when I use input_from_history I loose some of the length and then the lenght doesnt matchup anymore.

matousc89 commented 2 years ago

Of course the length does not match up. You can imagine the input construction as a rolling window - check out for example these pictures: https://www.mathworks.com/help/econ/rolling-window-estimation-of-state-space-models.html