-
Notifications
You must be signed in to change notification settings - Fork 9
/
corf1.m
executable file
·51 lines (42 loc) · 1.22 KB
/
corf1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function R=corf1(x,y,M)
% Correlation matrix corresp to covf.m crossproducts mtx
% Works for two time series only
%
% D. Meko 7-13-93
%
%********** INPUT ARGS *************************
%
% x (mx x 1) first time series, usually the master series
% y (my x 1) second times eries, usually the sample (undated)
% M number of + and - lags to compute xcorrs
%
%
%*********** OUTPUT ARGS **************************
%
% R matrix of correlation coefs, as follows
%
% rows: 1 - lag k autocorrelations of x
% 2 - cross corrs of y lagged 0,-1,-2,..-M
% from x
% 3 - cross corrs of y lagged 0, 1, 2,... M
% from x
% 4 - lag k autocorrels of y
%
% cols: col 1 is lag-0. Col 2 is lag 1. ...
% col M is lag +- lag (M-1)
%
%*********** NOTES *********************************
%
% x and y must be column vectors
[mx,nx]=size(x);
[my,ny]=size(y);
if (nx~=1) | (ny~=1), error('x and y must be col vectors'),end
if (mx ~= my), error ('x and y must be same length'), end
if (mx/M < 4), disp ('You set number of lags to > 1/4 n of obs'),end
z=[x y];
zs=std(z) * sqrt((mx-1)/mx);
zs=zs(ones(mx,1),:);
z1=dtrend(z); % subtract col means
z2=z1./zs; % convert to z-scores
R=covf(z2,M+1); % crossproducts matrix of z-scores = correls