Skip to content

Spike Detection and Filtering

Sambit Paul edited this page Jul 5, 2020 · 8 revisions

In the context of Peak Detection, a peak or local maximum is defined as any sample whose two direct neighbours have a smaller amplitude and a trough or local minimum is defined as any sample whose two direct neighbours have a larger amplitude. Peak detection is often used for identifying certain events which cause undulations in the signal which are recognised as peaks.

In this library, we are able to identify spikes and filter them based on these properties:

  • Left Height of Spike: The height of the peak from the neighbouring trough on the left.
  • Right Height of Spike: The height of the peak from the neighbouring trough on the right.
  • Mean Height of Spike: The height of the peak computed as the mean of the 2 neighbouring trough on the left and right.
  • Min Height of Spike: The height of the peak computed as the minimum of the 2 neighbouring trough on the left and right.
  • Max Height of Spike: The prominence of a peak computed as the maximum of the 2 neighbouring trough on the left and right.

This diagram provides a explanation regarding the properties mentioned above. signal

The examples provided here use this signal:
double[] data = UtilMethods.splitByIndex(UtilMethods.electrocardiogram(), 3200, 4200);
Smooth sObj = new Smooth(data, 15, "rectangular");
double[] ecgSignal = sObj.smoothSignal("same");

signal

Spike Detection

The first step of peak detection is to identify all the peaks in the signal. Filtering can only be done on the identified peaks.

Code
FindPeak fp = new FindPeak(this.highResSignal);
Spike out = fp.get_spikes();

double[] outLeftSpike = out.getLeftSpike();
double[] outRightSpike = out.getRightSpike();
double[] outMeanSpike = out.getMeanSpike();
double[] outMaxSpike = out.getMaxSpike();
double[] outMinSpike = out.getMinSpike();
Output:
outLeftSpike: [Double.NaN, 0.107, 0.598, 0.007, 0.236, 0.08 , 0.629, 0.016, 0.215,
                0.056, 0.651, 0.323, 0.004, 0.074, 0.003, 0.558, 0.012, 0.021,
                0.311, 0.09 , 0.006, 0.004, 0.604, 0.005, 0.007, 0.36 , 0.086,
                0.846, 0.003, 0.001, 0.007]
outRightSpike: [0.278, 0.299, 0.66 , 0.003, 0.165, 0.289, 0.691, 0.062, 0.263,
                0.323, 0.703, 0.007, 0.189, 0.001, 0.243, 0.558, 0.007, 0.004,
                0.154, 0.003, 0.162, 0.029, 0.713, 0.004, 0.006, 0.2  , 0.22 ,
                0.826, 0.011, 0.005, 0.002]
outMeanSpike: [0.278, 0.203 , 0.629 , 0.005 , 0.2005, 0.1845, 0.66  , 0.039 ,
                0.239 , 0.1895, 0.677 , 0.165 , 0.0965, 0.0375, 0.123 , 0.558 ,
                0.0095, 0.0125, 0.2325, 0.0465, 0.084 , 0.0165, 0.6585, 0.0045,
                0.0065, 0.28  , 0.153 , 0.836 , 0.007 , 0.003 , 0.0045]
outMaxSpike: [0.278, 0.299, 0.66 , 0.007, 0.236, 0.289, 0.691, 0.062, 0.263,
                0.323, 0.703, 0.323, 0.189, 0.074, 0.243, 0.558, 0.012, 0.021,
                0.311, 0.09 , 0.162, 0.029, 0.713, 0.005, 0.007, 0.36 , 0.22 ,
                0.846, 0.011, 0.005, 0.007]
outMinSpike: [0.278, 0.107, 0.598, 0.003, 0.165, 0.08 , 0.629, 0.016, 0.215,
                0.056, 0.651, 0.007, 0.004, 0.001, 0.003, 0.558, 0.007, 0.004,
                0.154, 0.003, 0.006, 0.004, 0.604, 0.004, 0.006, 0.2  , 0.086,
                0.826, 0.003, 0.001, 0.002]

spikes
Clone this wiki locally