The cross_spec
function computes the cross-spectrum between two inputs
using the Fourier transform. It supports multiple input types including
numeric vectors, time series (ts
), arrays, and fftab
objects.
The function provides options for normalization and controlling whether the
conjugate of the second input is used.
Usage
cross_spec(a, b, norm = FALSE, conj = TRUE)
# Default S3 method
cross_spec(a, b, norm = FALSE, conj = TRUE)
# S3 method for class 'ts'
cross_spec(a, b, norm = FALSE, conj = TRUE)
# S3 method for class 'array'
cross_spec(a, b, norm = FALSE, conj = TRUE)
# S3 method for class 'fftab'
cross_spec(a, b, norm = FALSE, conj = TRUE)
Arguments
- a
The first input for the cross FFT. Supported types include numeric vectors,
ts
objects, arrays, andfftab
objects.- b
The second input for the cross FFT. Must match the dimensions or structure of
a
.- norm
Logical; if
TRUE
, normalizes the Fourier transforms before computation. Default isFALSE
.- conj
Logical; if
TRUE
, uses the complex conjugate of the Fourier transform ofb
. Default isTRUE
.
Value
An object representing the cross-spectrum:
For
default
andfftab
methods: Afftab
object.For
ts
objects: Afftab
object with.tsp
attributes inherited froma
.For arrays: A
fftab
object with.dim
attributes inherited froma
.
Methods (by class)
cross_spec(default)
: Default method for computing cross FFT. Converts inputs tofftab
objects before computation.cross_spec(ts)
: Method for time series (ts
) objects. Ensures the time series frequencies are consistent and preserves thetsp
attribute.cross_spec(array)
: Method for array inputs. Ensures dimensions are consistent and preserves thedim
attribute.cross_spec(fftab)
: Method forfftab
objects. Performs the cross-frequency transform directly using the Fourier transforms ofa
andb
.
Examples
cross_spec(rnorm(8), rnorm(8), norm = TRUE)
#> # A tibble: 8 × 2
#> .dim_1 fx
#> * <dbl> <cpl>
#> 1 0 0.08308948+0.00000000i
#> 2 0.125 0.10985200-0.12520060i
#> 3 0.25 0.08367576-0.08516305i
#> 4 0.375 0.03773447-0.06840483i
#> 5 0.5 -0.47643722+0.00000000i
#> 6 -0.375 0.03773447+0.06840483i
#> 7 -0.25 0.08367576+0.08516305i
#> 8 -0.125 0.10985200+0.12520060i
cross_spec(
ts(rnorm(8), frequency = 4),
ts(rnorm(8), frequency = 4)
)
#> # A tibble: 8 × 2
#> .dim_1 fx
#> * <dbl> <cpl>
#> 1 0 0.2644164+0.0000000i
#> 2 0.5 -0.8349846-1.3687810i
#> 3 1 -0.1098456-1.7697982i
#> 4 1.5 -11.9966929+0.1242991i
#> 5 2 -2.3836460+0.0000000i
#> 6 -1.5 -11.9966929-0.1242991i
#> 7 -1 -0.1098456+1.7697982i
#> 8 -0.5 -0.8349846+1.3687810i