-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenPRComp.m
64 lines (52 loc) · 1.79 KB
/
genPRComp.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
% Goal is to generate kind of random codes that
% have good cross correlation properties
clear
merit = 0;
meritThresh = 4;
numPairs = 5;
while(merit < meritThresh)
% Generate a few codes and see how they cross correlate
shiftList = 1:40;
pairs = [];
for i = 1:numPairs
pairs = [pairs ; genCompPair(shiftList)];
end
% Check complementarity
% complResult = areCompl(pairs(1:2,:))
% complResult = areCompl(pairs(3:4,:))
% Find minimum main lobe value
% This is the minimum main lobe value in the sum
% of the ACFs of each code set
numPairs = size(pairs,1)/2;
minMainLobe = -1;
for i = 1:numPairs
currPair = pairs((2*i-1):2*i,:);
currACF = xcorr(currPair(1,:)) + xcorr(currPair(2,:));
currMain = max(abs(currACF));
if (currMain < minMainLobe || minMainLobe == -1)
minMainLobe = currMain;
end
end
% Find the cross correlation sum values
% There will be one of these for each pair of codes
maxXcorr = -1;
pairChoices = nchoosek(1:numPairs,2);
for i = 1:size(pairChoices,1)
% We find the sum of pairwise cross correlations
% Ex. for pair A and pair B, we sum xcorr(A1,B1) + xcorr(A2,B2)
currChoices = pairChoices(i,:);
firstPair = pairs((2*currChoices(1)-1):2*currChoices(1),:);
secPair = pairs((2*currChoices(2)-1):2*currChoices(2),:);
currXcorr = xcorr(firstPair(1,:),secPair(1,:)) + xcorr(firstPair(2,:),secPair(2,:));
currMax = max(abs(currXcorr));
% Store the largest cross cross correlation value
if (currMax > maxXcorr || maxXcorr == -1)
maxXcorr = currMax;
end
end
merit = minMainLobe/maxXcorr;
if (merit > 3)
disp(merit);
end
end
len = size(pairs,2)