arma

7
Lund University Projects in Stationary stochastic processes Centre for Mathematical Sciences VT 2009 Mathematical Statistics Computer Exercise 1 Preparations Carefully read through the entire computer exercise. Read Chapter 5.1-5.2, 5.5 and 6.1 in the compendium. Answer the exercises in the question dictionary below; you are expected to be able to answer these questions during the exercise. 1.1 Question dictionary 1. What is the connection between the spectral densities for input and output pro- cesses in a linear filter? 2. Define the quadratic coherence spectrum. What is the minimum and maximum value of the function? 3. The cross spectrum of the input process X (t ) and the output process Y (t ) from the filter with frequency function H ( f ) is R X , Y ( f )= H ( f )R X ( f ). For a white noise input, R X ( f )= 1 and R X , Y ( f )= H ( f ) . What is the quadratic coherence spectrum κ X , Y ( f ) ? 4. Let an uncorrelated disturbance process Z (t ) be added to the filtered process, i.e., Y (t )= h(t - u)X (u)du + Z (t ) , where X (t ) is white noise. What is R X , Y ( f ) and κ X , Y ( f ) in this case? 2 To start the exercise During the exercise, you will use your temporary computer account 1 . Log on to the account, open a shell-window (icon with shell) and initiate the Matlab environment by typing: matstat/mc1> initmstat matstat/mc1> matlab <MATLABSTARTAR> >> fms045mas210 WAFO toolbox paths set: normal initiation 1 This account will be removed after the course. Do not store files you wish to retain on this account. 1

Upload: saideepnarasimhan

Post on 20-Dec-2015

4 views

Category:

Documents


0 download

DESCRIPTION

ARMA

TRANSCRIPT

Page 1: Arma

Lund University Projects in Stationary stochastic processesCentre for Mathematical Sciences VT 2009Mathematical Statistics

Computer Exercise

1 Preparations

Carefully read through the entire computer exercise. Read Chapter 5.1-5.2, 5.5 and 6.1in the compendium. Answer the exercises in the question dictionary below; you areexpected to be able to answer these questions during the exercise.

1.1 Question dictionary

1. What is the connection between the spectral densities for input and output pro-cesses in a linear filter?

2. Define the quadratic coherence spectrum. What is the minimum and maximumvalue of the function?

3. The cross spectrum of the input process X(t) and the output process Y (t) fromthe filter with frequency function H( f ) is

RX ,Y ( f ) = H( f )RX( f ).

For a white noise input, RX( f ) = 1 and RX ,Y ( f ) = H( f ) . What is the quadraticcoherence spectrum κX ,Y ( f )?

4. Let an uncorrelated disturbance process Z(t) be added to the filtered process,i.e., Y (t) =

∫h(t − u)X(u)du + Z(t) , where X(t) is white noise. What is RX ,Y ( f )

and κX ,Y ( f ) in this case?

2 To start the exercise

During the exercise, you will use your temporary computer account1. Log on to theaccount, open a shell-window (icon with shell) and initiate the Matlab environment bytyping:matstat/mc1> initmstatmatstat/mc1> matlab< M A T L A B S T A R T A R>>> fms045mas210WAFO toolbox paths set: normal initiation

1This account will be removed after the course. Do not store files you wish to retain on this account.

1

Page 2: Arma

It is often convenient to gather Matlab commands in a program script; the Matlabeditor can be used for this purpose. This is started with the command edit in theMatlab window.

3 ARMA(p,q)-models in Matlab

An ARMA(p,q)-model

X(t)+a1X(t−1)+ · · ·+apX(t− p) = e(t)+ c1e(t−1)+ · · ·+ cqe(t−q)

can also be written asA(z−1)X(t) = C(z−1)e(t),

whereA(z−1) = 1+a1z−1 + · · ·+apz−p

C(z−1) = 1+ c1z−1 + · · ·+ cqz−q.

The operator z−1 is the time delay unit. If you choose C(z) ≡ 1 the process becomesan AR(p)-process, and if you choose A(z)≡ 1 it becomes an MA(q)-process.

In Matlab, polynomials are represented as row matrices with coefficients; e.g. zpA(z−1)=zp + · · ·+ap−1z+ap is represented with the row matrix [1 a1 ... ap].

3.1 Spectral density and covariance function

Initiate the row vectors of the ARMA(4,2)-model

X(t)−0.9X(t−1)+0.8X(t−2)−X(t−3)+0.8X(t−4) = e(t)+0.4e(t−1)+0.5e(t−2)

by writing

>> A = [1 -0.9 0.8 -1 0.8];>> C = [1 0.4 0.5];

in Matlab. To compute spectral density for this ARMA-process, one approach is to usethe commands

>> [H,w]=freqz(C,A);>> R=abs(H).^2;

where freqz is a Matlab-function that calculates the frequency function correspondingto the polynomials C and A in a number of equally spaced frequency values (default512) between 0 ≤ ω < π where ω = 2π f . The squared absolute value gives us thespectral density S . Visualize using

>> plot(w,R)

2

Page 3: Arma

The command semilogy(w,R) gives a logarithmic scale in y-axis.

To calculate the covariance function the inverse Fourier transform of the spectral den-sity is computed. The frequency range must be the whole period, i.e., −0.5 ≤ f < 0.5alternatively 0 ≤ f < 1 when the command ifft is used. The frequency function iscomputed for this range using whole in the function freqz,

>> H=freqz(C,A,512,’whole’);>> Rd=abs(H).^2;>> r=ifft(Rd);>> stem([0:127],r(1:128),’filled’)

where the 128 first values of the covariance function is plotted. Observe that the vectorelement r(1) is equal to the covariance value at zero, i.e. rX(0) = r(1) , and moregenerally rX(k) = r(k+1) in Matlab. If you instead are interested in the correlationfunction ρ(τ) = r(τ)/r(0) you obtain it by writing

>> stem([0:127], r(1:128)/r(1),’filled’)

3.2 Simulation of ARMA-processes

To be able to simulate an ARMA-model one need a sequence of independent normally2

distributed {e(t)} stochastic variables. Generate such a sequence with variance 1 by

>> m = 0;>> sigma = 1;>> e = normrnd(m, sigma, 1, n);

alternatively

>> e = randn(1,n);

Each call generate a row-matrix e with n normally random numbers, choose n≈ 400 .The simulation is done with

>> x = filter(C, A, e);

which result in the vector Y with the simulated time-series as the result, where A andC are defined as earlier. If you want to plot the result you can write e.g.

>> plot(x)

2In general e(t) does not need to be normally distributed.

3

Page 4: Arma

4 Filter design

Different filters can be designed directly by placing poles and zeros in armagui. Asthe input process of ARMA-processes (as well as AR- and MA-) is white noise, thespectral density plot will also be the plot of |H( f )|2 as Re( f ) = 1 .

1. Try to make some interesting filters by placing poles and zeros. Free your mindand try different possibilities! Sort out how your movements of the poles and zeroseffect the frequency function. Create e.g., a low-pass filter, a high-pass filter, aband-pass filter and a band-stop filter.

2. Try to create a low-pass filter using 6 poles and 6 zeros. The filter should havea flat spectral density (not necessarily with power one) below 0.25 and as smallenergy as possible at frequencies above 0.25. When you have found a model thatyou are satisfied with, export it. Thereafter, load the file lowpass.mat Matlabwhich contain a Butterworth low-pass filter. (The function butter in the SignalProcessing Toolbox of Matlab can be used.) Then import the model lowpassto armagui and compare to your own filter. Can you explain why this designwork.

3. Create a ”notch”-filter, which is a band-stop filter for a very small frequencyinterval. Use one pair of complex-valued poles and one pair of complex-valuedzeros. (Hint: Put the zeros on the unit circle and move the poles close to the zerosand investigate the result).

5 Spectral estimation of sea waves

Load the file afric.mat. The file contains measurements of the height of the seasurface, in meter, outside western Africa. The measurements have been taken duringapproximately 40 minutes and there are four measurements for each second.

Import afric to spekgui. Compute a spectral estimate of the sea wave data usingWelch’s method with 60 average. Which are the main frequencies of the process? Whichperiods correspond to the main frequencies? Do the periodicities seem to be reasonable?What do sea-waves look like? Is every seventh wave bigger than the others?

Go back to armagui and try to make an ARMA-model with a spectrum similarto the spectrum of the afric data, i.e., one with two peaks, and with the powerapproximately equal to zero for f = 0 . (Hint: An ARMA(4,3)-model can be useful.)

