Professional Documents
Culture Documents
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.
This account will be removed after the course. Do not store files you wish to retain on this account.
3 ARMA(p,q)-models in Matlab
An ARMA(p, q)-model
X(t) + a1 X(t 1) + + a p X(t p) = e(t) + c1 e(t 1) + + cq e(t q)
can also be written as
A(z1 )X(t) = C(z1 )e(t),
where
A(z1 ) = 1 + a1 z1 + + a p zp
C(z1 ) = 1 + c1 z1 + + cq zq .
The operator z1 is the time delay unit. If you choose C(z) 1 the process becomes
an 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. z p A(z1 ) =
z p + + a p1 z + a p is represented with the row matrix [1 a1 ... ap].
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 vector
element r(1) is equal to the covariance value at zero, i.e. rX (0) = r(1), and more
generally rX (k) = r(k+1) in Matlab. If you instead are interested in the correlation
function () = r()/r(0) you obtain it by writing
>> stem([0:127], r(1:128)/r(1),filled)
4 Filter design
Different filters can be designed directly by placing poles and zeros in armagui. As
the input process of ARMA-processes (as well as AR- and MA-) is white noise, the
spectral 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 mind
and try different possibilities! Sort out how your movements of the poles and zeros
effect the frequency function. Create e.g., a low-pass filter, a high-pass filter, a
band-pass filter and a band-stop filter.
2. Try to create a low-pass filter using 6 poles and 6 zeros. The filter should have
a flat spectral density (not necessarily with power one) below 0.25 and as small
energy as possible at frequencies above 0.25. When you have found a model that
you are satisfied with, export it. Thereafter, load the file lowpass.mat Matlab
which contain a Butterworth low-pass filter. (The function butter in the Signal
Processing Toolbox of Matlab can be used.) Then import the model lowpass
to armagui and compare to your own filter. Can you explain why this design
work.
3. Create a notch-filter, which is a band-stop filter for a very small frequency
interval. Use one pair of complex-valued poles and one pair of complex-valued
zeros. (Hint: Put the zeros on the unit circle and move the poles close to the zeros
and investigate the result).
6 Cross spectrum
The cross spectrum of the input signal X(t) and the output signal Y (t) from the filter
with 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 as
the 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 effect
the coherence spectrum? Can you intuitively explain this?
subplot(211)
plot(Road1(:,1))
subplot(212)
plot(Road1(1:10:end,1),Road1(1:10:end,2),.)
grid, axis square
5
Examine the cross-covariance between the tracks. The function covf computes covariance and cross-covariance function for the signal and return a matrix with four rows
and M columns,
>> r = covf(Road1,2000);
where r is a matrix with four rows and 2000 columns.The rows contain estimates of the
following 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 covariance
passed 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 the
cross 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 the
third argument is the number of frequencies that we estimate the spectrum at. In
the plot you can see the frequency dependency. Does the frequency dependency seems
reasonable for the knowledge you have on roads? Did you draw the correct conclusion
about the periodicity above?
8 MATLABfunctions
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
% 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.
%