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

[Experimental]

This function performs the following steps:

  1. Computes the Fourier Transform of both input signals using fftab.

  2. Calculates the cross-spectrum of the signals.

  3. Converts the cross-spectrum to polar form and computes the weighted average phase difference.

  4. Adjusts the phase of the second signal (b) using .shift_phase to maximize alignment with the first signal (a).

  5. 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:

See Also

Examples

phase_diff(
  sin(seq(0, 2 * pi, length.out = 128)),
  cos(seq(0, 2 * pi, length.out = 128))
)


[Package fftab version 0.1.0 Index]