Skip to content

wunderwald/rsa_sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RSA and Synchrony Algorithm Collection

by Moritz Wunderwald, 2025-2026

A library to calculate RSA and to estimate physiological synchrony through different metrics all at once - for adult and infant data.

Installation

Simply use pip to install the latest build. See /dist for available builds.

pip install sync_path/dist/sync-<LATEST_VERSION>-py3-none-any.whl

RSA calculation

Respiratory sinus arrythmia (RSA) can be calculated from a sequence of inter-beat interval (IBI) values. It can be represented as a single magnitude value, as a series of epoch-based magnitude values or as a time-series calculated using windowed approaches.

  1. Single RSA Magnitude Value: This method calculates a single RSA value for the entire sequence of IBI values. It provides an overall measure of RSA for the given data.

    from sync import rsa_magnitude
    
    ibi_values_ms = [...]
    rsa_mag = rsa_magnitude(ibi_ms=ibi_values_ms, rsa_method='porges_bohrer_nk2')
    print(f"RSA Magnitude: {rsa_mag}")
  2. Epoch-Based Magnitude Values: This method divides the IBI sequence into epochs (time intervals) and calculates an RSA value for each epoch. It provides a series of RSA values representing different time intervals.

    from sync import rsa_per_epoch
    
    ibi_values_ms = [...]
    rsa_epochs = rsa_per_epoch(ibi_ms=ibi_values_ms, rsa_method='hf-hrv', epoch_length_ms=30000)
    print(f"Epoch-based RSA magnitude values: {rsa_epochs}")
  3. RSA Time-Series Using Windowed Approaches (such as Drew Abbney's approach):

    from sync import rsa_time_series
    
    ibi_values_ms = [...]
    rsa_ts = rsa_time_series(ibi_ms=ibi_values_ms, rsa_method='abbney', age_type='infant')
    print(f"RSA Time-Series: {rsa_ts}")

Synchrony estimation

Physiological synchrony can be estimated from a pair of RSA signals (epoch-based magnitude lists or time-series) using techniques such as cross-correlation, simple correlation or crqa.

  1. Correlation of epoch-based RSA
from sync import rsa_per_epoch, epochs_synchrony

ibi_ms_a = [...]
ibi_ms_b = [...]

# calculate RSA
rsa_epochs_a = rsa_per_epoch(ibi_ms=ibi_ms_a, epoch_length_ms=30000, rsa_method='porges_bohrer_nk2')
rsa_epochs_b = rsa_per_epoch(ibi_ms=ibi_ms_b, epoch_length_ms=30000, rsa_method='porges_bohrer_nk2')

# calculate synchrony as correlation of RSA epoch values
sync_score = epochs_synchrony(rsa_epochs_a, rsa_epochs_b, sync_type='pearson')
print(f"Synchrony estimated using Pearson correlation: {sync_score}")
  1. Cross-correlation of adult and infant RSA time-series
from sync import rsa_time_series, cross_correlation_zlc

ibi_ms_adult = [...]
ibi_ms_infant = [...]

# calculate RSA
rsa_ts_adult = rsa_time_series(ibi_ms=ibi_ms_adult, rsa_method='abbney', age_type='adult')
rsa_ts_infant = rsa_time_series(ibi_ms=ibi_ms_infant, rsa_method='abbney', age_type='infant')

#  use zero-lag coefficient of cross-correlation as syncnchrony estimation
zlc = cross_correlation_zlc(rsa_ts_adult, rsa_ts_infant)
print(f"Cross-correlation ZLC: {zlc}")
  1. ⭐️ Multimodal synchrony ⭐️: all synchrony scores at once
from sync import multimodal_synchrony

ibi_ms_adult = [...]
ibi_ms_infant = [...]

sync_dict = multimodal_synchrony(ibi_ms_adult, ibi_ms_infant, dyad_type='adult_infant')

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages