There seems to be a bug in a R package named pgam:periodogram().
The function intensity happened to have two cos. One of them should be sin.
Here is the correct version.
function (w, x)
n <- length(x) t <- seq(1:n) sp <- ((sum(x * cos(w * t)))^2 + (sum(x * sin(w * t)))^2)/n return(sp) }