Trigonometric functions in discrete time: sin ( 2pπ t ) cos ( 2pπ t ) p=12 p=6 p=4 p=3 p=2.4 p=2 If one observation is sampled per unit of time, a periodic function with period n completes one full cycle in the observation period, a periodic function with period n/2 completes two full cycles in the observation period, etc. In general, a periodic function with period n/k completes k full cycles in the observation period. The frequency ωk=2πk/n that is associated with the period n/k is called the k-th Fourier frequency. We consider only those Fourier frequencies ωk that are less than or equal to the Nyquist frequency π, i.e., k≤m=[n/2]. If the improper Fourier frequency 2π 0/n=0 is also included, there are always n non-vanishing sines and cosines. If n is even and m=n/2, we have 1) t ). 1, cos( 2πn⋅1 t ), …, cos( 2 π⋅n m t ), sin( 2πn⋅1 t ), ..., sin( 2 π⋅(mn Clearly, g(t)=cos( 2π2 t)=cos(π t)=(-1)t is the most rapid oscillation we can observe. The frequency π (one half a cycle per sampling interval) is known as Nyquist frequency. If n is odd and m=(n-1)/2, we have 1, cos( 2πn ⋅1 t ), ..., cos( 2πn⋅m t ), sin( 2πn ⋅1 t ), …, sin( 2πn⋅m t ). Note that cos( 2 πn⋅0 t ) equals 1 and sin( 2 πn⋅0 t ) vanishes. If n is even, then sin( 2 π⋅n m t )=sin(πt) vanishes too. 1 n Exericse: Show that bˆ = ∑ xt yt t =1 n ∑x 2 t minimizes the t =1 (Aˆ , Aˆ , Bˆ ,...) = ((C , C , S ,...) (C , C , S ,...)) T 0 n sum of squared errors In the case of orthogonal regressors, the LS estimates ∑ ( yt−bxt)2. CB t =1 Using only Fourier frequencies ωk=2π k/n, k∈T⊆{0,…,m}, in the trigonometric regression model yt= ∑ ( Akcos(ωkt)+Bksin(ωkt))+ut k∈T has the advantage that the regressors are orthogonal1, i.e., C S j = 0 , if 0≤j,k≤m, T k 1 1 1 where 1 1 −1 (C0 , C1 , S1 ,...)T y C0T y T C1 y STy 1 M = diag ( n , n / 2 , n / 2 ,...) n Aˆ 0 = ∑ cos(ω0t ) yt 2π j n n n ∑ cos t =1 2 (ω0t ) = n 1 n ∑ cos(ω0t ) yt = y , n t =1 n t =1 n t =1 n t =1 t =1 Aˆ1 = ∑ cos(ω1t ) yt ∑ cos 2 (ω1t ) = 2n ∑ cos(ω1t ) yt , Bˆ1 = ∑ sin(ω1t ) yt ∑ sin 2 (ω1t ) = n2 ∑ sin(ω1t ) yt , … t =1 n t =1 See Appendix B. 0 C0T C0 C0T C1 C0T S1 L T C1 C0 C1T C1 C1T S 0 L = T T T S1 C0 S1 C1 S1 S1 L M M M O 14444 4244444 3 t =1 cos ( sin ( ⋅1 ) ⋅1 ) Ck = M M , Sk = . 2π k 2π j cos ( n ⋅ n) sin ( n ⋅ n) 1 1 obtained from the full model are identical to the estimates S kT S j = CkT C j = 0 , if 0≤j≠k≤m, 2π k n −1 T 0 obtained from simple models with only one regressor. CR 2 n Exercise: Show that ∑ cos ( π 2 2 k n t ) =n, if k= n2 . CN t =1 Exercise: If n is even, then m=n/2 and ωm=π. But since sin(π t)=0, only cos(π t) can be used as a regressor. Show that the LS estimate of the parameter Am is given by Aˆ m = n 1 n ∑ y (−1) . t CM t The periodogram I(ω) of a time series y1,…,yn is for a Fourier frequency ωk with k∈{1,2,…,[ n2−1 ]} defined by = (( ∑y t t =1 n I(ω)= = Rˆ k2 n n n t =1 t =1 I(ω)= 2π1 n (( ∑ yt cos(ωt))2+( ∑ yt sin(ωt))2), 1 2π n n n t =1 t =1 cos(ωkt)) +( 2 n 2 n n ∑y t sin(ωkt)) ) t =1 2 1 2π n 2 ∑ yt( cos (ωt) + i sin (ωt)) t =1 n = 2π1 n 2 ∑ yt cos (ωt) + i∑ yt sin (ωt) n I(ωk)= 8nπ ( Aˆ k2 + Bˆ k2 ) 1 424 3 2 n Defining the periodogram for an arbitrary frequency ω by it can be written in complex form as t =1 n 8π Apart from an unimportant scaling factor, I(ωk) is just the squared estimate of the amplitude of a sinusoid with frequency ωk, hence its size indicates how important that particular frequency is. ∑ yt e 2 iωt . CP t =1 = 2π1 n (( ∑ yt cos(ωkt))2+( ∑ yt sin(ωkt))2). t =1 t =1 3 Exercise: Show that it is sufficient to consider I(ω) on the interval 0≤ω≤π by proving that I(ω) is periodic with period 2π and symmetric about the y-axis. CS Exercise: Revisit the not seasonally adjusted Retail and Food Services Sales. Plot the differenced log series. d <- y-lag(y,k=-1); d <- na.omit(d,method="r") par(mar=c(2,2,1,1)); plot(d,type="l") The sequence n ∑ yt e −iωk t , k=0,…,n−1, t =1 is called the discrete Fourier transform (DFT) of the sequence y1,…,yn. The R function fft uses a fast algorithm (the fast Fourier transform) to calculate the slightly different version n ∑ yt e −iωk (t −1) , k=0,…,n−1. t =1 However, we have n ∑ yt e 2 −iωk ( t −1) =e iωk t =1 2 n ∑ yt e −iωk t t =1 = 2 eiωk { =1 n ∑ yt e 2 −iωk t . t =1 4 Exercise: Calculate the periodogram of d at the Fourier frequencies ωk, k=1,…,[n/2] and plot it. n <- length(d); m <- floor(n/2) # number of frequencies f <- (2*pi/n)*(1:m) # vector of frequencies ft <- fft(d)[2:(m+1)] # excl. k=0,m+1,m+2,...,n-1 pg <- (1/(2*pi*n))*(Mod(ft))^2 # Mod = modulus plot(f,pg,type="l") Exercise: Redo the last exercise, but this time omit some observations to guarantee that the seasonal frequencies 2πj/12, j=1,…,6, are Fourier frequencies. r12 <- n%%12 # n modulo 12 # the remainder we get when we divide n by 12 n12 <- n - r12 d12 <- d[(r12+1):n] # omit the first r12 observations # length of new series d12 is divisible by 12 m12 <- floor(n12/2); f12 <- (2*pi/n12)*(1:m12) ft12 <- fft(d12); ft12 <- ft12[2:(m12+1)] pg12 <- (1/(2*pi*n12))*(Mod(ft12))^2 plot(f12,pg12,type="l") The peaks at the seasonal frequencies are more pronounced than the slightly displaced peaks in the last exercise. 5