Compare the estimated covariance function with the covariance function for your mo-del. What seems to the most appropriate tool for analysing the wave data: the covari-ance function or the spectrum?

4

Page 5: Arma

6 Cross spectrum

The cross spectrum of the input signal X(t) and the output signal Y (t) from the filterwith frequency function H( f ) is

RX ,Y ( f ) = H( f )RX( f ).

For a white noise input signal RX( f ) = 1 and RX ,Y ( f ) = H( f ) . Use an ARMA(4,2)-process

X(t)−0.9X(t−1)+0.8X(t−2)−X(t−3)+0.8X(t−4) = e(t)+0.4e(t−1)+0.5e(t−2)

by writing

A = [1 -0.9 0.8 -1 0.8];C = [1 0.4 0.5];

in Matlab. Compute the filter for this ARMA-process, and a lowpass AR(1)-process asthe uncorrelated disturbance Z(t) i.e.,

[H,w]=freqz(C,A);A2=[1 -0.95];[H2,w]=freqz(1,A2);kappa=abs(H).^2./(abs(H).^2+abs(H2).^2);plot(w,kappa)

1. Change the location of the pole of the low-pass disturbance process, .e.g, a1 =0.95 . What differs in the resulting coherence spectrum? Why?

2. Change the power of the disturbance process,

kappa=abs(H).^2./(abs(H).^2+sigma2*abs(H2).^2);

where sigma2 can be chosen e.g., 0.01, 0.1, 10 or 100. How does the choice effectthe coherence spectrum? Can you intuitively explain this?

7 Cross-covariance and cross-spectrum estimation

Now shall we examine the relation between left, X1(t) , and right, X2(t) , wheel trackfor measurements of the road level somewhere in Sweden. The measurements are madeevery 10:th centimeter. Load data with load Road1. Study data for some dependence,e.g.,

>> subplot(211)>> plot(Road1(:,1))>> subplot(212)>> plot(Road1(1:10:end,1),Road1(1:10:end,2),’.’)>> grid, axis square

5

Page 6: Arma

Examine the cross-covariance between the tracks. The function covf computes cova-riance and cross-covariance function for the signal and return a matrix with four rowsand M columns,>> r = covf(Road1,2000);

where r is a matrix with four rows and 2000 columns.The rows contain estimates of thefollowing covariance functions: C(X1(t),X1(t + τ)) , C(X2(t),X1(t + τ)) , C(X1(t),X2(t +τ)) and C(X2(t),X2(t +τ)) . We are interested of the rows 2, and 3, the cross covariances.

Plot one of the cross covariances. After how many meters has the cross covariancepassed zero for the first time? Can you see any periodically in the cross covariance.

Now shall we study the cross spectrum of the tracks. One function that estimates thecross spectrum is etfe,

>> left = etfe(Road1(:,1), 64, 512); % calculates Rx1>> right = etfe(Road1(:,2), 64, 512); % calculates Rx2>> ffplot(left,right) % plot Rx1 and Rx2

The spectral densities RX1 and RX2 are very similar and the coherence spectrumκX1,X2( f ) can be estimated with the transfer function,

>> both = etfe(Road1, 64, 512);>> bodeplot(both); subplot(211); set(gca,’yscale’,’linear’)

The second argument to etfe is a smoothing factor, lower implies smoother, and thethird argument is the number of frequencies that we estimate the spectrum at. Inthe plot you can see the frequency dependency. Does the frequency dependency seemsreasonable for the knowledge you have on roads? Did you draw the correct conclusionabout the periodicity above?

6

Page 7: Arma

8 MATLAB–functions

spekgui

function spekgui(action,varargin)% SPEKGUI%% spekgui opens a window for spectral estimation.%% Import data by putting them into a "structure", write the name in the "Import"-box% and push the button.% Example:%% >> litedata.t=linspace(0,50,1001);% >> litedata.x=sin(2*pi*litedata.t)+randn(1,1001)*0.5;%% The different spectral estimation methods are :%% Periodogram% Welch: averaging over m periodogram.% Welch with time window ’Hanning’.%% The covariance function is estimated from data or from% the spectral density estimate.%% The estimates of the covariance function and spectral density% is exported to Matlab with the "Export"-button.%

7