add equalizers
This commit is contained in:
+4
-1
@@ -99,8 +99,11 @@ list(APPEND gr_ieee802_11_sources
|
||||
decode_mac.cc
|
||||
decode_signal.cc
|
||||
equalize_symbols.cc
|
||||
equalizer/linear_comb.cc
|
||||
equalizer/base.cc
|
||||
equalizer/comb.cc
|
||||
equalizer/ls.cc
|
||||
equalizer/lms.cc
|
||||
equalizer/sta.cc
|
||||
ether_encap_impl.cc
|
||||
mac.cc
|
||||
mapper.cc
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 "base.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using namespace gr::ieee802_11::equalizer;
|
||||
|
||||
const gr_complex base::LONG[] = {
|
||||
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 base::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 };
|
||||
@@ -19,6 +19,7 @@
|
||||
#define INCLUDED_IEEE802_11_EQUALIZER_BASE_H
|
||||
|
||||
#include <gnuradio/gr_complex.h>
|
||||
#include <gnuradio/digital/constellation.h>
|
||||
|
||||
namespace gr {
|
||||
namespace ieee802_11 {
|
||||
@@ -27,7 +28,13 @@ namespace equalizer {
|
||||
class base {
|
||||
public:
|
||||
virtual ~base() {};
|
||||
virtual void equalize(const gr_complex *in, gr_complex *out, int n) = 0;
|
||||
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) = 0;
|
||||
virtual double get_snr() = 0;
|
||||
|
||||
static const gr_complex POLARITY[127];
|
||||
|
||||
protected:
|
||||
static const gr_complex LONG[64];
|
||||
};
|
||||
|
||||
} /* namespace channel_estimation */
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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 "comb.h"
|
||||
|
||||
using namespace gr::ieee802_11::equalizer;
|
||||
|
||||
void comb::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) {
|
||||
|
||||
gr_complex pilot[4];
|
||||
|
||||
if(n < 2) {
|
||||
pilot[0] = in[11];
|
||||
pilot[1] = -in[25];
|
||||
pilot[2] = in[39];
|
||||
pilot[3] = in[53];
|
||||
} else {
|
||||
gr_complex p = POLARITY[(n - 2) % 127];
|
||||
pilot[0] = in[11] * p;
|
||||
pilot[1] = in[25] * p;
|
||||
pilot[2] = in[39] * p;
|
||||
pilot[3] = in[53] * -p;
|
||||
}
|
||||
|
||||
gr_complex avg = (pilot[0] + pilot[1] + pilot[2] + pilot[3]) / gr_complex(4, 0);
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
gr_complex H;
|
||||
if(i <= 11) {
|
||||
H = gr_complex((11-i) / 11.0, 0) * avg + gr_complex( i / 11.0, 0) * pilot[0];
|
||||
} else if(i <= 25) {
|
||||
H = gr_complex((25-i) / 14.0, 0) * pilot[0] + gr_complex((i-11) / 14.0, 0) * pilot[1];
|
||||
} else if(i <= 39) {
|
||||
H = gr_complex((39-i) / 14.0, 0) * pilot[1] + gr_complex((i-25) / 14.0, 0) * pilot[2];
|
||||
} else if(i <= 53) {
|
||||
H = gr_complex((53-i) / 14.0, 0) * pilot[2] + gr_complex((i-39) / 14.0, 0) * pilot[3];
|
||||
} else {
|
||||
H = gr_complex((64-i) / 11.0, 0) * pilot[3] + gr_complex((i-53) / 11.0, 0) * avg;
|
||||
}
|
||||
|
||||
if(n == 0) {
|
||||
d_H[i] = H;
|
||||
} else {
|
||||
d_H[i] = gr_complex(1-alpha, 0) * d_H[i] + gr_complex(alpha, 0) * H;
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
symbols[c] = in[i] / d_H[i];
|
||||
bits[c] = mod->decision_maker(&symbols[c]);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
comb::get_snr() {
|
||||
return 42;
|
||||
}
|
||||
@@ -15,8 +15,8 @@
|
||||
* 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
|
||||
#ifndef INCLUDED_IEEE802_11_EQUALIZER_COMB_H
|
||||
#define INCLUDED_IEEE802_11_EQUALIZER_COMB_H
|
||||
|
||||
#include "base.h"
|
||||
|
||||
@@ -24,16 +24,21 @@ namespace gr {
|
||||
namespace ieee802_11 {
|
||||
namespace equalizer {
|
||||
|
||||
class linear_comb: public base {
|
||||
class comb: public base {
|
||||
public:
|
||||
virtual void equalize(const gr_complex *in, gr_complex *out, int n);
|
||||
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod);
|
||||
double get_snr();
|
||||
|
||||
private:
|
||||
static const gr_complex POLARITY[127];
|
||||
gr_complex d_H[64];
|
||||
|
||||
|
||||
const double alpha = 0.2;
|
||||
};
|
||||
|
||||
} /* namespace channel_estimation */
|
||||
} /* namespace ieee802_11 */
|
||||
} /* namespace gr */
|
||||
|
||||
#endif /* INCLUDED_IEEE802_11_EQUALIZER_LINEAR_COMB_H */
|
||||
#endif /* INCLUDED_IEEE802_11_EQUALIZER_COMB_H */
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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 };
|
||||
+24
-64
@@ -21,84 +21,44 @@
|
||||
|
||||
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;
|
||||
void lms::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) {
|
||||
|
||||
if(n == 0) {
|
||||
std::memcpy(carrier, in, 64 * sizeof(gr_complex));
|
||||
std::memcpy(d_H, 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;
|
||||
double signal = 0;
|
||||
double noise = 0;
|
||||
for(int i = 0; i < 64; i++) {
|
||||
carrier[i] += in[i];
|
||||
carrier[i] *= ref[i] * gr_complex(0.5, 0);
|
||||
noise += std::pow(std::abs(d_H[i] - in[i]), 2);
|
||||
signal += std::pow(std::abs(d_H[i] + in[i]), 2);
|
||||
}
|
||||
|
||||
d_snr = 10 * std::log10(signal / noise / 2);
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
d_H[i] += in[i];
|
||||
d_H[i] /= LONG[i] * gr_complex(2, 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));
|
||||
symbols[c] = in[i] / d_H[i];
|
||||
bits[c] = mod->decision_maker(&symbols[c]);
|
||||
gr_complex point;
|
||||
mod->map_to_points(bits[c], &point);
|
||||
d_H[i] = gr_complex(1-alpha,0) * d_H[i] + gr_complex(alpha,0) * in[i] / point;
|
||||
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 };
|
||||
double
|
||||
lms::get_snr() {
|
||||
return d_snr;
|
||||
}
|
||||
|
||||
+7
-5
@@ -27,11 +27,14 @@ namespace equalizer {
|
||||
|
||||
class lms: public base {
|
||||
public:
|
||||
virtual void equalize(const gr_complex *in, gr_complex *out, int n);
|
||||
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod);
|
||||
private:
|
||||
gr_complex carrier[64];
|
||||
static const gr_complex ref[64];
|
||||
static const gr_complex POLARITY[127];
|
||||
double get_snr();
|
||||
|
||||
|
||||
gr_complex d_H[64];
|
||||
double d_snr;
|
||||
const double alpha = 0.5;
|
||||
};
|
||||
|
||||
} /* namespace channel_estimation */
|
||||
@@ -39,4 +42,3 @@ private:
|
||||
} /* namespace gr */
|
||||
|
||||
#endif /* INCLUDED_IEEE802_11_EQUALIZER_LMS_H */
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 "ls.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using namespace gr::ieee802_11::equalizer;
|
||||
|
||||
void ls::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) {
|
||||
|
||||
if(n == 0) {
|
||||
std::memcpy(d_H, in, 64 * sizeof(gr_complex));
|
||||
|
||||
} else if(n == 1) {
|
||||
double signal = 0;
|
||||
double noise = 0;
|
||||
for(int i = 0; i < 64; i++) {
|
||||
noise += std::pow(std::abs(d_H[i] - in[i]), 2);
|
||||
signal += std::pow(std::abs(d_H[i] + in[i]), 2);
|
||||
}
|
||||
|
||||
d_snr = 10 * std::log10(signal / noise / 2);
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
d_H[i] += in[i];
|
||||
d_H[i] /= LONG[i] * gr_complex(2, 0);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
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 {
|
||||
symbols[c] = in[i] / d_H[i];
|
||||
bits[c] = mod->decision_maker(&symbols[c]);
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double ls::get_snr() {
|
||||
return d_snr;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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_LS_H
|
||||
#define INCLUDED_IEEE802_11_EQUALIZER_LS_H
|
||||
|
||||
#include "base.h"
|
||||
#include <vector>
|
||||
|
||||
namespace gr {
|
||||
namespace ieee802_11 {
|
||||
namespace equalizer {
|
||||
|
||||
class ls: public base {
|
||||
public:
|
||||
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod);
|
||||
virtual double get_snr();
|
||||
private:
|
||||
gr_complex d_H[64];
|
||||
double d_snr;
|
||||
};
|
||||
|
||||
} /* namespace channel_estimation */
|
||||
} /* namespace ieee802_11 */
|
||||
} /* namespace gr */
|
||||
|
||||
#endif /* INCLUDED_IEEE802_11_EQUALIZER_LS_H */
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 "sta.h"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
using namespace gr::ieee802_11::equalizer;
|
||||
|
||||
void sta::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) {
|
||||
|
||||
if(n == 0) {
|
||||
std::memcpy(d_H, in, 64 * sizeof(gr_complex));
|
||||
|
||||
} else if(n == 1) {
|
||||
double signal = 0;
|
||||
double noise = 0;
|
||||
for(int i = 0; i < 64; i++) {
|
||||
noise += std::pow(std::abs(d_H[i] - in[i]), 2);
|
||||
signal += std::pow(std::abs(d_H[i] + in[i]), 2);
|
||||
}
|
||||
|
||||
d_snr = 10 * std::log10(signal / noise / 2);
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
d_H[i] += in[i];
|
||||
d_H[i] /= LONG[i] * gr_complex(2, 0);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
gr_complex H_update[64];
|
||||
gr_complex H[64];
|
||||
|
||||
gr_complex p = POLARITY[(n - 2) % 127];
|
||||
|
||||
H[11] = in[11] * p;
|
||||
H[25] = in[25] * p;
|
||||
H[39] = in[39] * p;
|
||||
H[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 {
|
||||
symbols[c] = in[i] / d_H[i];
|
||||
bits[c] = mod->decision_maker(&symbols[c]);
|
||||
gr_complex point;
|
||||
mod->map_to_points(bits[c], &point);
|
||||
H[i] = in[i] / point;
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
int n = 0;
|
||||
gr_complex s = 0;
|
||||
for(int k = i-beta; k <= i+beta; k++) {
|
||||
if((k == 32) || (k < 6) || ( k > 58)) {
|
||||
continue;
|
||||
}
|
||||
n++;
|
||||
s += H[k];
|
||||
}
|
||||
H_update[i] = s / gr_complex(n, 0);
|
||||
}
|
||||
|
||||
for(int i = 0; i < 64; i++) {
|
||||
d_H[i] = gr_complex(1-alpha,0) * d_H[i] + gr_complex(alpha,0) * H_update[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double
|
||||
sta::get_snr() {
|
||||
return d_snr;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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_STA_H
|
||||
#define INCLUDED_IEEE802_11_EQUALIZER_STA_H
|
||||
|
||||
#include "base.h"
|
||||
#include <vector>
|
||||
|
||||
namespace gr {
|
||||
namespace ieee802_11 {
|
||||
namespace equalizer {
|
||||
|
||||
class sta: public base {
|
||||
public:
|
||||
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod);
|
||||
double get_snr();
|
||||
|
||||
private:
|
||||
gr_complex d_H[64];
|
||||
double d_snr;
|
||||
|
||||
const double alpha = 0.5;
|
||||
const int beta = 2;
|
||||
};
|
||||
|
||||
} /* namespace channel_estimation */
|
||||
} /* namespace ieee802_11 */
|
||||
} /* namespace gr */
|
||||
|
||||
#endif /* INCLUDED_IEEE802_11_EQUALIZER_STA_H */
|
||||
Reference in New Issue
Block a user