1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-06-11 19:14:09 +00:00

Code cleaning, comments, code style fixes

git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@251 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
Carles Fernandez 2012-10-19 16:00:40 +00:00
parent c241b7b1d6
commit 323e8e6765
2 changed files with 153 additions and 166 deletions

View File

@ -6,11 +6,9 @@
* <li> Luis Esteve, 2012. luis(at)epsilon-formacion.com * <li> Luis Esteve, 2012. luis(at)epsilon-formacion.com
* </ul> * </ul>
* *
* Detailed description of the file here if needed.
*
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
* *
* Copyright (C) 2010-2011 (see AUTHORS file for a list of contributors) * Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
* *
* GNSS-SDR is a software defined Global Navigation * GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver * Satellite Systems receiver
@ -55,13 +53,15 @@ pcps_acquisition_cc_sptr pcps_make_acquisition_cc(
fs_in, samples_per_ms, queue, dump, dump_filename)); fs_in, samples_per_ms, queue, dump, dump_filename));
} }
pcps_acquisition_cc::pcps_acquisition_cc( pcps_acquisition_cc::pcps_acquisition_cc(
unsigned int sampled_ms, unsigned int doppler_max, long freq, unsigned int sampled_ms, unsigned int doppler_max, long freq,
long fs_in, int samples_per_ms, gr_msg_queue_sptr queue, bool dump, long fs_in, int samples_per_ms, gr_msg_queue_sptr queue, bool dump,
std::string dump_filename) : std::string dump_filename) :
gr_block("pcps_acquisition_cc", gr_make_io_signature(1, 1, gr_block("pcps_acquisition_cc",
sizeof(gr_complex) * sampled_ms *samples_per_ms), gr_make_io_signature(0, 0, gr_make_io_signature(1, 1, sizeof(gr_complex) * sampled_ms * samples_per_ms),
sizeof(gr_complex) * sampled_ms *samples_per_ms)) gr_make_io_signature(0, 0, sizeof(gr_complex) * sampled_ms * samples_per_ms))
{ {
d_sample_counter = 0; // SAMPLE COUNTER d_sample_counter = 0; // SAMPLE COUNTER
d_active = false; d_active = false;
@ -85,39 +85,39 @@ pcps_acquisition_cc::pcps_acquisition_cc(
// Inverse FFT // Inverse FFT
d_ifft = new gri_fft_complex(d_fft_size, false); d_ifft = new gri_fft_complex(d_fft_size, false);
// For dumping samples into a file
d_dump = dump; d_dump = dump;
d_dump_filename = dump_filename; d_dump_filename = dump_filename;
} }
pcps_acquisition_cc::~pcps_acquisition_cc() pcps_acquisition_cc::~pcps_acquisition_cc()
{ {
free(d_carrier); free(d_carrier);
free(d_fft_codes); free(d_fft_codes);
delete d_ifft; delete d_ifft;
delete d_fft_if; delete d_fft_if;
if (d_dump) if (d_dump)
{ {
d_dump_file.close(); d_dump_file.close();
} }
} }
void pcps_acquisition_cc::set_local_code(std::complex<float> * code) void pcps_acquisition_cc::set_local_code(std::complex<float> * code)
{ {
memcpy(d_fft_if->get_inbuf(),code,sizeof(gr_complex)*d_fft_size); memcpy(d_fft_if->get_inbuf(),code,sizeof(gr_complex)*d_fft_size);
} }
void pcps_acquisition_cc::init() void pcps_acquisition_cc::init()
{ {
d_gnss_synchro->Acq_delay_samples = 0.0;
d_gnss_synchro->Acq_delay_samples=0.0; d_gnss_synchro->Acq_doppler_hz = 0.0;
d_gnss_synchro->Acq_doppler_hz=0.0; d_gnss_synchro->Acq_samplestamp_samples = 0;
d_gnss_synchro->Acq_samplestamp_samples=0;
d_mag = 0.0; d_mag = 0.0;
d_input_power = 0.0; d_input_power = 0.0;
@ -128,7 +128,6 @@ void pcps_acquisition_cc::init()
{ {
d_fft_codes[i] = std::complex<float>(conj(d_fft_if->get_outbuf()[i])); d_fft_codes[i] = std::complex<float>(conj(d_fft_if->get_outbuf()[i]));
} }
} }
@ -137,7 +136,6 @@ int pcps_acquisition_cc::general_work(int noutput_items,
gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items) gr_vector_void_star &output_items)
{ {
/* /*
* By J.Arribas and L.Esteve * By J.Arribas and L.Esteve
* Acquisition strategy (Kay Borre book + CFAR threshold): * Acquisition strategy (Kay Borre book + CFAR threshold):
@ -156,29 +154,26 @@ int pcps_acquisition_cc::general_work(int noutput_items,
} }
else else
{ {
d_sample_counter += d_fft_size; // sample counter
//restart acquisition variables
d_gnss_synchro->Acq_delay_samples=0.0;
d_gnss_synchro->Acq_doppler_hz=0.0;
d_mag = 0.0;
d_input_power = 0.0;
// initialize acquisition algorithm // initialize acquisition algorithm
int doppler; int doppler;
unsigned int indext = 0; unsigned int indext = 0;
float magt = 0.0; float magt = 0.0;
float tmp_magt = 0.0; float tmp_magt = 0.0;
const gr_complex *in = (const gr_complex *)input_items[0]; //Get the input samples pointer const gr_complex *in = (const gr_complex *)input_items[0]; //Get the input samples pointer
bool positive_acquisition = false; bool positive_acquisition = false;
int acquisition_message = -1; //0=STOP_CHANNEL 1=ACQ_SUCCEES 2=ACQ_FAIL int acquisition_message = -1; //0=STOP_CHANNEL 1=ACQ_SUCCEES 2=ACQ_FAIL
//aux vars //aux vars
unsigned int i; unsigned int i;
float fft_normalization_factor; float fft_normalization_factor;
d_sample_counter += d_fft_size; // sample counter
//restart acquisition variables
d_gnss_synchro->Acq_delay_samples = 0.0;
d_gnss_synchro->Acq_doppler_hz = 0.0;
d_mag = 0.0;
d_input_power = 0.0;
DLOG(INFO) << "Channel: " << d_channel DLOG(INFO) << "Channel: " << d_channel
<< " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN << " , doing acquisition of satellite: " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN
<< " ,sample stamp: " << d_sample_counter << ", threshold: " << " ,sample stamp: " << d_sample_counter << ", threshold: "
@ -190,37 +185,39 @@ int pcps_acquisition_cc::general_work(int noutput_items,
{ {
d_input_power += std::norm(in[i]); d_input_power += std::norm(in[i]);
} }
d_input_power = d_input_power / (float)d_fft_size; d_input_power = d_input_power / (float)d_fft_size;
// 2- Doppler frequency search loop // 2- Doppler frequency search loop
for (doppler = (int)(-d_doppler_max); doppler < (int)d_doppler_max; doppler += d_doppler_step) for (doppler = (int)(-d_doppler_max); doppler < (int)d_doppler_max; doppler += d_doppler_step)
{ {
//doppler search steps // doppler search steps
//Perform the carrier wipe-off // Perform the carrier wipe-off
complex_exp_gen_conj(d_carrier, d_freq + doppler, d_fs_in, d_fft_size); complex_exp_gen_conj(d_carrier, d_freq + doppler, d_fs_in, d_fft_size);
if (is_unaligned()==true) if (is_unaligned()==true)
{ {
volk_32fc_x2_multiply_32fc_u(d_fft_if->get_inbuf(), in, d_carrier, d_fft_size); volk_32fc_x2_multiply_32fc_u(d_fft_if->get_inbuf(), in, d_carrier, d_fft_size);
}else{ }
//use directly the input vector else
volk_32fc_x2_multiply_32fc_a(d_fft_if->get_inbuf(), in, d_carrier, d_fft_size); {
} //use directly the input vector
volk_32fc_x2_multiply_32fc_a(d_fft_if->get_inbuf(), in, d_carrier, d_fft_size);
}
//3- Perform the FFT-based circular convolution (parallel time search) // 3- Perform the FFT-based convolution (parallel time search)
// Compute the FFT of the carrier wiped--off incoming signal
d_fft_if->execute(); d_fft_if->execute();
// Using SIMD operations with VOLK library // Multiply carrier wiped--off, Fourier transformed incoming signal
// with the local FFT'd code reference using SIMD operations with VOLK library
volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), d_fft_if->get_outbuf(), d_fft_codes, d_fft_size); volk_32fc_x2_multiply_32fc_a(d_ifft->get_inbuf(), d_fft_if->get_outbuf(), d_fft_codes, d_fft_size);
// compute the inverse FFT
d_ifft->execute(); d_ifft->execute();
// Search maximum // Search maximum
indext = 0; indext = 0;
magt = 0; magt = 0;
fft_normalization_factor=(float)d_fft_size*(float)d_fft_size; fft_normalization_factor = (float)d_fft_size * (float)d_fft_size;
for (i = 0; i < d_fft_size; i++) for (i = 0; i < d_fft_size; i++)
{ {
tmp_magt = std::norm(d_ifft->get_outbuf()[i]); tmp_magt = std::norm(d_ifft->get_outbuf()[i]);
@ -230,44 +227,43 @@ int pcps_acquisition_cc::general_work(int noutput_items,
indext = i; indext = i;
} }
} }
// Normalize the maximum value to correct the scale factor introduced by FFTW // Normalize the maximum value to correct the scale factor introduced by FFTW
magt=magt/(fft_normalization_factor*fft_normalization_factor); magt = magt / (fft_normalization_factor * fft_normalization_factor);
// Record results to files
if (d_dump)
{
std::stringstream filename;
std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write
filename.str("");
filename << "../data/test_statistics_"<<d_gnss_synchro->System<<"_"<<d_gnss_synchro->Signal<<"_sat_" << d_gnss_synchro->PRN << "_doppler_"<< doppler << ".dat";
d_dump_file.open(filename.str().c_str(), std::ios::out
| std::ios::binary);
d_dump_file.write((char*)d_ifft->get_outbuf(), n); //write directly |abs(x)|^2 in this Doppler bin?
d_dump_file.close();
}
// 4- record the maximum peak and the associated synchronization parameters // 4- record the maximum peak and the associated synchronization parameters
if (d_mag < magt) if (d_mag < magt)
{ {
d_mag = magt; d_mag = magt;
d_gnss_synchro->Acq_delay_samples= (double)indext; d_gnss_synchro->Acq_delay_samples = (double)indext;
d_gnss_synchro->Acq_doppler_hz= (double)doppler; d_gnss_synchro->Acq_doppler_hz = (double)doppler;
}
// Record results to file if required
if (d_dump)
{
std::stringstream filename;
std::streamsize n = 2 * sizeof(float) * (d_fft_size); // complex file write
filename.str("");
filename << "../data/test_statistics_" << d_gnss_synchro->System
<<"_" << d_gnss_synchro->Signal << "_sat_"
<< d_gnss_synchro->PRN << "_doppler_" << doppler << ".dat";
d_dump_file.open(filename.str().c_str(), std::ios::out
| std::ios::binary);
d_dump_file.write((char*)d_ifft->get_outbuf(), n); //write directly |abs(x)|^2 in this Doppler bin?
d_dump_file.close();
} }
} }
// 5- Compute the test statistics and compare to the threshold // 5- Compute the test statistics and compare to the threshold
d_test_statistics = 2 * d_fft_size * d_mag / d_input_power; d_test_statistics = 2 * d_fft_size * d_mag / d_input_power;
// 6- Declare positive or negative acquisition using a message queue // 6- Declare positive or negative acquisition using a message queue
if (d_test_statistics > d_threshold) if (d_test_statistics > d_threshold)
{ {
positive_acquisition = true; positive_acquisition = true;
d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter; d_gnss_synchro->Acq_samplestamp_samples = d_sample_counter;
DLOG(INFO) << "positive acquisition"; DLOG(INFO) << "positive acquisition";
DLOG(INFO) << "satellite " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN; DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN;
DLOG(INFO) << "sample_stamp " << d_sample_counter; DLOG(INFO) << "sample_stamp " << d_sample_counter;
DLOG(INFO) << "test statistics value " << d_test_statistics; DLOG(INFO) << "test statistics value " << d_test_statistics;
DLOG(INFO) << "test statistics threshold " << d_threshold; DLOG(INFO) << "test statistics threshold " << d_threshold;
@ -279,7 +275,7 @@ int pcps_acquisition_cc::general_work(int noutput_items,
else else
{ {
DLOG(INFO) << "negative acquisition"; DLOG(INFO) << "negative acquisition";
DLOG(INFO) << "satellite " << d_gnss_synchro->System << " "<< d_gnss_synchro->PRN; DLOG(INFO) << "satellite " << d_gnss_synchro->System << " " << d_gnss_synchro->PRN;
DLOG(INFO) << "sample_stamp " << d_sample_counter; DLOG(INFO) << "sample_stamp " << d_sample_counter;
DLOG(INFO) << "test statistics value " << d_test_statistics; DLOG(INFO) << "test statistics value " << d_test_statistics;
DLOG(INFO) << "test statistics threshold " << d_threshold; DLOG(INFO) << "test statistics threshold " << d_threshold;
@ -299,9 +295,7 @@ int pcps_acquisition_cc::general_work(int noutput_items,
{ {
acquisition_message = 2; acquisition_message = 2;
} }
d_channel_internal_queue->push(acquisition_message); d_channel_internal_queue->push(acquisition_message);
consume_each(1); consume_each(1);
} }
return 0; return 0;

View File

@ -46,8 +46,8 @@
* ------------------------------------------------------------------------- * -------------------------------------------------------------------------
*/ */
#ifndef PCPS_ACQUISITION_CC_H_ #ifndef GNSS_SDR_PCPS_ACQUISITION_CC_H_
#define PCPS_ACQUISITION_CC_H_ #define GNSS_SDR_PCPS_ACQUISITION_CC_H_
#include <fstream> #include <fstream>
#include <gnuradio/gr_block.h> #include <gnuradio/gr_block.h>
@ -62,154 +62,147 @@
class pcps_acquisition_cc; class pcps_acquisition_cc;
typedef boost::shared_ptr<pcps_acquisition_cc> typedef boost::shared_ptr<pcps_acquisition_cc>
pcps_acquisition_cc_sptr; pcps_acquisition_cc_sptr;
pcps_acquisition_cc_sptr pcps_acquisition_cc_sptr
pcps_make_acquisition_cc(unsigned int sampled_ms, pcps_make_acquisition_cc(unsigned int sampled_ms,
unsigned int doppler_max, long freq, long fs_in, int samples_per_ms, unsigned int doppler_max, long freq, long fs_in, int samples_per_ms,
gr_msg_queue_sptr queue, bool dump, std::string dump_filename); gr_msg_queue_sptr queue, bool dump, std::string dump_filename);
/*! /*!
* \brief This class implements a Parallel Code Phase Search Acquisition * \brief This class implements a Parallel Code Phase Search Acquisition
*/ */
class pcps_acquisition_cc: public gr_block { class pcps_acquisition_cc: public gr_block {
private: private:
friend pcps_acquisition_cc_sptr
pcps_make_acquisition_cc(unsigned int sampled_ms,
unsigned int doppler_max, long freq, long fs_in,
int samples_per_ms, gr_msg_queue_sptr queue, bool dump,
std::string dump_filename);
friend pcps_acquisition_cc_sptr pcps_acquisition_cc(unsigned int sampled_ms,
pcps_make_acquisition_cc(unsigned int sampled_ms, unsigned int doppler_max, long freq, long fs_in,
unsigned int doppler_max, long freq, long fs_in, int samples_per_ms, gr_msg_queue_sptr queue, bool dump,
int samples_per_ms, gr_msg_queue_sptr queue, bool dump, std::string dump_filename);
std::string dump_filename);
pcps_acquisition_cc(unsigned int sampled_ms, void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift,
unsigned int doppler_max, long freq, long fs_in, int doppler_offset);
int samples_per_ms, gr_msg_queue_sptr queue, bool dump,
std::string dump_filename);
void calculate_magnitudes(gr_complex* fft_begin, int doppler_shift, long d_fs_in;
int doppler_offset); long d_freq;
int d_samples_per_ms;
long d_fs_in; unsigned int d_doppler_resolution;
long d_freq; float d_threshold;
int d_samples_per_ms; std::string d_satellite_str;
unsigned int d_doppler_resolution; unsigned int d_doppler_max;
float d_threshold; unsigned int d_doppler_step;
std::string d_satellite_str; unsigned int d_sampled_ms;
unsigned int d_doppler_max; unsigned int d_fft_size;
unsigned int d_doppler_step; unsigned long int d_sample_counter;
unsigned int d_sampled_ms; gr_complex* d_carrier;
unsigned int d_fft_size; gr_complex* d_fft_codes;
unsigned long int d_sample_counter; gri_fft_complex* d_fft_if;
gr_complex* d_carrier; gri_fft_complex* d_ifft;
Gnss_Synchro *d_gnss_synchro;
gr_complex* d_fft_codes; unsigned int d_code_phase;
float d_doppler_freq;
gri_fft_complex* d_fft_if; float d_mag;
float d_input_power;
gri_fft_complex* d_ifft; float d_test_statistics;
gr_msg_queue_sptr d_queue;
Gnss_Synchro *d_gnss_synchro; concurrent_queue<int> *d_channel_internal_queue;
unsigned int d_code_phase; std::ofstream d_dump_file;
float d_doppler_freq; bool d_active;
float d_mag; bool d_dump;
float d_input_power; unsigned int d_channel;
float d_test_statistics; std::string d_dump_filename;
gr_msg_queue_sptr d_queue;
concurrent_queue<int> *d_channel_internal_queue;
std::ofstream d_dump_file;
bool d_active;
bool d_dump;
unsigned int d_channel;
std::string d_dump_filename;
public: public:
/*!
~pcps_acquisition_cc(); * \brief Default destructor
*/
~pcps_acquisition_cc();
/*! /*!
* \brief Set acquisition/tracking common Gnss_Synchro object pointer * \brief Set acquisition/tracking common Gnss_Synchro object pointer
* to efficiently exchange synchronization data between acquisition and * to exchange synchronization data between acquisition and tracking blocks
* tracking blocks
*/ */
void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
{ {
d_gnss_synchro = p_gnss_synchro; d_gnss_synchro = p_gnss_synchro;
} }
/*! /*!
* \brief Returns the maximum peak of grid search * \brief Returns the maximum peak of grid search
*/ */
unsigned int mag() unsigned int mag()
{ {
return d_mag; return d_mag;
} }
/*! /*!
* \brief Initializes acquisition algorithm. * \brief Initializes acquisition algorithm.
*/ */
void init(); void init();
/*! /*!
* \brief Sets local code for PCPS acquisition algorithm. * \brief Sets local code for PCPS acquisition algorithm.
*/ */
void set_local_code(std::complex<float> * code); void set_local_code(std::complex<float> * code);
/*! /*!
* \brief Starts acquisition algorithm, turning from standby mode to * \brief Starts acquisition algorithm, turning from standby mode to
* active mode * active mode
*/ */
void set_active(bool active) void set_active(bool active)
{ {
d_active = active; d_active = active;
} }
/*! /*!
* \brief Set acquisition channel unique ID * \brief Set acquisition channel unique ID
*/ */
void set_channel(unsigned int channel) void set_channel(unsigned int channel)
{ {
d_channel = channel; d_channel = channel;
} }
/*! /*!
* \brief Set statistics threshold of PCPS algorithm * \brief Set statistics threshold of PCPS algorithm
*/ */
void set_threshold(float threshold) void set_threshold(float threshold)
{ {
d_threshold = threshold; d_threshold = threshold;
} }
/*! /*!
* \brief Set maximum Doppler off grid search * \brief Set maximum Doppler off grid search
*/ */
void set_doppler_max(unsigned int doppler_max) void set_doppler_max(unsigned int doppler_max)
{ {
d_doppler_max = doppler_max; d_doppler_max = doppler_max;
} }
/*! /*!
* \brief Set Doppler steps for the grid search * \brief Set Doppler steps for the grid search
*/ */
void set_doppler_step(unsigned int doppler_step) void set_doppler_step(unsigned int doppler_step)
{ {
d_doppler_step = doppler_step; d_doppler_step = doppler_step;
} }
/*! /*!
* \brief Set tracking channel internal queue * \brief Set tracking channel internal queue
*/ */
void set_channel_queue(concurrent_queue<int> *channel_internal_queue) void set_channel_queue(concurrent_queue<int> *channel_internal_queue)
{ {
d_channel_internal_queue = channel_internal_queue; d_channel_internal_queue = channel_internal_queue;
} }
int general_work(int noutput_items, gr_vector_int &ninput_items, int general_work(int noutput_items, gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items); gr_vector_void_star &output_items);
}; };
#endif /* PCPS_ACQUISITION_CC_H_*/ #endif /* GNSS_SDR_PCPS_ACQUISITION_CC_H_*/