Learn R Programming

fftab (version 0.1.0)

phase_diff: 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)

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.

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.

See Also

  • fftab()

  • cross_spec()

Examples

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

Run the code above in your browser using DataLab