SDR_al/Matlab/helperGainCodes.m

37 lines
1.1 KiB
Matlab
Raw Normal View History

2023-07-24 15:14:00 +00:00
function calibGainCode = helperGainCodes(analogWeights)
% get gain for each subarray
sub1weights = analogWeights(:,1);
sub2weights = analogWeights(:,2);
sub1gain = getGain(sub1weights);
sub2gain = getGain(sub2weights);
% Loading the measured gain profiles
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