0001 function [flags,slopeLoad,slopeSky,interceptDiffSky] = flagAlpha(d, flagParams)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if size(d.correction.alpha.indices,2) == 4
0024
0025 si = d.correction.alpha.indices(:,1);
0026 ei = d.correction.alpha.indices(:,2);
0027 esi = d.correction.alpha.indices(:,4);
0028 else
0029
0030 si = d.correction.alpha.indices(:,1);
0031 ei = d.correction.alpha.indices(:,3);
0032 esi = d.correction.alpha.indices(:,6);
0033 end
0034
0035 numEvents = size(d.correction.alpha.indices,1);
0036
0037 maxInterceptDiff = flagParams(1);
0038 minInterceptDiff = flagParams(2);
0039 maxSlope = flagParams(3);
0040
0041
0042 for m=1:numEvents
0043 x{1,m} = d.antenna0.receiver.data(si(m):ei(m),[1,2]);
0044 x{2,m} = d.antenna0.receiver.data(si(m):ei(m),[9,10]);
0045 end
0046
0047
0048
0049
0050
0051
0052
0053 for m=1:numEvents
0054 thisX = [1:1:size(x{1,m},1)]';
0055 thisY = x{1,m}(:,2);
0056 thisX = thisX/100;
0057
0058
0059 [slopeVal(m,1), interceptVal(m,1)] = linfit(thisX, thisY);
0060
0061
0062 thisY = x{2,m}(:,2);
0063 [slopeVal(m,2), interceptVal(m,2)] = linfit(thisX, thisY);
0064 end
0065
0066 slopeVal = abs(slopeVal);
0067 slopeLoad = slopeVal;
0068 badSlope1 = slopeVal>maxSlope;
0069 badSlope1 = sum(badSlope1,2)>0;
0070
0071
0072
0073
0074
0075 clear slopeVal;
0076 clear interceptVal;
0077 for m=1:numEvents
0078 for nchan=1:2
0079 numSamples = size(x{nchan,m},1);
0080 midSample = esi(m)-si(m);
0081 slack = 50;
0082
0083 thisX1 = [1:(midSample-slack)]';
0084 thisY1 = x{nchan,m}(thisX1,1);
0085 thisX1 = thisX1/100;
0086
0087 thisX2 = [midSample+slack:numSamples]';
0088 thisY2 = x{nchan,m}(thisX2,1);
0089 thisX2 = thisX2/100;
0090
0091 [slopeA intA] = linfit(thisX1, thisY1);
0092 [slopeB intB] = linfit(thisX2, thisY2);
0093
0094 thisSlope = [slopeA slopeB];
0095 thisInt = [intA intB];
0096
0097 slopeVal(m,nchan,:) = thisSlope;
0098 interceptVal(m,nchan,:) = thisInt;
0099 end
0100 end
0101
0102
0103 slopeVal = abs(slopeVal);
0104 slopeSky = slopeVal;
0105 badSlope2 = slopeVal>maxSlope;
0106 badSlope2 = sum(sum(badSlope2,3),2)>0;
0107
0108
0109 interceptDiff = interceptVal(:,:,1) - interceptVal(:,:,2);
0110 interceptDiff = abs(interceptDiff);
0111 interceptDiffSky = interceptDiff;
0112 badIntercept = sum(sum(interceptDiff>maxInterceptDiff | ...
0113 interceptDiff<minInterceptDiff,3),2)>0;
0114
0115
0116 badEvents = badSlope1 | badSlope2 | badIntercept;
0117
0118 flags = badEvents;
0119
0120 return;
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139