use long preamble for channel estimation and add lms equalizer
This commit is contained in:
@@ -5,7 +5,24 @@
|
|||||||
<key>ieee802_11_ofdm_equalize_symbols</key>
|
<key>ieee802_11_ofdm_equalize_symbols</key>
|
||||||
<category>IEEE802.11</category>
|
<category>IEEE802.11</category>
|
||||||
<import>import ieee802_11</import>
|
<import>import ieee802_11</import>
|
||||||
<make>ieee802_11.ofdm_equalize_symbols($debug)</make>
|
<make>ieee802_11.ofdm_equalize_symbols($algo, $debug)</make>
|
||||||
|
<callback>set_algorithm($algo)</callback>
|
||||||
|
|
||||||
|
<param>
|
||||||
|
<name>Algorithm</name>
|
||||||
|
<key>algo</key>
|
||||||
|
<value>ieee802_11.LINEAR_COMB</value>
|
||||||
|
<type>int</type>
|
||||||
|
|
||||||
|
<option>
|
||||||
|
<name>LMS</name>
|
||||||
|
<key>ieee802_11.LMS</key>
|
||||||
|
</option>
|
||||||
|
<option>
|
||||||
|
<name>linear comb</name>
|
||||||
|
<key>ieee802_11.LINEAR_COMB</key>
|
||||||
|
</option>
|
||||||
|
</param>
|
||||||
|
|
||||||
<param>
|
<param>
|
||||||
<name>Debug</name>
|
<name>Debug</name>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Bastian Bloessl <bloessl@ccs-labs.org>
|
* Copyright (C) 2013, 2015 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -20,6 +20,11 @@
|
|||||||
#include <ieee802-11/api.h>
|
#include <ieee802-11/api.h>
|
||||||
#include <gnuradio/block.h>
|
#include <gnuradio/block.h>
|
||||||
|
|
||||||
|
enum Equalizer {
|
||||||
|
LMS = 0,
|
||||||
|
LINEAR_COMB = 1,
|
||||||
|
};
|
||||||
|
|
||||||
namespace gr {
|
namespace gr {
|
||||||
namespace ieee802_11 {
|
namespace ieee802_11 {
|
||||||
|
|
||||||
@@ -28,7 +33,8 @@ class IEEE802_11_API ofdm_equalize_symbols : virtual public block
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
typedef boost::shared_ptr<ofdm_equalize_symbols> sptr;
|
typedef boost::shared_ptr<ofdm_equalize_symbols> sptr;
|
||||||
static sptr make(bool debug = false);
|
static sptr make(Equalizer algo, bool debug = false);
|
||||||
|
virtual void set_algorithm(Equalizer algo) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ add_dependencies(ieee802_11_generated_sources ieee802_11_generated_includes)
|
|||||||
########################################################################
|
########################################################################
|
||||||
list(APPEND gr_ieee802_11_sources
|
list(APPEND gr_ieee802_11_sources
|
||||||
${generated_sources}
|
${generated_sources}
|
||||||
|
equalizer/linear_comb.cc
|
||||||
|
equalizer/lms.cc
|
||||||
chunks_to_symbols_impl.cc
|
chunks_to_symbols_impl.cc
|
||||||
ether_encap_impl.cc
|
ether_encap_impl.cc
|
||||||
ofdm_decode_mac.cc
|
ofdm_decode_mac.cc
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDED_IEEE802_11_EQUALIZER_BASE_H
|
||||||
|
#define INCLUDED_IEEE802_11_EQUALIZER_BASE_H
|
||||||
|
|
||||||
|
#include <gnuradio/gr_complex.h>
|
||||||
|
|
||||||
|
namespace gr {
|
||||||
|
namespace ieee802_11 {
|
||||||
|
namespace equalizer {
|
||||||
|
|
||||||
|
class base {
|
||||||
|
public:
|
||||||
|
virtual ~base() {};
|
||||||
|
virtual void equalize(const gr_complex *in, gr_complex *out, int n) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace channel_estimation */
|
||||||
|
} /* namespace ieee802_11 */
|
||||||
|
} /* namespace gr */
|
||||||
|
|
||||||
|
#endif /* INCLUDED_IEEE802_11_EQUALIZER_BASE_H */
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "linear_comb.h"
|
||||||
|
|
||||||
|
using namespace gr::ieee802_11::equalizer;
|
||||||
|
|
||||||
|
void linear_comb::equalize(const gr_complex *in, gr_complex *out, int n) {
|
||||||
|
if(n < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
double avg_mag = (abs(in[11]) + abs(in[25]) + abs(in[39]) + abs(in[53])) / 4;
|
||||||
|
|
||||||
|
gr_complex p = POLARITY[(n - 2) % 127 ];
|
||||||
|
|
||||||
|
double p1 = arg( p * in[11]);
|
||||||
|
double p2 = arg( p * in[25] * conj(p * in[11])) + p1;
|
||||||
|
double p3 = arg( p * in[39] * conj(p * in[25])) + p2;
|
||||||
|
double p4 = arg(-p * in[53] * conj(p * in[39])) + p3;
|
||||||
|
|
||||||
|
double my = (p1 + p2 + p3 + p4) / 4;
|
||||||
|
double mx = (11.0 + 25 + 39 + 53) / 4;
|
||||||
|
|
||||||
|
double var = (((11.0 * 11.0) + (25.0 * 25.0) + (39.0 * 39.0) + (53.0 * 53.0)) / 4) - (mx * mx);
|
||||||
|
double cov = (( (p1 * 11) + (p2 * 25) + (p3 * 39) + (p4 * 53) ) / 4) - (mx * my);
|
||||||
|
double beta = cov / var;
|
||||||
|
double alpha = my - beta * mx;
|
||||||
|
|
||||||
|
int c = 0;
|
||||||
|
for(int n = 0; n < 64; n++) {
|
||||||
|
if( (n == 11) || (n == 25) || (n == 32) || (n == 39) || (n == 53) || (n < 6) || ( n > 58)) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
out[c] = in[n] * exp(gr_complex(0, -n * beta - alpha)) * gr_complex(1 / avg_mag, 0);
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const gr_complex linear_comb::POLARITY[127] = {
|
||||||
|
1, 1, 1, 1,-1,-1,-1, 1,-1,-1,-1,-1, 1, 1,-1, 1,
|
||||||
|
-1,-1, 1, 1,-1, 1, 1,-1, 1, 1, 1, 1, 1, 1,-1, 1,
|
||||||
|
1, 1,-1, 1, 1,-1,-1, 1, 1, 1,-1, 1,-1,-1,-1, 1,
|
||||||
|
-1, 1,-1,-1, 1,-1,-1, 1, 1, 1, 1, 1,-1,-1, 1, 1,
|
||||||
|
-1,-1, 1,-1, 1,-1, 1, 1,-1,-1,-1, 1, 1,-1,-1,-1,
|
||||||
|
-1, 1,-1,-1, 1,-1, 1, 1, 1, 1,-1, 1,-1, 1,-1, 1,
|
||||||
|
-1,-1,-1,-1,-1, 1,-1, 1, 1,-1, 1,-1, 1, 1, 1,-1,
|
||||||
|
-1, 1,-1,-1,-1, 1, 1, 1,-1,-1,-1,-1,-1,-1,-1 };
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDED_IEEE802_11_EQUALIZER_LINEAR_COMB_H
|
||||||
|
#define INCLUDED_IEEE802_11_EQUALIZER_LINEAR_COMB_H
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
|
|
||||||
|
namespace gr {
|
||||||
|
namespace ieee802_11 {
|
||||||
|
namespace equalizer {
|
||||||
|
|
||||||
|
class linear_comb: public base {
|
||||||
|
public:
|
||||||
|
virtual void equalize(const gr_complex *in, gr_complex *out, int n);
|
||||||
|
private:
|
||||||
|
static const gr_complex POLARITY[127];
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace channel_estimation */
|
||||||
|
} /* namespace ieee802_11 */
|
||||||
|
} /* namespace gr */
|
||||||
|
|
||||||
|
#endif /* INCLUDED_IEEE802_11_EQUALIZER_LINEAR_COMB_H */
|
||||||
|
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "lms.h"
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace gr::ieee802_11::equalizer;
|
||||||
|
|
||||||
|
void lms::equalize(const gr_complex *in, gr_complex *out, int n) {
|
||||||
|
|
||||||
|
static float freq_offset = 0;
|
||||||
|
static float freq_sum = 0;
|
||||||
|
static float alpha = 0.9;
|
||||||
|
|
||||||
|
if(n == 0) {
|
||||||
|
std::memcpy(carrier, in, 64 * sizeof(gr_complex));
|
||||||
|
} else if(n == 1) {
|
||||||
|
gr_complex sum =
|
||||||
|
(carrier[11] * conj(in[11])) +
|
||||||
|
(carrier[25] * conj(in[25])) +
|
||||||
|
(carrier[39] * conj(in[39])) +
|
||||||
|
(carrier[53] * conj(in[53]));
|
||||||
|
freq_offset = arg(sum);
|
||||||
|
freq_sum = 0;
|
||||||
|
for(int i = 0; i < 64; i++) {
|
||||||
|
carrier[i] += in[i];
|
||||||
|
carrier[i] *= ref[i] * gr_complex(0.5, 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
gr_complex p = POLARITY[(n - 2) % 127];
|
||||||
|
gr_complex sum =
|
||||||
|
(carrier[11] * conj(in[11]) * p) +
|
||||||
|
(carrier[25] * conj(in[25]) * p) +
|
||||||
|
(carrier[39] * conj(in[39]) * p) +
|
||||||
|
(carrier[53] * conj(in[53]) * -p);
|
||||||
|
|
||||||
|
freq_offset = (1 - alpha) * freq_offset + alpha * arg(sum);
|
||||||
|
freq_sum += freq_offset;
|
||||||
|
|
||||||
|
//std::cout << "lms: symbol " << n
|
||||||
|
// << " p1 " << abs(carrier[11] * conj(in[11]) * p)
|
||||||
|
// << " p2 " << abs(carrier[25] * conj(in[25]) * p)
|
||||||
|
// << " p3 " << abs(carrier[39] * conj(in[39]) * p)
|
||||||
|
// << " p4 " << abs(carrier[53] * conj(in[53]) * -p)
|
||||||
|
// << std::endl;
|
||||||
|
//std::cout << "lms: symbol " << n
|
||||||
|
// << " p1 " << arg(carrier[11] * conj(in[11]) * p)
|
||||||
|
// << " p2 " << arg(carrier[25] * conj(in[25]) * p)
|
||||||
|
// << " p3 " << arg(carrier[39] * conj(in[39]) * p)
|
||||||
|
// << " p4 " << arg(carrier[53] * conj(in[53]) * -p)
|
||||||
|
// << std::endl;
|
||||||
|
|
||||||
|
carrier[11] = in[11] * p;
|
||||||
|
carrier[25] = in[25] * p;
|
||||||
|
carrier[39] = in[39] * p;
|
||||||
|
carrier[53] = in[53] * -p;
|
||||||
|
|
||||||
|
int c = 0;
|
||||||
|
for(int i = 0; i < 64; i++) {
|
||||||
|
if( (i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) || (i < 6) || ( i > 58)) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
out[c] = in[i] / carrier[i] * exp(gr_complex(0, freq_sum));
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const gr_complex lms::ref[] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 1, 1, -1, -1,
|
||||||
|
1, 1, -1, 1, -1, 1, 1, 1, 1, 1,
|
||||||
|
1, -1, -1, 1, 1, -1, 1, -1, 1, 1,
|
||||||
|
1, 1, 0, 1, -1, -1, 1, 1, -1, 1,
|
||||||
|
-1, 1, -1, -1, -1, -1, -1, 1, 1, -1,
|
||||||
|
-1, 1, -1, 1, -1, 1, 1, 1, 1, 0,
|
||||||
|
0, 0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
const gr_complex lms::POLARITY[127] = {
|
||||||
|
1, 1, 1, 1,-1,-1,-1, 1,-1,-1,-1,-1, 1, 1,-1, 1,
|
||||||
|
-1,-1, 1, 1,-1, 1, 1,-1, 1, 1, 1, 1, 1, 1,-1, 1,
|
||||||
|
1, 1,-1, 1, 1,-1,-1, 1, 1, 1,-1, 1,-1,-1,-1, 1,
|
||||||
|
-1, 1,-1,-1, 1,-1,-1, 1, 1, 1, 1, 1,-1,-1, 1, 1,
|
||||||
|
-1,-1, 1,-1, 1,-1, 1, 1,-1,-1,-1, 1, 1,-1,-1,-1,
|
||||||
|
-1, 1,-1,-1, 1,-1, 1, 1, 1, 1,-1, 1,-1, 1,-1, 1,
|
||||||
|
-1,-1,-1,-1,-1, 1,-1, 1, 1,-1, 1,-1, 1, 1, 1,-1,
|
||||||
|
-1, 1,-1,-1,-1, 1, 1, 1,-1,-1,-1,-1,-1,-1,-1 };
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef INCLUDED_IEEE802_11_EQUALIZER_LMS_H
|
||||||
|
#define INCLUDED_IEEE802_11_EQUALIZER_LMS_H
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace gr {
|
||||||
|
namespace ieee802_11 {
|
||||||
|
namespace equalizer {
|
||||||
|
|
||||||
|
class lms: public base {
|
||||||
|
public:
|
||||||
|
virtual void equalize(const gr_complex *in, gr_complex *out, int n);
|
||||||
|
private:
|
||||||
|
gr_complex carrier[64];
|
||||||
|
static const gr_complex ref[64];
|
||||||
|
static const gr_complex POLARITY[127];
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace channel_estimation */
|
||||||
|
} /* namespace ieee802_11 */
|
||||||
|
} /* namespace gr */
|
||||||
|
|
||||||
|
#endif /* INCLUDED_IEEE802_11_EQUALIZER_LMS_H */
|
||||||
|
|
||||||
@@ -17,6 +17,9 @@
|
|||||||
#include <ieee802-11/ofdm_equalize_symbols.h>
|
#include <ieee802-11/ofdm_equalize_symbols.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "equalizer/base.h"
|
||||||
|
#include "equalizer/linear_comb.h"
|
||||||
|
#include "equalizer/lms.h"
|
||||||
#include <gnuradio/io_signature.h>
|
#include <gnuradio/io_signature.h>
|
||||||
|
|
||||||
using namespace gr::ieee802_11;
|
using namespace gr::ieee802_11;
|
||||||
@@ -25,12 +28,14 @@ using namespace gr::ieee802_11;
|
|||||||
class ofdm_equalize_symbols_impl : public ofdm_equalize_symbols {
|
class ofdm_equalize_symbols_impl : public ofdm_equalize_symbols {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ofdm_equalize_symbols_impl(bool debug) : block("ofdm_equalize_symbols",
|
ofdm_equalize_symbols_impl(Equalizer algo, bool debug) : block("ofdm_equalize_symbols",
|
||||||
gr::io_signature::make(1, 1, 64 * sizeof(gr_complex)),
|
gr::io_signature::make(1, 1, 64 * sizeof(gr_complex)),
|
||||||
gr::io_signature::make(1, 1, 48 * sizeof(gr_complex))),
|
gr::io_signature::make(1, 1, 48 * sizeof(gr_complex))),
|
||||||
d_debug(debug) {
|
d_debug(debug), d_equalizer(NULL) {
|
||||||
|
|
||||||
set_relative_rate(1);
|
set_relative_rate(1);
|
||||||
|
set_tag_propagation_policy(block::TPP_DONT);
|
||||||
|
set_algorithm(algo);
|
||||||
}
|
}
|
||||||
|
|
||||||
~ofdm_equalize_symbols_impl(){
|
~ofdm_equalize_symbols_impl(){
|
||||||
@@ -40,87 +45,76 @@ 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) {
|
||||||
|
|
||||||
|
gr::thread::scoped_lock lock(d_mutex);
|
||||||
|
|
||||||
const gr_complex *in = (const gr_complex*)input_items[0];
|
const gr_complex *in = (const gr_complex*)input_items[0];
|
||||||
gr_complex *out = (gr_complex*)output_items[0];
|
gr_complex *out = (gr_complex*)output_items[0];
|
||||||
|
|
||||||
int noutput = noutput_items;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
int o = 0;
|
||||||
std::vector<gr::tag_t> tags;
|
|
||||||
const uint64_t nread = nitems_read(0);
|
|
||||||
|
|
||||||
dout << "SYMBOLS: input " << ninput_items[0] << " output " << noutput_items << std::endl;
|
dout << "SYMBOLS: input " << ninput_items[0] << " output " << noutput_items << std::endl;
|
||||||
|
|
||||||
while((i < ninput_items[0]) && (i < noutput)) {
|
while((i < ninput_items[0]) && (o < noutput_items)) {
|
||||||
|
|
||||||
get_tags_in_range(tags, 0, nread + i, nread + i + 1,
|
get_tags_in_window(tags, 0, i, i + 1, pmt::string_to_symbol("ofdm_start"));
|
||||||
pmt::string_to_symbol("ofdm_start"));
|
|
||||||
|
|
||||||
|
// new WiFi frame
|
||||||
if(tags.size()) {
|
if(tags.size()) {
|
||||||
index = 0;
|
d_nsym = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gr_complex p = POLARITY[index];
|
// first data symbol (= signal field)
|
||||||
index++;
|
if(d_nsym == 2) {
|
||||||
index %= 127;
|
add_item_tag(0, nitems_written(0) + o,
|
||||||
|
pmt::string_to_symbol("ofdm_start"),
|
||||||
|
pmt::PMT_T,
|
||||||
|
pmt::string_to_symbol(name()));
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: think about this... average over amplitude or power
|
d_equalizer->equalize(in + (i * 64), out + (o * 48), d_nsym);
|
||||||
double avg_mag = (abs(in[11]) + abs(in[25]) + abs(in[39]) + abs(in[53])) / 4;
|
|
||||||
|
|
||||||
|
if(d_nsym > 1) {
|
||||||
double p1 = arg( p * in[11]);
|
|
||||||
double p2 = arg( p * in[25] * conj(p * in[11])) + p1;
|
|
||||||
double p3 = arg( p * in[39] * conj(p * in[25])) + p2;
|
|
||||||
double p4 = arg(-p * in[53] * conj(p * in[39])) + p3;
|
|
||||||
|
|
||||||
double my = (p1 + p2 + p3 + p4) / 4;
|
|
||||||
double mx = (11.0 + 25 + 39 + 53) / 4;
|
|
||||||
|
|
||||||
double var = (((11.0 * 11.0) + (25.0 * 25.0) + (39.0 * 39.0) + (53.0 * 53.0)) / 4) - (mx * mx);
|
|
||||||
double cov = (( (p1 * 11) + (p2 * 25) + (p3 * 39) + (p4 * 53) ) / 4) - (mx * my);
|
|
||||||
double beta = cov / var;
|
|
||||||
double alpha = my - beta * mx;
|
|
||||||
|
|
||||||
int o = 0;
|
|
||||||
for(int n = 0; n < 64; n++) {
|
|
||||||
if( (n == 11) || (n == 25) || (n == 32) || (n == 39) || (n == 53) || (n < 6) || ( n > 58)) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
// FIXME: think about this... square or not
|
|
||||||
out[o] = in[n] * exp(gr_complex(0, -n * beta - alpha)) * gr_complex(1 / avg_mag, 0);
|
|
||||||
o++;
|
o++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
in += 64;
|
d_nsym++;
|
||||||
out += 48;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dout << "SYMBOLS: produced / consumed " << i << std::endl;
|
dout << "SYMBOLS: consumed " << i << " produced " << o << std::endl;
|
||||||
|
|
||||||
consume(0, i);
|
consume(0, i);
|
||||||
return i;
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_algorithm(Equalizer algo) {
|
||||||
|
gr::thread::scoped_lock lock(d_mutex);
|
||||||
|
delete d_equalizer;
|
||||||
|
|
||||||
|
switch(algo) {
|
||||||
|
case LMS:
|
||||||
|
dout << "LMS" << std::endl;
|
||||||
|
d_equalizer = new equalizer::lms();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LINEAR_COMB:
|
||||||
|
dout << "Linear Comb" << std::endl;
|
||||||
|
d_equalizer = new equalizer::linear_comb();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int index;
|
int d_nsym;
|
||||||
const bool d_debug;
|
const bool d_debug;
|
||||||
static const gr_complex POLARITY[127];
|
equalizer::base *d_equalizer;
|
||||||
|
std::vector<gr::tag_t> tags;
|
||||||
|
gr::thread::mutex d_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
const gr_complex ofdm_equalize_symbols_impl::POLARITY[127] = {
|
|
||||||
1, 1, 1, 1,-1,-1,-1, 1,-1,-1,-1,-1, 1, 1,-1, 1,
|
|
||||||
-1,-1, 1, 1,-1, 1, 1,-1, 1, 1, 1, 1, 1, 1,-1, 1,
|
|
||||||
1, 1,-1, 1, 1,-1,-1, 1, 1, 1,-1, 1,-1,-1,-1, 1,
|
|
||||||
-1, 1,-1,-1, 1,-1,-1, 1, 1, 1, 1, 1,-1,-1, 1, 1,
|
|
||||||
-1,-1, 1,-1, 1,-1, 1, 1,-1,-1,-1, 1, 1,-1,-1,-1,
|
|
||||||
-1, 1,-1,-1, 1,-1, 1, 1, 1, 1,-1, 1,-1, 1,-1, 1,
|
|
||||||
-1,-1,-1,-1,-1, 1,-1, 1, 1,-1, 1,-1, 1, 1, 1,-1,
|
|
||||||
-1, 1,-1,-1,-1, 1, 1, 1,-1,-1,-1,-1,-1,-1,-1 };
|
|
||||||
|
|
||||||
ofdm_equalize_symbols::sptr
|
ofdm_equalize_symbols::sptr
|
||||||
ofdm_equalize_symbols::make(bool debug) {
|
ofdm_equalize_symbols::make(Equalizer algo, bool debug) {
|
||||||
return gnuradio::get_initial_sptr(new ofdm_equalize_symbols_impl(debug));
|
return gnuradio::get_initial_sptr(new ofdm_equalize_symbols_impl(algo, debug));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user