# parameters used in the Fourier Transform: nyears = 4 # used 4 years of data to calculate the Fourier Transform ppyear = 64 # used a time step of 64 points per year in the input data to calculate the Fourier Transforms. # reading in the Fourier Transform data file: FT = read.table("FT_2003-2006_64ppyear_ERAday_0_1deg_255721.txt",header=T) # selecting a number of locations for which to evaluate the time series: # (skip if you want to calculate the whole file) FT = FT[1:10,] # specifying the time points throughout the year # for which to calculate the time series. # here: daily time step timepoints = (1:365)/365 # calculating the constant term (=annual mean) for each location and time point: TS0 = matrix(FT$H0/(nyears*ppyear),nrow=nrow(FT),ncol=length(timepoints)) # calculating the time series based on # constant term H0 and annual mode H1: TS1 = TS0 + 1/(nyears*ppyear)*(outer(FT$ReH1,cos(2*pi*timepoints*1))+outer(FT$ImH1,sin(2*pi*timepoints*1))) # calculating the time series based on # constant term H0, annual mode H1 and biannual mode H2 TS2 = TS1 + 1/(nyears*ppyear)*(outer(FT$ReH2,cos(2*pi*timepoints*2))+outer(FT$ImH2,sin(2*pi*timepoints*2))) # plotting the reconstructed time series for a selected location: i=1 plot(timepoints, TS0[i,], type="l",lwd=2,ylim=range(c(TS0[i,],TS1[i,],TS2[i,])),xlab="time throughout the year",ylab="Temperature in Celsius",main="") lines(timepoints, TS1[i,],col=2,lwd=2) lines(timepoints, TS2[i,],col=3,lwd=3) legend("bottomright",col=1:3,lwd=2,legend=c("constant term H0","constant term H0 and annual mode H1","constant term H0, annual mode H1 and biannual mode H2")) title(main=paste("Reconstructed time series \nfor longitude ",FT$longitude[i]," and latitude ",FT$latitude[i],sep=""))