-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhelperGainCodes.m
40 lines (32 loc) · 1.21 KB
/
helperGainCodes.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
function calibGainCode = helperGainCodes(analogWeights)
% Get gain code for each subarray
% Copyright 2023 The MathWorks, Inc.
sub1weights = analogWeights(:,1);
sub2weights = analogWeights(:,2);
sub1gain = getGain(sub1weights);
sub2gain = getGain(sub2weights);
% Loading the measured gain profiles. These are captured using the
% script saveGainProfile.m.
load('GainProfile.mat','subArray1_NormalizedGainProfile','subArray2_NormalizedGainProfile','gaincode');
calibGainCode = zeros(1,8);
for nch = 1 : 4
xp = sub1gain(nch);
if xp == -Inf
calibGainCode(nch) = 0;
else
calibGainCode(nch) = round(interp1(subArray1_NormalizedGainProfile(:,nch),gaincode,xp));
end
xp = sub2gain(nch);
if xp == -Inf
calibGainCode(nch+4) = 0;
else
calibGainCode(nch+4) = round(interp1(subArray2_NormalizedGainProfile(:,nch),gaincode,xp));
end
end
% Make sure the values of the gain code is always <= 127
calibGainCode(calibGainCode>127 | isnan(calibGainCode)) = 127;
function gain = getGain(weights)
amp = abs(weights);
gain = mag2db(amp);
end
end