1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-13 19:50:34 +00:00

adding a fir_filter for std::complex<signed char> (aka cbyte). It

converts the data type to floats, filters, and converts back to cbyte.
This commit is contained in:
Carles Fernandez 2015-02-03 00:58:21 +01:00
parent 9601ee3607
commit b9e7d8a446
13 changed files with 443 additions and 15 deletions

View File

@ -29,8 +29,8 @@
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_IBYTE_TO_COMPLEX_H_
#define GNSS_SDR_IBYTE_TO_COMPLEX_H_
#ifndef GNSS_SDR_IBYTE_TO_CBYTE_H_
#define GNSS_SDR_IBYTE_TO_CBYTE_H_
#include <string>
#include <gnuradio/blocks/file_sink.h>

View File

@ -58,12 +58,14 @@ int interleaved_byte_to_complex_byte::work(int noutput_items,
const signed char *in = (const signed char *) input_items[0];
lv_8sc_t *out = (lv_8sc_t *) output_items[0];
// This could be put into a Volk kernel
unsigned int sample_index = 0;
signed char real_part;
signed char imag_part;
for(unsigned int number = 0; number < 2 * noutput_items; number++)
{
// lv_cmake(r, i) defined at volk/volk_complex.h
*out++ = lv_cmake(in[sample_index], in[sample_index + 1]);
sample_index = sample_index + 2;
real_part = *in++;
imag_part = *in++;
*out++ = lv_cmake(real_part, imag_part);
}
return noutput_items;

View File

@ -30,6 +30,7 @@ include_directories(
${GLOG_INCLUDE_DIRS}
${GFlags_INCLUDE_DIRS}
${GNURADIO_RUNTIME_INCLUDE_DIRS}
${VOLK_INCLUDE_DIRS}
)
file(GLOB INPUT_FILTER_ADAPTER_HEADERS "*.h")

View File

@ -32,6 +32,7 @@
#include <boost/lexical_cast.hpp>
#include <gnuradio/filter/pm_remez.h>
#include <glog/logging.h>
#include <volk/volk.h>
#include "configuration_interface.h"
using google::LogMessage;
@ -56,9 +57,50 @@ FirFilter::FirFilter(ConfigurationInterface* configuration, std::string role,
file_sink_ = gr::blocks::file_sink::make(item_size, dump_filename_.c_str());
}
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
item_size = sizeof(gr_complex);
cbyte_to_float_x2_ = make_complex_byte_to_float_x2();
fir_filter_fff_1_ = gr::filter::fir_filter_fff::make(1, taps_);
fir_filter_fff_2_ = gr::filter::fir_filter_fff::make(1, taps_);
DLOG(INFO) << "I input_filter(" << fir_filter_fff_1_->unique_id() << ")";
DLOG(INFO) << "Q input_filter(" << fir_filter_fff_2_->unique_id() << ")";
float_to_complex_ = gr::blocks::float_to_complex::make();
if (dump_)
{
DLOG(INFO) << "Dumping output into file " << dump_filename_;
file_sink_ = gr::blocks::file_sink::make(item_size, dump_filename_.c_str());
}
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("cbyte") == 0))
{
item_size = sizeof(lv_8sc_t);
cbyte_to_float_x2_ = make_complex_byte_to_float_x2();
fir_filter_fff_1_ = gr::filter::fir_filter_fff::make(1, taps_);
fir_filter_fff_2_ = gr::filter::fir_filter_fff::make(1, taps_);
DLOG(INFO) << "I input_filter(" << fir_filter_fff_1_->unique_id() << ")";
DLOG(INFO) << "Q input_filter(" << fir_filter_fff_2_->unique_id() << ")";
float_to_char_1_ = gr::blocks::float_to_char::make();
float_to_char_2_ = gr::blocks::float_to_char::make();
char_x2_cbyte_ = make_byte_x2_to_complex_byte();
if (dump_)
{
DLOG(INFO) << "Dumping output into file " << dump_filename_;
file_sink_ = gr::blocks::file_sink::make(item_size, dump_filename_.c_str());
}
}
else
{
LOG(ERROR) << taps_item_type_ << " unknown input filter item type";
LOG(ERROR) << " Unknown item type conversion";
}
}
@ -71,13 +113,48 @@ FirFilter::~FirFilter()
void FirFilter::connect(gr::top_block_sptr top_block)
{
if (dump_)
if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("gr_complex") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
top_block->connect(fir_filter_ccf_, 0, file_sink_, 0);
if (dump_)
{
top_block->connect(fir_filter_ccf_, 0, file_sink_, 0);
}
else
{
DLOG(INFO) << "Nothing to connect internally";
}
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
top_block->connect(cbyte_to_float_x2_, 0, fir_filter_fff_1_, 0);
top_block->connect(cbyte_to_float_x2_, 1, fir_filter_fff_2_, 0);
top_block->connect(fir_filter_fff_1_, 0, float_to_complex_, 0);
top_block->connect(fir_filter_fff_2_, 0, float_to_complex_, 1);
if (dump_)
{
top_block->connect(float_to_complex_, 0, file_sink_, 0);
}
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("cbyte") == 0))
{
top_block->connect(cbyte_to_float_x2_, 0, fir_filter_fff_1_, 0);
top_block->connect(cbyte_to_float_x2_, 1, fir_filter_fff_2_, 0);
top_block->connect(fir_filter_fff_1_, 0, float_to_char_1_, 0);
top_block->connect(fir_filter_fff_2_, 0, float_to_char_2_, 0);
top_block->connect(float_to_char_1_, 0, char_x2_cbyte_, 0);
top_block->connect(float_to_char_2_, 0, char_x2_cbyte_, 1);
if (dump_)
{
top_block->connect(char_x2_cbyte_, 0, file_sink_, 0);
}
}
else
{
DLOG(INFO) << "Nothing to connect internally";
LOG(ERROR) << " Unknown item type conversion";
}
}
@ -85,9 +162,39 @@ void FirFilter::connect(gr::top_block_sptr top_block)
void FirFilter::disconnect(gr::top_block_sptr top_block)
{
if (dump_)
if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("gr_complex") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
top_block->connect(fir_filter_ccf_, 0, file_sink_, 0);
if (dump_)
{
top_block->disconnect(fir_filter_ccf_, 0, file_sink_, 0);
}
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
top_block->disconnect(fir_filter_fff_2_, 0, float_to_complex_, 1);
top_block->disconnect(fir_filter_fff_1_, 0, float_to_complex_, 0);
top_block->disconnect(cbyte_to_float_x2_, 1, fir_filter_fff_2_, 0);
top_block->disconnect(cbyte_to_float_x2_, 0, fir_filter_fff_1_, 0);
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("cbyte") == 0))
{
top_block->disconnect(float_to_char_2_, 0, char_x2_cbyte_, 1);
top_block->disconnect(float_to_char_1_, 0, char_x2_cbyte_, 0);
top_block->disconnect(fir_filter_fff_2_, 0, float_to_char_2_, 0);
top_block->disconnect(fir_filter_fff_1_, 0, float_to_char_1_, 0);
top_block->disconnect(cbyte_to_float_x2_, 0, fir_filter_fff_1_, 0);
top_block->disconnect(cbyte_to_float_x2_, 1, fir_filter_fff_2_, 0);
if (dump_)
{
top_block->disconnect(char_x2_cbyte_, 0, file_sink_, 0);
}
}
else
{
LOG(ERROR) << " unknown input filter item type";
}
}
@ -95,14 +202,52 @@ void FirFilter::disconnect(gr::top_block_sptr top_block)
gr::basic_block_sptr FirFilter::get_left_block()
{
return fir_filter_ccf_;
if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("gr_complex") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
return fir_filter_ccf_;
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
return cbyte_to_float_x2_;
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("cbyte") == 0))
{
return cbyte_to_float_x2_;
}
else
{
return nullptr;
LOG(ERROR) << " unknown input filter item type";
}
}
gr::basic_block_sptr FirFilter::get_right_block()
{
return fir_filter_ccf_;
if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("gr_complex") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
return fir_filter_ccf_;
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("gr_complex") == 0))
{
return float_to_complex_;
}
else if ((taps_item_type_.compare("float") == 0) && (input_item_type_.compare("cbyte") == 0)
&& (output_item_type_.compare("cbyte") == 0))
{
return char_x2_cbyte_;
}
else
{
return nullptr;
LOG(ERROR) << " unknown input filter item type";
}
}

