I intend to perform spectral analysis with
R stat:spectrum and then plot power spectrum.
My code is listed here:
t <- seq(0,1024,by=0.1) x <- cos(2*pi*t) + 0.75*sin(2*pi*4*t) + 2*sin(2*pi*6*t) x.spec <- spectrum(x,log="no",span=5,plot=FALSE) del <- 0.1 spx <- x.spec$freq/del spy <- 2*x.spec$spec plot(spy~spx,xlab="frequency",ylab="spectral density",type="l")
the signal has 3 periodic components with 1 Hz, 4 Hz, 6 Hz, but the final spectrum only shows the first 2 frequencies, without 6 Hz. And I don't know why the range of
x.spec$freq is [0,0.5] before scaling.
Please tell me my possible concept misunderstanding and guide me how to plot the spectrum correctly. Thank you very much.