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")