PIA-Group / BioSPPy

Biosignal Processing in Python
Other
573 stars 274 forks source link

EDA library detects peak positions imprecisely #45

Closed Tomatenbiss closed 3 years ago

Tomatenbiss commented 5 years ago

I am facing the issue that the eda.eda method returns incorrect positions of the peaks. I already analyzed where the problem is and summarized my findings in the following pdf. I might be wrong so I would be glad to hear your opinion on this.

SCR_Library_PeakPositions.pdf

capcarr commented 5 years ago

Hi @Tomatenbiss Sorry for taking so long to answer the issues you raised.

If you read the article on which the algorithm is based (available here), I think the implementation is correct. The authors define an SCR occurrence as the segment between two consecutive zero-crossings, from negative to positive and positive to negative, and define the SCR amplitude as the maximum value between the two zero-crossings. This also relates to issue #46.

However, I do think that the nomenclature can be misleading, mixing the signal with the SCR from the derivative. We could maybe change the names or descriptions of the outputs.

Do you agree with this interpretation?

Tomatenbiss commented 5 years ago

Dear @capcarr,

I have read the article and I fully agree with the conclusions you draw from it. But I am also convinced that the code does not represent our interpretation of the algorithm.

An SCR occurs between the Zero crossings for the derivative: Correctly implemented

SCR Amplitude = max. value between Zero Crossings: This is were the issue is. The code takes the maximum value of the derivative(!) in line 232, not the maximum value of the original signal. Taking the highest value of the derivative yields the inflection point of a curve. The second zero crossing yields the position of the curve's peak and should be considered in the code.

I agree that this is related to issue #46 , as this is also caused by checking the amplitude on the derivative instead of checking the original signal.

Please let me know your opinion on this :)

Kind regards Tom

matu3ba commented 5 years ago
  1. @Tomatenbiss @capcarr I can reproduce the problem as well. For me shifting the interval to the right helps and the problem only does occur, if I start the interval on such nearby saddle point.
  2. For too noisy data the algorithm fails as expected by the paper.
  3. For moving artefacts the same behavior occurs.

I guess the tool is nice, but such behavior is not documented / it would be nice to know that artefacts are not automatically filtered etc.

afonsocraposo commented 3 years ago

Fixed with commit a324641b76ec6e5194c35b247a6d075fa6974940.