Home > reduc > calculateGains.m

calculateGains

PURPOSE ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function gain = calculateGains(d)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  function gain = calculateGains(d)

  calculates the gains loading noise diode temperature data from the
  measurements immediately prior and later. 

  sjcm

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function gain = calculateGains(d)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function gain = calculateGains(d)
0006 %
0007 %  calculates the gains loading noise diode temperature data from the
0008 %  measurements immediately prior and later.
0009 %
0010 %  sjcm
0011 %
0012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0013 
0014 k_b   = 1.38e-23;
0015  
0016 % first we see if there is any noise source data
0017 if(length(find(d.index.noise_event.fast))==0)
0018   display('calculateGains:: FAIL: no noise source in your data.');
0019   display('calculateGains:: Can not calibrate your data');
0020   gainVals = [];
0021   return;
0022 end
0023 
0024 if(~issubfield(d, 'correction', 'alpha', 'indices'))
0025   % find the start stop
0026   [offStartPos onEndPos offEndPos onStartPos] = calcNoiseIndices(d);
0027   d.correction.alpha.indices = [offStartPos onEndPos offEndPos ...
0028     onStartPos];
0029 end
0030 
0031 if(isempty(d.correction.alpha.indices))
0032   display('calculateGains:: FAIL: no noise source in your data.');
0033   display('calculateGains:: Can not calibrate your data');
0034   gainVals = [];
0035   return;
0036 end
0037 
0038 
0039 if(~isfield(d.correction.tsys, 'tnoise'))
0040   [time tnoise] = getNoiseTemps(d.array.frame.utc(1), ...
0041       d.array.frame.utc(end));  
0042 else
0043   time = d.correction.tsys.time;
0044   tnoise = d.correction.tsys.tnoise;
0045 end
0046 
0047 % next we get the off and on powers for each noise diode event
0048 indices = d.correction.alpha.indices;
0049 for m=1:size(indices,1)
0050   % sjcm:  2011, 03, 18:  need to modify this so that it uses the new
0051   % calculated indices.
0052  
0053 % Need to edit this in case we use Pol Only alpha corrections whihc end up
0054 % with only 8 columns in data
0055  
0056 
0057 switch(size(d.antenna0.receiver.data,2))
0058     case 10
0059       dataNoiseOn = d.antenna0.receiver.data((indices(m,4)+5):indices(m,2), ...
0060       [1 9]);
0061       dataNoiseOff= d.antenna0.receiver.data([indices(m,1):(indices(m,4)-5) ...
0062     (indices(m,2)+5):indices(m,3)], [1 9]);
0063     case 8
0064       dataNoiseOn = d.antenna0.receiver.data((indices(m,4)+5):indices(m,2), ...
0065       [1 8]);
0066       dataNoiseOff= d.antenna0.receiver.data([indices(m,1):(indices(m,4)-5) ...
0067     (indices(m,2)+5):indices(m,3)], [1 8]);
0068 end
0069   PnoiseOn  = mean(dataNoiseOn);
0070   PnoiseOff = mean(dataNoiseOff);
0071   Ptime     = mean(d.antenna0.receiver.utc(indices(m,1):indices(m,3)));
0072   
0073   gain.time(m,1) = Ptime;
0074   gain.power(m,:) = PnoiseOn - PnoiseOff;
0075 end
0076 
0077 out_of_range_flag=0;
0078 
0079 
0080 
0081 % if it is a survey, take a mean of the values.
0082 if(d.correction.survey)
0083   preVal = find(time<d.array.frame.utc(1));
0084   if(length(preVal)>1)
0085     tnoiseBin(1,:) = nanmean(tnoise(preVal,:));
0086     timeBin(1) = nanmean(time(preVal));
0087   elseif(length(preVal)==1)
0088     tnoiseBin(1,:) = tnoise(preVal,:);
0089     timeBin(1) = nanmean(time(preVal));
0090   elseif(length(preVal)==0)
0091     %if completely out of range, just average the whole lot
0092     gain.tnoise = nanmean(tnoise(:,:));
0093     gain.tnoise = nanmean(gain.tnoise);
0094     out_of_range_flag=1; 
0095   end
0096   
0097 
0098   
0099   postVal = find(time>d.array.frame.utc(1));
0100   if(length(postVal)>1)
0101     tnoiseBin(2,:) = nanmean(tnoise(postVal,:));
0102     timeBin(2) = nanmean(time(postVal));  
0103   elseif(length(postVal)==1)
0104     tnoiseBin(2,:) = tnoise(postVal,:);
0105     timeBin(2) = nanmean(time(postVal));  
0106   elseif(length(postVal)==0)
0107     %if completely out of range, just average the whole lot
0108     gain.tnoise = nanmean(tnoise(:,:));
0109     gain.tnoise = nanmean(gain.tnoise);
0110     out_of_range_flag=1; 
0111   end
0112  
0113   time = timeBin;
0114   tnoise = tnoiseBin;
0115 end
0116 
0117 % next we get the noise diode temperature at each of those points
0118 % N.B. for the out of range case, we have already set gain.tnoise,
0119 % so we just skip the step
0120 
0121 if( out_of_range_flag==0 )
0122   gain.tnoise = interp1(time, tnoise, gain.time);
0123   % element by element
0124   val = gain.power./(k_b*1e9*gain.tnoise);
0125  else
0126   % divide by 1-D scalar
0127   val = gain.power/(k_b*1e9*gain.tnoise);
0128 end
0129 
0130 % and now we calculate the gains
0131 val = gain.power./(k_b*1e9*gain.tnoise);
0132 gain.val = 10*log10(val);
0133 
0134 % and that's it.
0135 
0136 return;

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005