R-factor calculation MEJ 8/4/10
0001 function [rfactor] = r_calc(d) 0002 0003 % R-factor calculation MEJ 8/4/10 0004 0005 %Calculate and the r- and gain factors. The factors are 0006 % rfactor(:,1), (:,2) = ratio of gains for each pair of channels 0007 % rfactor(:,3), (:,4) = offsets to be subtracted from each pair of channels 0008 % rfactor(:,5) = raio of gains for difference, offset subtracted pair 0009 % So the correction then to be applied to channels 1-4 is: 0010 % data = ((r1*ch1) + ch2 - r3) + r5*((r2*ch3 + ch4 - r4) 0011 0012 for i = 1:6 %Looping over 6 channels ie I1, U1, Q1, U2, Q2, I2 0013 0014 for j = 1:4 %Looping over all four outputs per channel, get means and rms 0015 temp(:,j) = d.antenna0.receiver.switchData(~d.flags.rfiFlags,(4*(i-1)+j)); 0016 temptemp = detrend(temp(:,j)); 0017 rms(j) = std(temptemp); 0018 av(j) = mean(temp(:,j)); 0019 end 0020 0021 % gain factor from ratio of rms's 0022 rfactor(i,1) = rms(2)/rms(1); 0023 rfactor(i,2) = rms(4)/rms(3); 0024 0025 %offset from the averages 0026 rfactor(i,3) = (rfactor(i,1)*av(1))+av(2); 0027 rfactor(i,4) = (rfactor(i,2)*av(3))+av(4); 0028 %gain ratio for two pairs: 0029 0030 rfactor(i,5) = std((rfactor(i,1)*temp(:,1))+temp(:,2))/std((rfactor(i,2)*temp(:,3))+temp(:,4)); 0031 0032 end 0033 0034 0035 0036