corr2d: Two-dimensional correlation analysis.

Description Usage Arguments Details Value References See Also Examples


corr2d calculates the synchronous and asynchronous correlation spectra between Mat1 and Mat1 (homo correlation) or between Mat1 and Mat2 (hetero correlation).


corr2d(Mat1, Mat2 = NULL, Ref1 = NULL, Ref2 = NULL, Wave1 = NULL,
  Wave2 = NULL, Time = NULL, Int = stats::splinefun,
  N = 2^ceiling(log2(NROW(Mat1))), Norm = 1/(pi * (NROW(Mat1) - 1)),
  scaling = 0, corenumber = parallel::detectCores(), preview = FALSE)


Mat1, Mat2

Numeric matrix containing the data which will be correlated; 'spectral variable' by columns and 'perturbation variables' by rows. For hetero correlations Mat1 and Mat2 must have the same number of rows.

Ref1, Ref2

Numeric vector containing a single spectrum, which will be subtracted from Mat1 (or Mat2, respectively) to generate dynamic spectra for 2D correlation analysis. Default is NULL in which case the colMeans() of Mat1 (or Mat2, respectively) is used as reference. The length of Ref1 (or Ref2) needs to be equal to the number of columns in Mat1 (or Mat2).

Wave1, Wave2

Numeric vector containing the spectral variable. Needs to be specified if column names of Mat1 (or Mat2) are undefined.


Numeric vector containing the perturbation variables. If specified, Mat1 (and Mat2 if given) will be interpolated to N equally spaced perturbation varibales using Int to speed up the fft algorithm.


Function specifying how the dataset will be interpolated to give N equally spaced perturbation variables. splinefun (default) or approxfun can for example be used.


Positive, non-zero integer specifying how many equally spaced perturbation variables should be interpolated using Int. N should be higher than 4.corr2d is fastest if N is a power of 2.


A number specifying how the correlation matrix should be normalized.


Positive real number used as exponent when scaling the dataset with its standard deviation. Defaults to 0 meaning no scaling. 0.5 (Pareto scaling) and 1 (Pearson scaling) are commonly used to enhance weak correlations relative to strong correlations.


Positive, non-zero integer specifying how many CPU cores should be used for parallel fft computation.


Logical: Should a 3D preview of the synchronous correlation spectrum be drawn at the end? Uses persp3d from rgl package.


corr2d uses a parallel fast Fourier transformation (fft) to calculate the complex correlation matrix. For parallelization the foreach function is used. Large input matrices (> 4000 columns) can lead to long calculation times depending on the number of cores used. Also note that the resulting matrix can become very large, adjust the RAM limit with memory.limit accordingly. For a detailed description of the underlying math see references.


corr2D returns a list of class "corr2d" containing the complex correlation matrix ($FT), the used reference spectra ($Ref1, $Ref2), the spectral variables ($Wave1, $Wave2), the (interpolated) perturbation variables ($Time) and logical variable ($Het) indicating if homo (FALSE) or hetero (TRUE) correlation was done.


I. Noda (1993) <DOI:10.1366/0003702934067694>
I. Noda (2012) <DOI:10.1016/j.vibspec.2012.01.006>

See Also

For plotting of the resulting list containing the 2D correlation spectra see plot_corr2d and plot_corr2din3d.


    data(FuranMale, package = "corr2D")
    twod <- corr2d(FuranMale, Ref1 = FuranMale[1, ], corenumber = 1)
    plot_corr2d(twod, xlab = expression(paste("relative Wavenumber" / cm^-1)),
                      ylab = expression(paste("relative Wavenumber" / cm^-1)))

Search within the corr2D package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.