Compute Phase Difference and Maximum Correlation Between Two Signals
Source:R/cross.R
phase_diff.Rd
Computes the phase difference and maximum normalized correlation between two input signals
after phase-aligning the second signal (b
) to the first signal (a
).
Value
A numeric vector of length two:
The first element represents the phase difference (in radians) required to maximize alignment between the two signals.
The second element represents the maximum normalized correlation achieved after phase alignment.
Details
This function performs the following steps:
Computes the Fourier Transform of both input signals using
fftab
.Calculates the cross-spectrum of the signals.
Converts the cross-spectrum to polar form and computes the weighted average phase difference.
Adjusts the phase of the second signal (
b
) using.shift_phase
to maximize alignment with the first signal (a
).Computes the normalized correlation between the phase-aligned signals.
The correlation is normalized using the variances of both signals and will generally be higher than the correlation between the original signals due to the optimal phase alignment.