Пример #1
0
static double gain_interp(double gain, boost::array<double, 17> db_vector, boost::array<double, 17> volts_vector) {
    double volts;
    gain = uhd::clip<double>(gain, db_vector.front(), db_vector.back()); //let's not get carried away here

    boost::uint8_t gain_step = 0;
    //find which bin we're in
    for(size_t i = 0; i < db_vector.size()-1; i++) {
        if(gain >= db_vector[i] && gain <= db_vector[i+1]) gain_step = i;
    }

    //find the current slope for linear interpolation
    double slope = (volts_vector[gain_step + 1] - volts_vector[gain_step])
                / (db_vector[gain_step + 1] - db_vector[gain_step]);

    //the problem here is that for gains approaching the maximum, the voltage slope becomes infinite
    //i.e., a small change in gain requires an infinite change in voltage
    //to cope, we limit the slope

    if(slope == std::numeric_limits<double>::infinity())
        return volts_vector[gain_step];

    //use the volts per dB slope to find the final interpolated voltage
    volts = volts_vector[gain_step] + (slope * (gain - db_vector[gain_step]));

    UHD_LOGV(often) << "Gain interp: gain: " << gain << ", gain_step: " << int(gain_step) << ", slope: " << slope << ", volts: " << volts << std::endl;

    return volts;
}
Пример #2
0
BOOST_AUTO_TEST_CASE_TEMPLATE(test_leading_coefficient, T, all_test_types)
{
    polynomial<T> const zero;
    BOOST_CHECK_EQUAL(leading_coefficient(zero), T(0));
    polynomial<T> a(d0a.begin(), d0a.end());
    BOOST_CHECK_EQUAL(leading_coefficient(a), T(d0a.back()));
}
Пример #3
0
static uhd::dict<std::string, gain_range_t> get_tvrx_gain_ranges(void) {
    double rfmax = 0.0, rfmin = FLT_MAX;
    BOOST_FOREACH(const std::string range, tvrx_rf_gains_db.keys()) {
        double my_max = tvrx_rf_gains_db[range].back(); //we're assuming it's monotonic
        double my_min = tvrx_rf_gains_db[range].front(); //if it's not this is wrong wrong wrong
        if(my_max > rfmax) rfmax = my_max;
        if(my_min < rfmin) rfmin = my_min;
    }

    double ifmin = tvrx_if_gains_db.front();
    double ifmax = tvrx_if_gains_db.back();

    return map_list_of
        ("RF", gain_range_t(rfmin, rfmax, (rfmax-rfmin)/4096.0))
        ("IF", gain_range_t(ifmin, ifmax, (ifmax-ifmin)/4096.0))
    ;
}
Пример #4
0
/** @brief Set the dimensions of the image, allocate memory, etc.
	\param dims Sizes of each non trival dimension (min=1, max=3), supposed in row major order.
	n[0] varies slower than n[1], itself variing slower that n[3]
	For a 3D image scanned with x faster than y faster than z, the dimensions must be given in reverse order
	n[0]=dimz, n[1]=dimy, n[2]=dimx
*/
void Tracker::setDimensions(const boost::array<size_t,3> &dims)
{
	//allocate main memory block for FFT.
	// Last dimension has to be padded with extra values to allow real2complex and c2r fft
	boost::array<size_t,3> paddedDims = dims;
	paddedDims.back()= 2*(paddedDims.back()/2+1);
	size_t memsize = 1;
	memsize = accumulate(paddedDims.begin(),paddedDims.end(),1,multiplies<size_t>());
	cout<<"Allocating a block of "<<sizeof(float) * memsize<<" bytes ... ";
	data = (float*)fftwf_malloc(sizeof(float)* memsize);
	assert(data);

	//allocate memory.
	centersMap.resize(dims);
	paddedDims.back() = dims.back()/2 + 1;
	FFTmask.resize(paddedDims);

	//planning fft.
	int n[3];
	copy(dims.begin(),dims.end(),&(n[0]));
	forward_plan = fftwf_plan_dft_r2c(dims.size(), &(n[0]), data, (fftwf_complex *)data, flags);
	//n[2] = 2*(n[2]/2 +1);
	backward_plan = fftwf_plan_dft_c2r(dims.size(), &(n[0]), (fftwf_complex *)data, data, flags);
}
Пример #5
0
		explicit Center(const Center<D-1> &c, const double &additional_coord): Center_base(c.r, c.intensity)
		{
			std::copy(c.coords.begin(), c.coords.end(), coords.begin());
			coords.back() = additional_coord;
		};