/* -*- c++ -*- */ /* * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module * * Copyright (C) 2016, Libre Space Foundation * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include namespace gr { namespace satnogs { /** * Creates a polynomial fitting routine. * @param degree the degree of the polynomial */ doppler_fit::doppler_fit (size_t degree) : d_degree(degree) { } doppler_fit::~doppler_fit () { } void doppler_fit::fit (std::deque drifts) { size_t i; size_t j; size_t s; size_t singular; double val; s = drifts.size(); boost::numeric::ublas::matrix x_matrix(s, d_degree+1); boost::numeric::ublas::matrix y_matrix(s, 1); for(i = 0; i < s; i++){ y_matrix(i, 0) = drifts[i].get_freq_drift(); } for(i = 0; i < s; i++){ val = 1.0; for(j = 0; j < d_degree + 1; j++) { x_matrix(i, j) = val; val *= drifts[i].get_x(); } } /* Transpose the matrix with the x values */ boost::numeric::ublas::matrix tx_matrix ( boost::numeric::ublas::trans (x_matrix)); boost::numeric::ublas::matrix txx_matrix ( boost::numeric::ublas::prec_prod(tx_matrix, x_matrix)); boost::numeric::ublas::matrix txy_matrix ( boost::numeric::ublas::prec_prod(tx_matrix, y_matrix)); boost::numeric::ublas::permutation_matrix perm(txx_matrix.size1()); singular = boost::numeric::ublas::lu_factorize(txx_matrix, perm); BOOST_ASSERT( singular == 0 ); boost::numeric::ublas::lu_substitute(txx_matrix, perm, txy_matrix); d_coeff = std::vector (txy_matrix.data().begin(), txy_matrix.data().end()); } } /* namespace satnogs */ } /* namespace gr */