-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCUM3X.M
110 lines (88 loc) · 3.53 KB
/
CUM3X.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function y_cum = cum3x (x,y,z, maxlag, nsamp, overlap, flag, k1)
%CUM3X Third-order cross-cumulants.
% y_cum = cum3x (x,y,z,maxlag, samp_seg, overlap, flag, k1)
% x,y,z - data vectors/matrices with identical dimensions
% if x,y,z are matrices, rather than vectors, columns are
% assumed to correspond to independent realizations,
% overlap is set to 0, and samp_seg to the row dimension.
% maxlag - maximum lag to be computed [default = 0]
% samp_seg - samples per segment [default = data_length]
% overlap - percentage overlap of segments [default = 0]
% overlap is clipped to the allowed range of [0,99].
% flag : 'biased', biased estimates are computed [default]
% 'unbiased', unbiased estimates are computed.
% k1: the fixed lag in c3(m,k1): defaults to 0
% y_cum: estimated third-order cross cumulant,
% E x^*(n)y(n+m)z(n+k1), -maxlag <= m <= maxlag
% Copyright (c) 1991-2001 by United Signals & Systems, Inc.
% $Revision: 1.4 $
% A. Swami January 20, 1995
% RESTRICTED RIGHTS LEGEND
% Use, duplication, or disclosure by the Government is subject to
% restrictions as set forth in subparagraph (c) (1) (ii) of the
% Rights in Technical Data and Computer Software clause of DFARS
% 252.227-7013.
% Manufacturer: United Signals & Systems, Inc., P.O. Box 2374,
% Culver City, California 90231.
%
% This material may be reproduced by or for the U.S. Government pursuant
% to the copyright license under the clause at DFARS 252.227-7013.
%---------------- Parameter checks ---------------------------
[lx, nrecs] = size(x);
if ( [lx,nrecs] ~= size(y) || [lx, nrecs] ~= size(z))
error('x,y,z should have identical dimensions')
end
if (lx == 1)
lx = nrecs; nrecs = 1;
end
if (exist('maxlag') ~= 1) maxlag = 0; end
if (maxlag < 0)
error ('"maxlag" must be non-negative ')
end
if (exist('nsamp') ~= 1) nsamp = lx; end
if (nrecs > 1) nsamp = lx; end
if (nsamp <= 0 || nsamp > lx) nsamp = lx; end
if (exist('overlap') ~= 1) overlap = 0; end
if (nrecs > 1) overlap = 0; end
overlap = max(0,min(overlap,99));
if (exist('flag') ~= 1) flag = 'biased' ; end
if (flag(1:1) ~= 'b' && flag(1:1) ~= 'B')
flag = 'unbiased';
else, flag = 'biased';
end
overlap = fix(overlap/100 * nsamp);
nadvance = nsamp - overlap;
if (nrecs == 1)
nrecs = fix( (lx - overlap)/nadvance ) ;
end
if (exist('k1') ~= 1) k1 = 0; end
nlags = 2*maxlag+1;
zlag = maxlag + 1;
y_cum = zeros(nlags,1);
if (flag(1) == 'b' || flag(1) == 'B')
scale = ones(nlags,1)/nsamp;
else
lsamp = lx - abs(k1);
scale = [lsamp-maxlag:lsamp,lsamp-1:-1:lsamp-maxlag]';
scale = ones(2*maxlag+1,1) ./ scale;
end
% ----------------------------------------------------------
if (k1 >= 0) indx = (1:nsamp-k1)'; indz = (k1+1:nsamp)';
else indx = (-k1+1:nsamp)'; indz = (1:nsamp+k1)';
end
ind = 1:nsamp;
for k=1:nrecs
xs = x(ind); xs = xs(:) - mean(xs);
ys = y(ind); ys = ys(:) - mean(ys);
zs = z(ind); zs = zs(:) - mean(zs); zs = conj(zs);
u = zeros(nsamp,1);
u(indx) = xs(indx) .* zs(indz);
y_cum(zlag) = y_cum(zlag) + u' * ys;
for m = 1:maxlag
y_cum(zlag-m) = y_cum(zlag-m) + u([m+1:nsamp])' * ys([1:nsamp-m]) ;
y_cum(zlag+m) = y_cum(zlag+m) + u([1:nsamp-m])' * ys([m+1:nsamp]);
end
ind = ind + nadvance;
end
y_cum = y_cum .* scale / nrecs;
return