View File

@ -38,11 +38,15 @@
#include <vector>
#include <gnuradio/gr_complex.h>
#include <gnuradio/blocks/file_sink.h>
#include <gnuradio/blocks/float_to_char.h>
#include <gnuradio/blocks/float_to_complex.h>
#include <gnuradio/filter/fir_filter_ccf.h>
#include <gnuradio/filter/fir_filter_fff.h>
#include <gnuradio/msg_queue.h>
#include "gnss_synchro.h"
#include "gnss_block_interface.h"
#include "complex_byte_to_float_x2.h"
#include "byte_x2_to_complex_byte.h"
class ConfigurationInterface;
@ -100,6 +104,13 @@ private:
boost::shared_ptr<gr::msg_queue> queue_;
gr::blocks::file_sink::sptr file_sink_;
void init();
complex_byte_to_float_x2_sptr cbyte_to_float_x2_;
gr::filter::fir_filter_fff::sptr fir_filter_fff_1_;
gr::filter::fir_filter_fff::sptr fir_filter_fff_2_;
gr::blocks::float_to_char::sptr float_to_char_1_;
gr::blocks::float_to_char::sptr float_to_char_2_;
byte_x2_to_complex_byte_sptr char_x2_cbyte_;
gr::blocks::float_to_complex::sptr float_to_complex_;
};
#endif

