# How to calculate the gain in a bivariate fft in R?

In Statistica gain is defined as follows:

Gain. The gain value is computed by dividing the cross-amplitude value by the spectrum density estimates for one of the two series in the analysis. Consequently, two gain values are computed, which can be interpreted as the standard least squares regression coefficients for the respective frequencies.

However, spec.pgram (the engine behind spectrum) in R does not return the cross-amplitude value (as far as I can tell). How can I calculate gain for these signals?

Example:

makewave <- function(freq,phase,amp,Nsamples=length*samplerate,samplerate,time=Nsamples/samplerate,as.time.series=TRUE) {
time <- Nsamples/samplerate
phase <- phase*(2*pi)/180
wavetimes <- seq(0+phase,time*freq*pi*2+phase,length.out=Nsamples)
#plot(1:samples/samplerate,amp*sin(wavetimes),type="l",xlab="Time")
if (as.time.series) {res <- ts(amp*sin(wavetimes),deltat=1/samplerate)} else {res <- amp*sin(wavetimes)}
return(res)
}
signal1 <- makewave(15,30,1,180,60)
signal2 <- makewave(15.01,60,1,180,60)
signal.union <- ts.union(signal1,signal2)
sp <- spectrum(signal.union,span=c(3),taper=0)
plot(sp)
plot(sp,plot.type="phase")
plot(sp,plot.type="coh")

• I'm sorry if this question is too simple for this site. If so, I'll delete it. – russellpierce Apr 3 '12 at 22:04
• It's not too simple, it's just not very clear- at least to me. What do you mean by "bivariate fft"? It looks like you are calculating the fft of two signals added together. Is that what "bivariate fft" means? What does "cross-amplitude value" mean? – Jim Clay Apr 4 '12 at 1:10
• @JimClay I believe that bivariate FFT is simply a two-dimensional FFT. – Phonon Apr 4 '12 at 1:44
• "The cross amplitude values are computed as the square root of the sum of the squared cross-density and quad-density values. The cross-amplitude can be interpreted as a measure of covariance between the respective frequency components in the two series." (documentation.statsoft.com/STATISTICAHelp.aspx?path=TimeSeries/…) – Jim Clay Apr 4 '12 at 13:33
• I am/was shaky on the correct terminology. I have two signals, and I want to compare them to see how much the 2nd matches the first (coh), how much the 2nd lags behind the 1st (phase), and the extent to which the 2nd is under/overshooting the peak amplitudes of the 1st. – russellpierce Apr 4 '12 at 15:55