# Program to identify the freqs amps and phases of a function
# that is a sum of sines each of which oscillates an integral number
# of times for N points
N = 1024 # FFT works best with powers of 2
t = seq(from=0,by=2*pi/N,length=N) # N evenly spaced pts 0 -- 2*pi
f = 100 # number of cycles per N pts
y = 1*cos(f*t+1) +
2*cos(2*f*t + 2) +
3*cos(3*f*t +3);
plot(y[1:100],type="l")
Y = fft(y) # take the fft
plot(Mod(Y[1:(N/2)]) / (N/2)) # plot of Modulus = amplitudes
#plot(Y[1:(N/2)])