View File

@ -19,6 +19,8 @@
set(INPUT_FILTER_GR_BLOCKS_SOURCES
beamformer.cc
complex_byte_to_float_x2.cc
byte_x2_to_complex_byte.cc
)
include_directories(
@ -26,9 +28,10 @@ include_directories(
${GLOG_INCLUDE_DIRS}
${GFlags_INCLUDE_DIRS}
${GNURADIO_RUNTIME_INCLUDE_DIRS}
${VOLK_INCLUDE_DIRS}
)
file(GLOB INPUT_FILTER_GR_BLOCKS_HEADERS "*.h")
add_library(input_filter_gr_blocks ${INPUT_FILTER_GR_BLOCKS_SOURCES} ${INPUT_FILTER_GR_BLOCKS_HEADERS})
source_group(Headers FILES ${INPUT_FILTER_GR_BLOCKS_HEADERS})
target_link_libraries(input_filter_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES})
target_link_libraries(input_filter_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES} ${VOLK_LIBRARIES})

View File

@ -0,0 +1,72 @@
/*!
* \file byte_x2_to_complex_byte.cc
* \brief * \brief Adapts two signed char streams into a std::complex<signed char> stream
* \author Carles Fernandez Prades, cfernandez(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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.
*
* GNSS-SDR 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 GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "byte_x2_to_complex_byte.h"
#include <gnuradio/io_signature.h>
#include <volk/volk.h>
byte_x2_to_complex_byte_sptr make_byte_x2_to_complex_byte()
{
return byte_x2_to_complex_byte_sptr(new byte_x2_to_complex_byte());
}
byte_x2_to_complex_byte::byte_x2_to_complex_byte() : sync_block("byte_x2_to_complex_byte",
gr::io_signature::make (2, 2, sizeof(char)),
gr::io_signature::make (1, 1, sizeof(lv_8sc_t))) // lv_8sc_t is a Volk's typedef for std::complex<signed char>
{
const int alignment_multiple = volk_get_alignment() / sizeof(lv_8sc_t);
set_alignment(std::max(1, alignment_multiple));
}
int byte_x2_to_complex_byte::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const char *in0 = (const char *) input_items[0];
const char *in1 = (const char *) input_items[1];
lv_8sc_t *out = (lv_8sc_t *) output_items[0];
// This could be put into a volk kernel
signed char real_part;
signed char imag_part;
for(unsigned int number = 0; number < 2 * noutput_items; number++)
{
// lv_cmake(r, i) defined at volk/volk_complex.h
real_part = *in0++;
imag_part = *in1++;
*out++ = lv_cmake(real_part, imag_part);
}
return noutput_items;
}

View File

@ -0,0 +1,61 @@
/*!
* \file byte_x2_to_complex_byte.h
* \brief Adapts two signed char streams into a std::complex<signed char> stream
* \author Carles Fernandez Prades, cfernandez(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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.
*
* GNSS-SDR 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 GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_BYTE_X2_TO_COMPLEX_BYTE_H_
#define GNSS_SDR_BYTE_X2_TO_COMPLEX_BYTE_H_
#include <string>
#include <boost/shared_ptr.hpp>
#include <gnuradio/sync_block.h>
class byte_x2_to_complex_byte;
typedef boost::shared_ptr<byte_x2_to_complex_byte> byte_x2_to_complex_byte_sptr;
byte_x2_to_complex_byte_sptr make_byte_x2_to_complex_byte();
/*!
* \brief This class adapts two signed char streams
* into a std::complex<signed char> stream
*/
class byte_x2_to_complex_byte : public gr::sync_block
{
private:
friend byte_x2_to_complex_byte_sptr make_byte_x2_to_complex_byte();
public:
byte_x2_to_complex_byte();
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
#endif

View File

@ -0,0 +1,63 @@
/*!
* \file complex_byte_to_float_x2.cc
* \brief Adapts a std::complex<signed char> stream into two 16-bits (short) streams
* \author Carles Fernandez Prades, cfernandez(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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.
*
* GNSS-SDR 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 GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "complex_byte_to_float_x2.h"
#include <gnuradio/io_signature.h>
#include <volk/volk.h>
complex_byte_to_float_x2_sptr make_complex_byte_to_float_x2()
{
return complex_byte_to_float_x2_sptr(new complex_byte_to_float_x2());
}
complex_byte_to_float_x2::complex_byte_to_float_x2() : sync_block("complex_byte_to_float_x2",
gr::io_signature::make (1, 1, sizeof(lv_8sc_t)), // lv_8sc_t is a Volk's typedef for std::complex<signed char>
gr::io_signature::make (2, 2, sizeof(float)))
{
const int alignment_multiple = volk_get_alignment() / sizeof(lv_8sc_t);
set_alignment(std::max(1, alignment_multiple));
}
int complex_byte_to_float_x2::work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const lv_8sc_t *in = (const lv_8sc_t *) input_items[0];
float *out0 = (float*) output_items[0];
float *out1 = (float*) output_items[1];
const float scalar = 1;
volk_8ic_s32f_deinterleave_32f_x2(out0, out1, in, scalar, noutput_items);
return noutput_items;
}

View File

@ -0,0 +1,61 @@
/*!
* \file complex_byte_to_float_x2.h
* \brief Adapts a std::complex<signed char> stream into two 16-bits (short) streams
* \author Carles Fernandez Prades, cfernandez(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* This file is part of GNSS-SDR.
*
* GNSS-SDR 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.
*
* GNSS-SDR 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 GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef GNSS_SDR_COMPLEX_BYTE_TO_FLOAT_X2_H_
#define GNSS_SDR_COMPLEX_BYTE_TO_FLOAT_X2_H_
#include <string>
#include <boost/shared_ptr.hpp>
#include <gnuradio/sync_block.h>
class complex_byte_to_float_x2;
typedef boost::shared_ptr<complex_byte_to_float_x2> complex_byte_to_float_x2_sptr;
complex_byte_to_float_x2_sptr make_complex_byte_to_float_x2();
/*!
* \brief This class adapts a std::complex<signed char> stream
* into two 16-bits (short) streams
*/
class complex_byte_to_float_x2 : public gr::sync_block
{
private:
friend complex_byte_to_float_x2_sptr make_complex_byte_to_float_x2();
public:
complex_byte_to_float_x2();
int work(int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
#endif

View File

@ -41,6 +41,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/algorithms/channel/libs
${CMAKE_SOURCE_DIR}/src/algorithms/conditioner/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/data_type_adapter/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/data_type_adapter/gnuradio_blocks
${CMAKE_SOURCE_DIR}/src/algorithms/resampler/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/input_filter/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/input_filter/gnuradio_blocks

View File

@ -54,6 +54,7 @@
#include "array_signal_conditioner.h"
#include "ishort_to_complex.h"
#include "ibyte_to_complex.h"
#include "ibyte_to_cbyte.h"
#include "direct_resampler_conditioner.h"
#include "fir_filter.h"
#include "freq_xlating_fir_filter.h"
@ -455,6 +456,12 @@ std::unique_ptr<GNSSBlockInterface> GNSSBlockFactory::GetBlock(
out_streams, queue));
block = std::move(block_);
}
else if (implementation.compare("Ibyte_To_Cbyte") == 0)
{
std::unique_ptr<GNSSBlockInterface>block_(new IbyteToCbyte(configuration.get(), role, in_streams,
out_streams, queue));
block = std::move(block_);
}
// INPUT FILTER ----------------------------------------------------------------
else if (implementation.compare("Fir_Filter") == 0)
{

View File

@ -138,6 +138,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/algorithms/signal_generator/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/signal_generator/gnuradio_blocks
${CMAKE_SOURCE_DIR}/src/algorithms/input_filter/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/input_filter/gnuradio_blocks
${CMAKE_SOURCE_DIR}/src/algorithms/acquisition/adapters
${CMAKE_SOURCE_DIR}/src/algorithms/acquisition/gnuradio_blocks
${CMAKE_SOURCE_DIR}/src/algorithms/output_filter/adapters