Advanced Octave A46 — Cross-channel correlation and delay
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
- How long do seven samples last at 100 Hz?
- Which channel is late according to the script convention?
- Does the peak of correlation prove that one channel causes the other?
Worked solution
- 7/100 = 0.07 s.
yfollowsxof seven samples.- No, we need system knowledge, proper controls and analysis to discuss a causal relationship.
Other steps of this project
- Advanced Octave A75 — Dynamical systems in phase space
- Advanced Octave A81 — Geography of the waves and a 3D surface
- Advanced Octave A82 — Age, sex and demographic inequalities
- Advanced Octave A83 — All-cause mortality, certified COVID deaths and surveillance
- Advanced Octave A84 — A reproducible public account
- Advanced Octave A73 — Optimization landscapes and 3D trajectories