sincmaths

A Kotlin multi-platform implementation of 2D matrix with signal processing capabilities

https://github.com/gallvp/sincmaths

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.1%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

A Kotlin multi-platform implementation of 2D matrix with signal processing capabilities

Basic Info
Statistics
  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • Open Issues: 3
  • Releases: 2
Created almost 5 years ago · Last pushed about 2 years ago
Metadata Files
Readme Changelog License Citation

README.md

SincMaths

DOI

SincMaths is a Kotlin Multiplatform library which provides a 2D matrix SincMatrix to facilitate translation of signal processing code written in Octave/MATLAB to mobile applications. Originally written for the Gait&Balance app. See docs for a comprehensive list of functions. Key implementation aspects:

  • Stores data in row-major format as opposed to column-major format used by Octave/MATLAB
  • Uses ejml-simple for Android side optimisations
  • Uses Apple Accelerate for iOS side optimisations
  • Uses rafat/wavelib to provide wavelet-based demonising
  • Uses codeplea/tinyexpr to provide Octave/MATLAB style indexing

Examples

Initialisation

```kotlin val matrixA = matrixFrom("[1, 2, 3; 4, 5, 6]") val matrixB = matrixFrom("[1, 2, 3, 4]") val matrixC = matrixFrom("[5;6;7;8;9;10]") val matrixD = matrixFrom("1:10") val matrixE = matrixFrom("-1.5:-1:-7.9")

val matrixF = matrixOf(2, 10, 1..20) val matrixG = colVectorOf(1.0, 0.5, 2.9, 10.1, 15.4) ```

Indexing

```kotlin val matrixM: SincMatrix = (1..110).asSincMatrix(11, 10)

val matrixA = matrixM["1:5,4:7"] val matrixB = matrixM["1:end,end:-1:end-1"]

val matrixC = matrixM[3, 3] val matrixD = matrixM[1]

val matrixE = matrixM[1..4]

val matrixF = matrixM.get { endR, endC, allR, allC -> Pair(allR, 4..7) } // same as matrixM[":,4:7"] ```

Implementation of acf from MATLAB Central

Reference: https://au.mathworks.com/matlabcentral/fileexchange/30540-autocorrelation-function-acf

```kotlin fun SincMatrix.acf(numLags: Int): SincMatrix {

require(this.isVector) { "This function works only for vectors" }
require(numLags < this.numel) {
    "No. of lags should be smaller than the length of the vector"
}

val zeroMeanVector = this - this.mean().scalar
val convSum = zeroMeanVector.conv(bVector = zeroMeanVector.flip())
val scale = 1.0 / zeroMeanVector.dot(zeroMeanVector).scalar
val scaledConvSum = convSum * scale
val acfElements = this.numel + 1..this.numel + numLags
return if (this.isRow) {
    scaledConvSum[this.rowIndicesRange, acfElements]
} else {
    scaledConvSum[acfElements, this.colIndicesRange]
}

} ```

Usage

Kotlin Project: MavenCentral

Note: This library does not work with iosSimulatorArm64 target. Android tests have to be performed on an emulator or a connected device, otherwise, the underlying JAVA JNI libraries fail to load.

Add dependency:

kotlin implementation("io.github.gallvp:sincmathsmp:0.3")

Try a test:

kotlin expect(5050.0) { matrixFrom("1:100").sum().scalar }

Swift Project: CocoaPods

Note: Global functions such as matrixFrom are converted into open class functions as SincMatrixInitKt.matrixFrom. Use 'Jump to Definition' on 'SincMaths' to locate the class and function definitions.

Clone this project and add it to your project's Podfile:

pod pod 'SincMaths', :path => '/path/to/cloned/sincmaths/sincmathsmp'

Import it in your project and try a test:

```swift import SincMaths

XCTAssertEqual( SincMatrixInitKt.matrixFrom(script: "1:100").sum(dim: 1).scalar, 5050.0 ) ```

Owner

  • Name: Usman Rashid
  • Login: GallVp
  • Kind: user
  • Location: Auckland

Bioinformatics Developer at The New Zealand Institute for Plant and Food Research.

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Rashid"
  given-names: "Usman"
  orcid: "https://orcid.org/0000-0002-1109-5493"
title: "SincMaths: A Kotlin multi-platform implementation of 2D matrix with signal processing capabilities"
version: 0.3
date-released: 2023-12-30
url: "https://github.com/GallVp/sincmaths"
doi: 10.5281/zenodo.10457067

GitHub Events

Total
Last Year

Dependencies

.github/workflows/pull-request-task.yml actions
  • actions/checkout v4 composite
sincmathsmp/SincMaths.podspec cocoapods
build.gradle.kts maven
sincmathsmp/build.gradle.kts maven