1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-24 22:13:15 +00:00

Notch filters FFT improved

FFT migrated from Armadillo to GNU Radio
This commit is contained in:
Unknown 2017-10-18 12:30:42 +02:00
parent f6397c9c39
commit c114d38975
5 changed files with 15 additions and 18 deletions

View File

@ -38,7 +38,6 @@
#include <volk/volk.h>
#include <iostream>
#include <glog/logging.h>
#include <armadillo>
using google::LogMessage;
@ -72,6 +71,7 @@ Notch::Notch(float pfa, float p_c_factor, int length_, int n_segments_est, int n
angle_ = static_cast<float *>(volk_malloc(length_ * sizeof(float), volk_get_alignment()));
power_spect = static_cast<float *>(volk_malloc(length_ * sizeof(float), volk_get_alignment()));
last_out = gr_complex(0,0);
d_fft = std::unique_ptr<gr::fft::fft_complex>(new gr::fft::fft_complex(length_, true));
}
@ -99,17 +99,14 @@ int Notch::general_work(int noutput_items, gr_vector_int &ninput_items __attribu
lv_32fc_t dot_prod_;
const gr_complex* in = reinterpret_cast<const gr_complex *>(input_items[0]);
gr_complex* out = reinterpret_cast<gr_complex *>(output_items[0]);
in++;
arma::cx_fvec signal_segment;
arma::cx_fvec signal_segment_fft;
while((index_out + length_) < noutput_items)
{
if((n_segments < n_segments_est) && (filter_state_ == false))
{
signal_segment = arma::cx_fvec(in, length_);
signal_segment_fft = arma::fft(signal_segment);
volk_32fc_s32f_power_spectrum_32f(power_spect, signal_segment_fft.memptr(), 1.0, length_);
memcpy(d_fft->get_inbuf(), in, sizeof(gr_complex) * length_);
d_fft->execute();
volk_32fc_s32f_power_spectrum_32f(power_spect, d_fft->get_outbuf(), 1.0, length_);
volk_32f_s32f_calc_spectral_noise_floor_32f(&sig2dB, power_spect, 15.0, length_);
sig2lin = std::pow(10.0, (sig2dB / 10.0)) / (static_cast<float>(n_deg_fred) );
noise_pow_est = (static_cast<float>(n_segments) * noise_pow_est + sig2lin) / (static_cast<float>(n_segments + 1));

View File

@ -33,6 +33,8 @@
#include <boost/shared_ptr.hpp>
#include <gnuradio/block.h>
#include <gnuradio/fft/fft.h>
#include <memory>
class Notch;
@ -64,6 +66,7 @@ private:
gr_complex* c_samples;
float* angle_;
float* power_spect;
std::unique_ptr<gr::fft::fft_complex> d_fft;
public:

View File

@ -38,7 +38,6 @@
#include <iostream>
#include <glog/logging.h>
#include <boost/math/distributions/chi_squared.hpp>
#include <armadillo>
using google::LogMessage;
@ -47,7 +46,6 @@ notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int length_,
return notch_lite_sptr(new NotchLite(p_c_factor, pfa, length_, n_segments_est, n_segments_reset, n_segments_coeff));
}
NotchLite::NotchLite(float p_c_factor, float pfa, int length_, int n_segments_est, int n_segments_reset, int n_segments_coeff) : gr::block("NotchLite",
gr::io_signature::make (1, 1, sizeof(gr_complex)),
gr::io_signature::make (1, 1, sizeof(gr_complex)))
@ -76,10 +74,9 @@ NotchLite::NotchLite(float p_c_factor, float pfa, int length_, int n_segments_es
angle1 = 0.0;
angle2 = 0.0;
power_spect = static_cast<float *>(volk_malloc(length_ * sizeof(float), volk_get_alignment()));
d_fft = std::unique_ptr<gr::fft::fft_complex>(new gr::fft::fft_complex(length_, true));
}
NotchLite::~NotchLite()
{
volk_free(power_spect);
@ -102,17 +99,14 @@ int NotchLite::general_work(int noutput_items, gr_vector_int &ninput_items __att
lv_32fc_t dot_prod_;
const gr_complex* in = reinterpret_cast<const gr_complex *>(input_items[0]);
gr_complex* out = reinterpret_cast<gr_complex *>(output_items[0]);
in++;
arma::cx_fvec signal_segment;
arma::cx_fvec signal_segment_fft;
while((index_out + length_) < noutput_items)
{
if((n_segments < n_segments_est) && (filter_state_ == false))
{
signal_segment = arma::cx_fvec(in, length_);
signal_segment_fft = arma::fft(signal_segment);
volk_32fc_s32f_power_spectrum_32f(power_spect, signal_segment_fft.memptr(), 1.0, length_);
memcpy(d_fft->get_inbuf(), in, sizeof(gr_complex) * length_);
d_fft->execute();
volk_32fc_s32f_power_spectrum_32f(power_spect, d_fft->get_outbuf(), 1.0, length_);
volk_32f_s32f_calc_spectral_noise_floor_32f(&sig2dB, power_spect, 15.0, length_);
sig2lin = std::pow(10.0, (sig2dB / 10.0)) / static_cast<float>(n_deg_fred);
noise_pow_est = (static_cast<float>(n_segments) * noise_pow_est + sig2lin) / static_cast<float>(n_segments + 1);

View File

@ -33,6 +33,8 @@
#include <boost/shared_ptr.hpp>
#include <gnuradio/block.h>
#include <gnuradio/fft/fft.h>
#include <memory>
class NotchLite;
@ -67,6 +69,7 @@ private:
float angle1;
float angle2;
float* power_spect;
std::unique_ptr<gr::fft::fft_complex> d_fft;
public:

View File

@ -35,7 +35,7 @@
#include <gnuradio/fft/fft.h>
#include <armadillo>
DEFINE_int32(fft_speed_iterations_test, 1000, "Number of averaged iterations in FFT length timing test");
DEFINE_int32(fft_speed_iterations_test, 100, "Number of averaged iterations in FFT length timing test");
TEST(FFTSpeedTest, ArmadilloVSGNURadioExecutionTime)
{