-
Notifications
You must be signed in to change notification settings - Fork 14
/
CalculateSpatiallySmoothedR.m
30 lines (29 loc) · 1.13 KB
/
CalculateSpatiallySmoothedR.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
function [R,Rpre,Rpre_i,buffill,dataset] = CalculateSpatiallySmoothedR(u,N_weight,num_sub_arr,Rpre,Rpre_i,buffill,dataset,SNAPSHOT_NO)
% Calculate the spatial correlation matrix
R = zeros(N_weight,N_weight);
for apo_m = 1:num_sub_arr
R = R + u(apo_m:apo_m+N_weight-1)*u(apo_m:apo_m+N_weight-1)';
end
R = R/num_sub_arr;
if SNAPSHOT_NO~=0
Rpre(:,:,Rpre_i) = R;
if Rpre_i == SNAPSHOT_NO
Rpre_i = 1; % reset the buffer pointer
buffill = 1; % buffer is full
dataset = SNAPSHOT_NO; % number of snapshots used to calculate correlation matrix
else
Rpre_i = Rpre_i + 1;
end
if buffill== 0
dataset = Rpre_i-1 ;
end
% Average the past SNAPSHOT_NO spatial smoothed correlation matrix
% SNAPSHOT_NO is max 2 or 3,
% otherwise this for loop averaging is not very efficient.
R = zeros(N_weight,N_weight);
for i = 1:dataset
R = R + Rpre(:,:,i);
end
R = R/dataset;
end
end