#You can play around with the amplitudes of the following
#cosines
amplitude_k0 = 10
amplitude_k1 = -5
amplitude_k2 = 3
x=seq(0,pi,length.out=10000)
x2=seq(0,2*pi,length.out=10000)
cos0=rep(amplitude_k0,each=10000)
cos1=amplitude_k1*cos(x)
cos2=amplitude_k2*cos(x2)
par(mfrow=c(1,3))
plot(cos0)
plot(cos1)
plot(cos2)

cosinus = dplyr::data_frame(cosinus=c(cos0,cos1,cos2),type=rep(c("k0","k1","k2"),each=10000),x=rep(seq(0,1,length.out=10000),3))

ggplot2::ggplot(cosinus)+
  aes(x=x,y=cosinus,col=type)+
  geom_line(lwd=2)

library(tidyverse)
signal=cosinus%>%
  group_by(x)%>%
  summarise(signal=sum(cosinus))
ggplot(signal)+
  aes(x=x,y=signal)+
  geom_line(lwd=2)

mean(signal$signal)
lm(signal~x,data=signal)
lm(signal~I(x^2)+x,data=signal)

library(emuR)

#dct with only 3 coefficients
dct(signal$signal,m=2,fit=FALSE)

#dct with all (=10000) coefficients,
# but all but the first three are close to zero
dct(signal$signal,fit=FALSE)

#so, you can plot either the one reconstructed with only three
# coefficients or you can plot the recontruction made with all 10000 coefficents
# and they look the same
par(mfrow=c(1,2))
plot(dct(signal$signal,m=2,fit=T))
plot(dct(signal$signal,fit=T),col="red")

