Time synchronization and waveform alignment algorithms for merging multi-source COMTRADE recordings.
In Detego
When two COMTRADE recordings capture the same power system event from different devices, their timelines must be aligned before the channels can be meaningfully combined. The core problem is that relay clocks are often not synchronized -- even with NTP, clock offsets of tens or hundreds of milliseconds are common. GPS-synced relays have sub-millisecond accuracy, but many installations lack GPS timing.
The alignment algorithm uses a three-layer approach:
The simplest alignment method uses the recording start timestamps embedded in the COMTRADE CFG header. Each recording has a start time and a trigger time . The alignment uses start times rather than trigger times because trigger times include variable relay processing delays that differ between devices.
Timestamp offset
Where
Relays at different substations may be configured with different timezone settings, or one relay may record in UTC while another uses local time. The timezone correction algorithm detects and removes these offsets by checking whether the computed offset is close to a multiple of 15 minutes (the smallest timezone granularity in use worldwide, accounting for zones like UTC+5:45 Nepal and UTC+9:30 Australia).
If the offset falls within a tolerance window of a 15-minute multiple, the nearest multiple is subtracted. This preserves the sub-minute timing difference (which reflects actual clock drift) while removing the timezone component.
Alignment pipeline: File A (purple) and File B before alignment (dotted orange) show a 13 ms timing difference at fault inception. After applying the computed offset, File B (solid orange) aligns with File A — both fault inception points coincide. The opposite current polarity is expected (current flows into the fault from both line ends).
When a fault event is present in both recordings, the fault inception point provides a physical anchor that is independent of clock settings. The algorithm detects fault inception in each recording independently using the superimposed delta method, then aligns the two inception points.
Superimposed delta
Where
The coarse fault-based offset is simply the difference between the two inception times (expressed in their respective local timelines):
Fault inception offset
Where
The detection runs independently on all current and voltage channels in each file. The earliest detected inception across all channels is used. This provides roughly 10-15 ms accuracy, limited by differences in relay ADC processing, anti-aliasing filter delays, and the fact that the fault wavefront arrives at the two line terminals at slightly different times (propagation delay).
After coarse alignment, the offset is refined using cross-correlation of the superimposed delta signals. This exploits the fact that the same fault produces similar transient waveforms at both line terminals (with possible polarity inversion due to opposite CT conventions).
The algorithm finds matching channel pairs by phase -- voltage channels are matched with voltage channels and current channels with current channels. Phase extraction uses the channel naming conventions from the COMTRADE header to identify which channels correspond to phases A, B, and C.
For each matched channel pair, the algorithm:
The normalised cross-correlation function is computed for both polarities to handle the case where CTs at opposite ends of a line produce currents of opposite sign:
Normalised cross-correlation
Where
The correlation is computed for both and (polarity inversion). The polarity that produces the higher peak correlation is selected.
The cross-correlation function has integer-sample resolution. To achieve fractional-sample precision, a parabolic (quadratic) interpolation is fitted to the three samples around the peak:
Parabolic peak refinement
Where
This achieves fractional-sample alignment precision, significantly better than the sample-rate limit.
When both timestamp and fault inception offsets are available, the algorithm cross-validates them by comparing the two independently derived offsets. This provides a measure of clock synchronization quality.
The alignment confidence reflects how reliably the fault inception was detected. It is based on the RMS change at the inception point -- a larger change means a more clearly defined fault onset and therefore a more reliable alignment anchor.
The confidence is measured as the maximum relative RMS change across all channels:
RMS change ratio
Where
The ratio is then mapped to a confidence score on a scale from 0 to 1. Higher RMS changes (indicating more severe faults with clearly defined inception points) produce higher confidence scores.
When the two recordings have different sample rates, the lower-rate recording is resampled to match the higher rate. The target sample rate is:
Target sample rate
Where
Analog channels (voltages and currents) are resampled using linear interpolation between adjacent samples:
Linear interpolation
Where
Boundary samples at the edges of the recording are clamped to the nearest available source sample to avoid extrapolation artifacts.
Digital channels (binary signals such as trip contacts, breaker status, protection flags) use nearest-neighbor resampling. Each output sample takes the value of the closest source sample in time. This preserves the binary nature of the signal -- interpolating between 0 and 1 would produce fractional values that have no physical meaning for contact status signals.
The merged output is serialized as an IEEE C37.111-1999 CFF file (Combined File Format), which embeds both the CFG configuration header and the ASCII DAT sample data in a single file.
Merged recordings enable several important analyses:
Alignment Accuracy