0001 function sidelobes_cw(d)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 [d_noise, d_off, indNoise] = cutNoise(d);
0015 indSource = bitsearch(d.array.frame.features, 0, 'only');
0016 indSource = interp1(d.array.frame.utc, indSource, d.antenna0.receiver.utc, 'closest');
0017 indSource = indSource & ~indNoise;
0018 indSource(isnan(indSource)) = 0;
0019
0020
0021
0022 data = d.antenna0.receiver.data(:,1);
0023 elevation = d.antenna0.servo.el;
0024 azimuth = d.antenna0.servo.az;
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 f = find(d.antenna0.servo.az<150 & d.antenna0.servo.el <18);
0043 a = d.antenna0.receiver.data(f(1):f(1)+10000,1);
0044
0045 da = diff(a);
0046 fa = find(abs(da)>30);
0047 dfa = diff(fa);
0048 fa(dfa>100 | dfa<30) = [];
0049 dfa(dfa>100) = [];
0050 dfa(dfa<30) = [];
0051 switch1 = mode(dfa);
0052 ff = find(dfa==switch1);
0053 if(mean(da(fa(ff)))>0)
0054
0055
0056 off_time = floor(switch1/2)-5;
0057 offPeriod = switch1;
0058 else
0059 on_time = floor(switch1/2)-5;
0060 onPeriod = switch1;
0061 end
0062
0063 fa(dfa==mode(dfa)) = [];
0064 dfa(dfa==mode(dfa)) = [];
0065 switch2 = mode(dfa);
0066 ff = find(dfa==switch2);
0067 if(mean(da(fa(ff)))>0)
0068
0069
0070 off_time = floor(switch2/2)-5;
0071 offPeriod = switch2;
0072 else
0073 on_time = floor(switch2/2)-5;
0074 onPeriod = switch2;
0075 end
0076
0077 switchFreq = 100./(switch1 + switch2+1);
0078
0079
0080
0081
0082
0083
0084
0085 switchPeriod = round(100/switchFreq);
0086 singleSquare = ones(switchPeriod,1);
0087 singleSquare(1:offPeriod) = -1;
0088 numDataPoints = size(d.antenna0.receiver.data,1);
0089 totSquares = ceil(numDataPoints/switchPeriod)+1;
0090
0091 onMidIndex = round(offPeriod + onPeriod/2);
0092
0093 dataVals = abs(d.antenna0.receiver.data);
0094
0095 sumVal = zeros(switchPeriod,6);
0096 for phase=0:switchPeriod-1
0097
0098 squareWave = repmat(singleSquare, [totSquares,1]);
0099 if(phase==0)
0100 squareWave = squareWave(1:numDataPoints);
0101 else
0102 squareWave(1:phase) = [];
0103 squareWave = squareWave(1:numDataPoints);
0104 end
0105 toSum = repmat(squareWave, [1 6]).*dataVals;
0106 sumVal(phase+1,:) = nansum(toSum);
0107 end
0108 switchPhase(1) = find(sumVal(:,1)==min(sumVal(:,1)));
0109 switchPhase(2) = find(sumVal(:,6)==min(sumVal(:,6)));
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 fullPeriod = onPeriod + offPeriod+1;
0124 n_meas = floor(length(data) / fullPeriod);
0125
0126
0127
0128
0129
0130
0131
0132
0133 x_on = round(mean(switchPhase)):fullPeriod:length(data);
0134 x_off = round(mean(switchPhase))- fullPeriod/2:fullPeriod:length(data);
0135 x_off(x_off<0) = [];
0136
0137
0138 diff_array = zeros(n_meas-2,1);
0139 elevation_array = zeros(n_meas-2,1);
0140 azimuth_array = zeros(n_meas-2,1);
0141 on_source = zeros(n_meas-2,1);
0142
0143
0144 on_time = on_time-5;
0145 off_time = off_time-5;
0146 for i=1:n_meas-2
0147
0148 on_mean = mean(data((x_on(i+1)-on_time):(x_on(i+1)+on_time)));
0149 off_mean_1 = mean(data(x_off(i):x_off(i)+off_time));
0150 off_mean_2 = mean(data(x_off(i+1)-off_time:x_off(i+1)));
0151
0152
0153
0154
0155
0156 difference = -(on_mean - 0.5*off_mean_1 - 0.5*off_mean_2);
0157
0158 if(difference < -10)
0159 display('problem');
0160 keyboard;
0161 end
0162
0163
0164 diff_array(i) = difference;
0165
0166
0167 elevation_array(i) = mean(elevation(x_on(i+1)-on_time:x_on(i+1)+on_time));
0168 azimuth_array(i) = mean(azimuth(x_on(i+1)-on_time:x_on(i+1)+on_time));
0169
0170 on_source(i) = mean(indSource(x_on(i+1)-on_time:x_on(i+1)+on_time))>0.8;
0171 end
0172
0173 keyboard;
0174 on_source = on_source > 0;
0175 f = find(azimuth_array > 180);
0176 elevation_array(f) = 180 - elevation_array(f);
0177
0178 plot(elevation_array(on_source), diff_array(on_source));
0179 xlabel('Elevation angle from horizon');
0180 ylabel('Backend Units');
0181
0182