# specxy_anal

Calculates cross spectra quantities of a series.

## Prototype

function specxy_anal ( x [*] : numeric, y [*] : numeric, iopt [1] : integer, jave [1] : integer, pct [1] : numeric ) return_val [1] : float or double

## Arguments

*x*

*y*

One-dimensional arrays containing the data. *x* and *y*
must be the same length, and missing values are not allowed.

*iopt*

A scalar representing the detrending option:

*iopt*= 0- Remove series mean.
*iopt*= 1- Remove the series mean and least squares linear trend.

*jave*

A scalar representing the smoothing to be performed on the periodogram estimates. This should be an odd number (>= 3). If not, the routine will force it to the next largest odd number.

*jave*< 3- Do no smoothing.
*spcx*contains raw spectra estimates (periodogram). *jave*>= 3- Average
*jave*periodogram estimates together utilizing modified Daniell smoothing (good stability but may lead to large bias). All weights are 1/*jave*except weight(1) and weight(*jave*) which are 1/(2**jave*). This is the recommended option. It is this number which has the most impact on the degrees of freedom.

*pct*

A scalar representing the percent of the series to be tapered (0.0
<= *pct* <= 1.0). If *pct* =0.0, no tapering will
be done. If *pct* = 1.0, the whole series is affected. A value
of 0.10 is common (tapering should always be done).

## Return value

The return value is a scalar representing the degrees of freedom. The
scalar will be double if *x*, *y*, or *pct* are
double, and float otherwise. See the description below for a list of
attributes that are also returned.

## Description

**specxy_anal** returns the degrees of freedom as a
scalar. It also returns the following attributes:

*spcx,spcy*- One-dimensional arrays of length
*N*/2.*spcx*(0) - spectral estimate at frequency = (1/*N*)

[*N*=**dimsizes**(x)]*spcx*(*N*/2-1)- spectral estimate at frequency = 0.5These spectra have been normalized so that the area under the curve:

(

equals the variance of the detrended series, where df=(1/*spcx*(0)+*spcx*(*N*/2-1))*(df/2) + SUM{*spcx*(n)*df}*N*)=frequency spacing and n=1 to*N*/2-2.The units are variance/(unit frequency interval).

*frq*- A one-dimensional array of length
*N*/2 representing frequency (cycles/time). *cospc*- A one-dimensional array of length
*N*/2 representing the cospectrum. This is the real part of the cross spectrum. It measures the extent to which there are oscillations with the same phase in the two series (or with opposite sign, i.e. with a phase shift of half a cycle). In other words, it measures the contribution of different frequencies to the total cross-covariance at zero lag. *quspc*- A one-dimensional array of length
*N*/2 representing the quadrature spectrum. This is the imaginary part of the cross spectrum. it measures the extent to which there are oscillations with a phase difference of a quarter cycle in either direction. i.e., It measures the contribution of different frequencies to the total cross-covariance of the series when all harmonics of one series are delayed a quarter cycle relative to the other relative to the other series. *coher*- A one-dimensional array of length
*N*/2 representing coherence squared. This is analogous to the square of the correlation coef except that the coherence squared is a function of frequency. *phase*- A one-dimensional array of length
*N*/2 representing the phase in degrees. A positive phase indicates that*x*leads*y*. *bw*- A scalar (same type as output) representing the spectral bandwidth.
*coher_probability*- An array of length 4 containing the coherence corresponding to the
90, 95, 99, and 99.9% levels.
*xavei*- A scalar (same type as output) representing the average of the x
series on input.
*xvari*- A scalar (same type as output) representing the variance of the x
series on input.
*xvaro*- A scalar (same type as output) representing the variance of the x
series after detrending.
*xlag1*- A scalar (same type as output) representing the lag-one autocorrelation
of the x series after detrending.
*xslope*- A scalar (same type as output) representing the least-squares
slope per time interval of linear trend (if
*iopt*= 1) of the x series. *yavei*- A scalar (same type as output) representing the average of the y
series on input.
*yvari*- A scalar (same type as output) representing the variance of the y
series on input.
*yvaro*- A scalar (same type as output) representing the variance of the y
series after detrending.
*ylag1*- A scalar (same type as output) representing the lag-one autocorrelation
of the y series after detrending.
*yslope*- A scalar (same type as output) representing the least-squares
slope per time interval of linear trend (if
*iopt*= 1) of the y series.

-------------------------------------------------------------------------------- Some NCL users have asked about testing for significance. The following may help: The coherence-squared is a statistic that can be used to examine the relation between two signals or data sets. It allows identification of significant frequency-domain correlation between the two time series.Phase estimates in the cross spectrum are only useful where significant frequency-domain correlation exists.References:Dennis Hartmann http://www.atmos.washington.edu/~dennis/552_Notes_6c.pdf See Table 6.2 , page 187 and the associated caption on page 186 Comments on the Determination of Significance Levels of the Coherence Statistic Paul R. Julian J. of Atm. Sci. (1975), Volume32, pp 836-837. Coherence Significance Levels Rory O. R. Y. Thompson Journal of the Atmospheric Sciences, 1979 Volume36, pp 2020-2021

## See Also

**specx_anal**,
**cohsq_c2p**,
**cohsq_p2c**,
**specx_ci**

## Examples

**Example 1**

Perform cross-spectral analysis on series *x* and
*y*:

iopt = 1 ; remove least squares linear trends from each ; series prior to tapering and computing spectra. jave = 7 ; Average 7 periodogram estimates using modified Daniell pct = 0.1 ; taper 10% of the data sdof =specxy_anal(x,y,iopt,jave,pct)

**Example 2**: Calculate the probability level of each coherence-squared returned by **specxy_anal**.

d = 0 ; detrending opt: 0=>remove mean 1=>remove mean and detrend sm = 7 ; smoothing periodogram: should be at least 3 and odd pct = 0.10 ; percent tapered: 0.10 common. ; calculate the cross-spectrum sdof =specxy_anal(x,y,d,sm,pct) ; sdof is a scalar quantity c2 = spec@coher ; c2(N) p =cohsq_c2p(c2, sdof) ; p(N), 0 <=p<= 1 ; print the values