Software Engineering

My part in its downfall

All the salient facts are true

JVM signal processing part 1

Objective

Simple demo code for JVM signal processing. Review the setup and configuration for Scala Breeze signal processing.

Target Audience

JVM Developers new to modern signal processing frameworks and tooling

Source Documents

Physionet
QRS complex
First-Derivative Based QRS Detection Algorithm
Shannon energy non linear Algorithm
Convolution
Convolution Filters
Scala Breeze
Java Colt Project
Scala Demo app

Summary

Use First-Derivative Based QRS Detection Algorithm implemented in Scala Breeze for detecting R-R interval of a ECG signal

Result

Scala Demo app for First-Derivative Based QRS Detection Algorithm

Discussion

JVM developers have many options for implementing signal processing algorithms with functional language constructs. Scala Breeze is a functional interface for the Java Colt Project. In the Scala Demo app there is an implementation of a First-Derivative Based QRS Detection Algorithm for ECG signals. This is a simple but effective filter of the base ECG signal that can be applied for calculating the R-R interval or peak detection. First an approximation to the derivative is found with a simple forward difference, then the shannon energy of the power signal for the derivative is filtered by convolving with a delta step function. Screenshot result.
The simple filter shown here resolves the peaks from the background ‘noise’. At the first differentiation we introduce a phase change, creating zero-crossings in the location of the R-peaks see ‘Method I: Hilbert transform with automatic threshold’First-Derivative Based QRS Detection Algorithm.
To account for this the filter can be extended with a second derivative of the correlation of the convolved shannon energy signal with a guassian filter, see Shannon energy non linear Algorithm. Then resolve the peaks as the zero crossings see ‘Method III: Second derivative of the ECG with automatic threshold’First-Derivative Based QRS Detection Algorithm.

Source code highlights

  1. an implementation of the finite difference algorithm to compute an approximation of the first derivative
    def forwardDifference[R: Ring](domian: DenseVector[R])(implicit ct: ClassTag[R]): DenseVector[R]
  2. an implementation of the ‘Shannon energy’ algorithm from the power distribution of the differentiated input signal
    def normalisedShannonEnergy(sample: DenseVector[Double], cuttOff: Double, max: Double): DenseVector[Double]
  3. Filtering the Shannon energy signal with convolution
    def powerSignalFilter(sig: DenseVector[Double], cuttOff: Double, maxPower: Double, rate: Double): DenseVector[Double]

Conclusion

Scala and Scala Breeze greatly reduce the amount of code we would need to write if we implemented this simple filter with Java.

Scala Demo app


Share

comments powered by Disqus