phase_diff {fftab} | R Documentation |
Compute Phase Difference and Maximum Correlation Between Two Signals
Description
Computes the phase difference and maximum normalized correlation between two input signals
after phase-aligning the second signal (b
) to the first signal (a
).
Usage
phase_diff(a, b)
Arguments
a |
A numeric vector or time series representing the first signal. |
b |
A numeric vector or time series representing the second signal. |
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.
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.
See Also
Examples
phase_diff(
sin(seq(0, 2 * pi, length.out = 128)),
cos(seq(0, 2 * pi, length.out = 128))
)