Advanced Octave A46 — Cross-channel correlation and delay

by Giux GX-TXT, octave-en, scripts-en 2 min read

Advanced GNU Octave with GX-TXT · Module 08

Two sensors can observe the same phenomenon at different times. A correlation calculated on candidate delays can help to estimate the timeline, provided that conventions and limits are explicit.

Objectives and prerequisites

We use two sampled synthetic sequences at 100 Hz. The test was performed with GX-TXT dev112-P011-bis and GNU Octave 9.4.0. Import ritardo.m, register it and run it in the Runner. The Dataset octave_advanced_crosscorr is created-only: to repeat, use a new session or change the ID.

Build and look for the delay

The reproducible generator uses the 2026 seed. x is a random sequence; y contains a delayed copy of seven samples plus independent noise. For each delay between −20 and +20 samples the program compares only the overlapping portions, subtracts the average of each portion and normalizes the product to scale with their respective standards.

The convention here is explicit: a positive delay k compares x(1:N-k) with y(1+k:N), so it means that y comes after x. Different conventions can reverse the sign.

The test finds a maximum of about 0.99585 to +7 samples: at 100 Hz corresponds to 0.070 s. The script publishes the correlation curve compared to the delay in seconds; NUMERIC_API_v1 also calculates the average curve between the delays tested.

Interpreting the result

The delay sought depends on the chosen range: if the true maximum was out of ±20 samples, this search could not find it. Periodic signals can produce more maximum; noise, gaps and finite length can alter the estimate. A high correlation describes a statistical relationship in the compared portions, but does not demonstrate causality or identifies the physical mechanism alone.

Exercise

  1. How long do seven samples last at 100 Hz?
  2. Which channel is late according to the script convention?
  3. Does the peak of correlation prove that one channel causes the other?

Worked solution

  1. 7/100 = 0.07 s.
  2. y follows x of seven samples.
  3. No, we need system knowledge, proper controls and analysis to discuss a causal relationship.

Download the Module 08 scripts (ZIP)

#GNU Octave #GX-TXT #GX-TXT public APIs

Other steps of this project

Leave a Reply

Your email address will not be published. Required fields are marked *