81 const Index& antenna_dim,
97 const Index n_ant = antenna_los.nrows();
100 assert( antenna_dim == 1 );
101 assert( antenna_los.ncols() == antenna_dim );
103 assert( n_pol >= 1 );
104 assert( do_norm >= 0 && do_norm <= 1 );
107 const Index n_ar_pol =
117 const Index n_ar_f = aresponse_f_grid.
nelem();
118 const Index n_ar_za = aresponse_za_grid.
nelem();
119 const Index pol_step = n_ar_pol > 1;
122 assert( n_ar_pol == 1 || n_ar_pol == n_pol );
124 assert( n_ar_za > 1 );
125 assert( n_ar_aa == 1 );
131 const Index nfpol = n_f * n_pol;
134 H.
resize( n_ant*nfpol, n_za*nfpol );
141 Vector aresponse( n_ar_za, 0.0 );
145 for(
Index ia=0; ia<n_ant; ia++ )
147 Vector shifted_aresponse_za_grid = aresponse_za_grid;
148 shifted_aresponse_za_grid += antenna_los(ia,0);
154 for(
Index f=0; f<n_f; f++ )
158 for(
Index ip=0; ip<n_pol; ip++ )
165 Index new_antenna = 1;
172 gridpos( gp_za, aresponse_za_grid, aresponse_za_grid );
175 Matrix aresponse_matrix(1,n_za);
176 interp( aresponse_matrix, itw,
178 aresponse = aresponse_matrix(0,
joker);
182 aresponse = antenna_response.
data(ip,0,
joker,0);
186 aresponse = antenna_response.
data(0,0,
joker,0);
197 shifted_aresponse_za_grid,
201 { hza /= hza.
sum(); }
206 const Index ii = f*n_pol + ip;
208 hrow[
Range(ii,n_za,nfpol) ] = hza;
249 const Index& antenna_dim,
259 const Index do_norm )
263 const Index nfpol = n_f * n_pol;
266 const Index n_ant = antenna_los.nrows();
272 assert( antenna_dim == 2 );
274 assert( do_norm >= 0 && do_norm <= 1 );
283 aresponse.
resize( n_ar_pol, n_ar_f, n_ar_za, 1 );
287 H.
resize( n_ant*nfpol, n_aa*n_za*nfpol );
290 for(
Index il=0; il<n_ant; il++ )
295 for(
Index row=0; row<nfpol; row++ )
297 hrows[row].resize(n_aa*n_za*nfpol);
302 for(
Index ia=0; ia<n_aa; ia++ )
304 const Numeric aa_point = aa_grid[ia] - antenna_los(il,1);
306 if( aa_point >= response_aa_grid[0] &&
307 aa_point <=
last(response_aa_grid) )
315 for(
Index i4=0; i4<n_ar_pol; i4++ )
317 for(
Index i3=0; i3<n_ar_f; i3++ )
319 for(
Index i2=0; i2<n_ar_za; i2++ )
321 aresponse.
data(i4,i3,i2,0) =
322 gp[0].fd[1] * antenna_response.
data(i4,i3,i2,gp[0].idx) +
323 gp[0].fd[0] * antenna_response.
data(i4,i3,i2,gp[0].idx+1);
331 Numeric aa_low = response_aa_grid[0];
334 const Numeric aam = antenna_los(il,1) +
335 ( aa_grid[ia] + aa_grid[ia-1] ) / 2.0;
342 const Numeric aam = antenna_los(il,1) +
343 ( aa_grid[ia+1] + aa_grid[ia] ) / 2.0;
348 const Numeric aa_width = aa_high - aa_low;
355 aresponse, za_grid, f_grid, n_pol, 0 );
357 for(
Index row=0; row<nfpol; row++ )
359 for(
Index iz=0; iz<n_za; iz++ )
361 for(
Index i=0; i<nfpol; i++ )
363 hrows[row][(iz*n_aa+ia)*nfpol+i] =
364 aa_width * Hza(row,iz*nfpol+i);
372 for(
Index row=0; row<nfpol; row++ )
376 hrows[row] /= hrows[row].sum();
417 const Numeric a = 1 / ( si * sqrt( 2 *
PI ) );
419 linspace( x, -si*xwidth_si, si*xwidth_si, si*dx_si );
423 for(
Index i=0; i<n; i++ )
424 y[i] = a * exp( -0.5 * pow((x[i]-x0)/si,2.0) );
463 const Index& do_norm )
471 assert( lo > f_grid[0] );
472 assert( lo <
last(f_grid) );
473 assert( filter_grid.
nelem() == nrp );
474 assert( fabs(
last(filter_grid)+filter_grid[0]) < 1e3 );
502 const Numeric lim_high = -filter_grid[0];
506 list<Numeric> l_mixer;
509 if( fabs(f_grid[i]-lo)>=lim_low && fabs(f_grid[i]-lo)<=lim_high )
511 l_mixer.push_back(fabs(f_grid[i]-lo));
514 l_mixer.push_back(lim_high);
519 for (list<Numeric>::iterator li=l_mixer.begin(); li != l_mixer.end(); li++)
540 if_grid, f_mixer[i], -f_mixer[i] );
544 row_temp /= row_temp.
sum();
547 for (
Index p=0; p<n_pol; p++)
550 for (
Index a=0; a<n_sp; a++)
587 Vector& sensor_response_f,
589 Vector& sensor_response_za,
590 Vector& sensor_response_aa,
595 const Index za_aa_independent )
598 const Index nf = sensor_response_f_grid.
nelem();
599 const Index npol = sensor_response_pol_grid.
nelem();
600 const Index nza = sensor_response_za_grid.
nelem();
609 if( !za_aa_independent )
612 const Index n = nf * npol * nza * naa;
615 sensor_response_f.
resize( n );
616 sensor_response_pol.resize( n );
617 sensor_response_za.
resize( n );
619 { sensor_response_aa.
resize( 0 ); }
621 { sensor_response_aa.
resize( n ); }
624 for(
Index iaa=0; iaa<naa; iaa++ )
626 const Index i1 = iaa * nza * nf * npol;
628 for(
Index iza=0; iza<nza; iza++ )
630 const Index i2 = i1 + iza * nf * npol;
632 for(
Index ifr=0; ifr<nf; ifr++ )
634 const Index i3 = i2 + ifr * npol;
636 for(
Index ip=0; ip<npol; ip++ )
638 const Index i = i3 + ip;
640 sensor_response_f[i] = sensor_response_f_grid[ifr];
641 sensor_response_pol[i] = sensor_response_pol_grid[ip];
642 sensor_response_za[i] = sensor_response_za_grid[iza];
645 if( za_aa_independent )
646 sensor_response_aa[i] = sensor_response_aa_grid[iaa];
648 sensor_response_aa[i] = sensor_response_aa_grid[iza];
694 assert( h.
nelem() == ng );
695 assert( f.
nelem() == nf );
707 Index xg_reversed = 0;
716 assert( x_g[0] <= x_f[0] );
717 assert( x_g[ng-1] >= x_f[nf-1] );
720 const Numeric xmax = x_g[ng-1];
731 for(
Index it=0; it<nf; it++ )
732 l_x.push_back(x_f[it]);
733 for (
Index it=0; it<ng; it++)
735 if( x_g[it]>x_f[0] && x_g[it]<x_f[x_f.
nelem()-1] )
736 l_x.push_back(x_g[it]);
744 for (list<Numeric>::iterator li=l_x.begin(); li != l_x.end(); li++) {
760 while( x_g[i_g+1] <= x_ref[i] ) {
763 while( x_f[i_f+1] <= x_ref[i] ) {
769 if( x_ref[i] >= x_f[0] && x_ref[i] < x_f[x_f.
nelem()-1] ) {
771 dx = (x_f[i_f+1] - x_f[i_f]) * (x_g[i_g+1] - x_g[i_g]);
774 a0 = (f[i_f] - f[i_f+1]) / 3;
775 b0 = (-f[i_f]*(x_g[i_g+1]+x_f[i_f+1])+f[i_f+1]*(x_g[i_g+1]+x_f[i_f]))
777 c0 = f[i_f]*x_f[i_f+1]*x_g[i_g+1]-f[i_f+1]*x_f[i_f]*x_g[i_g+1];
780 b1 = (f[i_f]*(x_g[i_g]+x_f[i_f+1])-f[i_f+1]*(x_g[i_g]+x_f[i_f]))/2;
781 c1 = -f[i_f]*x_f[i_f+1]*x_g[i_g]+f[i_f+1]*x_f[i_f]*x_g[i_g];
783 x3 = pow(x_ref[i+1],3) - pow(x_ref[i],3);
784 x2 = pow(x_ref[i+1],2) - pow(x_ref[i],2);
785 x1 = x_ref[i+1]-x_ref[i];
788 h[i_g] += (a0*x3+
b0*x2+c0*x1) /
dx;
789 h[i_g+1] += (a1*x3+b1*x2+c1*x1) /
dx;
842 assert( x_g[0] <= x_f[0] );
844 assert( x1 >= x_f[0] );
845 assert( x2 >= x_f[0] );
846 assert( x1 <=
last(x_f) );
847 assert( x2 <=
last(x_f) );
857 interp( f1, itw1, f, gp1f );
866 interp( f2, itw2, f, gp2f );
870 h[gp1g[0].idx] += f1 * gp1g[0].fd[1];
871 h[gp1g[0].idx+1] += f1 * gp1g[0].fd[0];
872 h[gp2g[0].idx] += f2 * gp2g[0].fd[1];
873 h[gp2g[0].idx+1] += f2 * gp2g[0].fd[0];
904 const Index& do_norm )
920 const Index nin = n_sp * nin_f * n_pol;
921 const Index nout = n_sp * nout_f * n_pol;
930 Vector weights_long( nin, 0.0 );
932 for(
Index ifr=0; ifr<nout_f; ifr++ )
934 const Index irp = ifr * freq_full;
937 ch_response_f = ch_response[irp].get_numeric_grid(
GFIELD1_F_GRID);
938 ch_response_f += ch_f[ifr];
942 ch_response_f, sensor_f );
946 weights /= weights.
sum();
950 for(
Index sp=0; sp<n_sp; sp++ )
952 for(
Index pol=0; pol<n_pol; pol++ )
955 weights_long[
Range(sp*nin_f*n_pol+pol,nin_f,n_pol)] = weights;
958 H.
insert_row( sp*nout_f*n_pol + ifr*n_pol + pol, weights_long );
1006 assert(fmax.
nelem()==nf);
1007 assert(i>=0 && i<nf);
1008 assert(j>=0 && j<nf);
1009 assert(fmin[i]<=fmin[j]);
1018 if (fmax[i] >= fmin[j])
1024 if (fmax[j] > fmax[i])
1030 Index n_behind = nf-1 - j;
1036 fmin[
Range(j,n_behind)] = dummy[
Range(j+1,n_behind)];
1042 fmax[
Range(j,n_behind)] = dummy[
Range(j+1,n_behind)];
1096 os <<
"There must be at least one channel.\n"
1097 <<
"(The vector *f_backend* must have at least one element.)";
1098 throw runtime_error(os.str());
1102 if (n_chan != backend_channel_response.
nelem())
1105 os <<
"Variables *f_backend_multi* and *backend_channel_response_multi*\n"
1106 <<
"must have same number of bands for each LO.";
1107 throw runtime_error(os.str());
1111 for (
Index i=0; i<n_chan; ++i)
1114 const Vector& backend_f_grid = backend_channel_response[i].get_numeric_grid(0);
1119 os <<
"The frequency grid for the backend channel response of\n"
1120 <<
"channel " << i <<
" is not strictly increasing.\n";
1121 os <<
"It is: " << backend_f_grid <<
"\n";
1122 throw runtime_error( os.str() );
1129 out2 <<
" Original channel characteristics:\n"
1130 <<
" min nominal max (all in Hz):\n";
1133 Vector fmin_orig(n_chan);
1134 Vector fmax_orig(n_chan);
1135 for (
Index i=0; i<n_chan; ++i)
1138 const Vector& backend_f_grid = backend_channel_response[i].get_numeric_grid(0);
1156 Numeric bf_min = backend_f_grid[0];
1157 Numeric bf_max = backend_f_grid[nf-1];
1174 fmin_orig[i] = f_backend[i] + bf_min - delta;
1175 fmax_orig[i] = f_backend[i] + bf_max + delta;
1177 out2 <<
" " << fmin_orig[i]
1178 <<
" " << f_backend[i]
1179 <<
" " << fmax_orig[i] <<
"\n";
1201 for (
Index i=0; i<n_chan; ++i)
1203 fmin[i] = fmin_orig[isorted[i]];
1204 fmax[i] = fmax_orig[isorted[i]];
1216 bool continue_checking =
true;
1220 while (continue_checking && i<fmin.
nelem()-1)
1231 out2 <<
" New channel characteristics:\n"
1232 <<
" min max (all in Hz):\n";
1234 out2 <<
" " << fmin[i] <<
" " << fmax[i] <<
"\n";