[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 04/09: Fixed an algorithmic problem with th
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 04/09: Fixed an algorithmic problem with the Viterbi decoder |
Date: |
Tue, 22 Jul 2014 19:33:56 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit dbbc0687b7323c86eb2b1c2d7524ff212bbd64d8
Author: Andrew F. Davis <address@hidden>
Date: Sat Jun 28 19:03:21 2014 -0400
Fixed an algorithmic problem with the Viterbi decoder
---
gr-dtv/lib/atsc_rs_decoder_impl.cc | 30 ++++++++++------------
gr-dtv/lib/atsc_rs_decoder_impl.h | 1 -
gr-dtv/lib/atsc_single_viterbi.cc | 44 +++++++++++++++------------------
gr-dtv/lib/atsc_single_viterbi.h | 11 +++++----
gr-dtv/lib/atsc_viterbi_decoder_impl.cc | 32 ++++++++++++------------
gr-dtv/lib/atsc_viterbi_decoder_impl.h | 3 +--
gr-dtv/python/dtv/atsc_rx.py | 2 +-
7 files changed, 57 insertions(+), 66 deletions(-)
diff --git a/gr-dtv/lib/atsc_rs_decoder_impl.cc
b/gr-dtv/lib/atsc_rs_decoder_impl.cc
index cd9588d..7fb6541 100644
--- a/gr-dtv/lib/atsc_rs_decoder_impl.cc
+++ b/gr-dtv/lib/atsc_rs_decoder_impl.cc
@@ -59,7 +59,6 @@ namespace gr {
nerrors_corrrected_count = 0;
bad_packet_count = 0;
total_packets = 0;
- reset_counter = 0;
}
int atsc_rs_decoder_impl::decode (atsc_mpeg_packet_no_sync &out, const
atsc_mpeg_packet_rs_encoded &in)
@@ -107,23 +106,20 @@ namespace gr {
bad_packet_count++;
else
nerrors_corrrected_count += nerrors_corrrected;
- }
- total_packets += noutput_items;
- reset_counter++;
-
- if (reset_counter > 100) {
- // FIXME: convert to logger
- std::cout << "Error rate: "
- << (float)nerrors_corrrected_count/total_packets
- << "\tPacket error rate: "
- << (float)bad_packet_count/total_packets
- << std::endl;
-
- nerrors_corrrected_count = 0;
- bad_packet_count = 0;
- total_packets = 0;
- reset_counter = 0;
+ total_packets++;
+ if (total_packets > 1000) {
+ // FIXME: convert to logger
+ std::cout << "Error rate: "
+ << (float)nerrors_corrrected_count/total_packets
+ << "\tPacket error rate: "
+ << (float)bad_packet_count/total_packets
+ << std::endl;
+
+ nerrors_corrrected_count = 0;
+ bad_packet_count = 0;
+ total_packets = 0;
+ }
}
return noutput_items;
diff --git a/gr-dtv/lib/atsc_rs_decoder_impl.h
b/gr-dtv/lib/atsc_rs_decoder_impl.h
index 691d619..5746012 100644
--- a/gr-dtv/lib/atsc_rs_decoder_impl.h
+++ b/gr-dtv/lib/atsc_rs_decoder_impl.h
@@ -39,7 +39,6 @@ namespace gr {
int nerrors_corrrected_count;
int bad_packet_count;
int total_packets;
- int reset_counter;
void *d_rs;
public:
diff --git a/gr-dtv/lib/atsc_single_viterbi.cc
b/gr-dtv/lib/atsc_single_viterbi.cc
index d8374ca..385940e 100644
--- a/gr-dtv/lib/atsc_single_viterbi.cc
+++ b/gr-dtv/lib/atsc_single_viterbi.cc
@@ -28,39 +28,31 @@ namespace gr {
/* was_sent is a table of what symbol we get given what bit pair
was sent and what state we where in [state][pair] */
- const int atsc_single_viterbi::was_sent[8][4] = {
- {0,2,0,2},
- {0,2,0,2},
- {1,3,1,3},
- {1,3,1,3},
- {4,6,4,6},
- {4,6,4,6},
- {5,7,5,7},
- {5,7,5,7}
+ const int atsc_single_viterbi::was_sent[4][4] = {
+ {0,2,4,6},
+ {0,2,4,6},
+ {1,3,5,7},
+ {1,3,5,7},
};
/* transition_table is a table of what state we were in
given current state and bit pair sent [state][pair] */
- const int atsc_single_viterbi::transition_table[8][4] = {
- {0,2,4,6},
- {2,0,6,4},
- {1,3,5,7},
- {3,1,7,5},
- {4,6,0,2},
- {6,4,2,0},
- {5,7,1,3},
- {7,5,3,1}
+ const int atsc_single_viterbi::transition_table[4][4] = {
+ {0,2,0,2},
+ {2,0,2,0},
+ {1,3,1,3},
+ {3,1,3,1},
};
void
atsc_single_viterbi::reset()
{
for (unsigned int i = 0; i<2; i++)
- for (unsigned int j = 0; j<8; j++) {
+ for (unsigned int j = 0; j<4; j++) {
path_metrics[i][j] = 0;
traceback[i][j] = 0;
}
-
+ post_coder_state = 0;
phase = 0;
}
@@ -81,8 +73,8 @@ namespace gr {
(float)fabs( input - 1 ), (float)fabs( input - 3
),
(float)fabs( input - 5 ), (float)fabs( input - 7
) };
- /* We start by iterating over all possible states */
- for (unsigned int state = 0; state < 8; state++) {
+ /* We start by iterating over all possible states */
+ for (unsigned int state = 0; state < 4; state++) {
/* Next we find the most probable path from the previous
states to the state we are testing, we only need to look at
the 4 paths that can be taken given the 2-bit input */
@@ -113,12 +105,16 @@ namespace gr {
}
if(best_state_metric > 10000) {
- for(unsigned int state = 0; state < 8; state++)
+ for(unsigned int state = 0; state < 4; state++)
path_metrics[phase^1][state] -= best_state_metric;
}
phase ^= 1;
- return (0x3 & traceback[phase][best_state]);
+ int y2 = (0x2 & traceback[phase][best_state]) >> 1;
+ int x2 = y2 ^ post_coder_state;
+ post_coder_state = y2;
+
+ return ( x2 << 1 ) | (0x1 & traceback[phase][best_state]);
}
} /* namespace dtv */
diff --git a/gr-dtv/lib/atsc_single_viterbi.h b/gr-dtv/lib/atsc_single_viterbi.h
index 4f71369..3c756c7 100644
--- a/gr-dtv/lib/atsc_single_viterbi.h
+++ b/gr-dtv/lib/atsc_single_viterbi.h
@@ -42,15 +42,16 @@ namespace gr {
void reset ();
//! internal delay of decoder
- int delay () { return TB_LEN - 1; }
+ static int delay () { return TB_LEN - 1; }
protected:
- static const int transition_table[8][4];
- static const int was_sent[8][4];
+ static const int transition_table[4][4];
+ static const int was_sent[4][4];
- float path_metrics [2][8];
- unsigned long long traceback [2][8];
+ float path_metrics [2][4];
+ unsigned long long traceback [2][4];
unsigned char phase;
+ int post_coder_state;
};
} /* namespace dtv */
diff --git a/gr-dtv/lib/atsc_viterbi_decoder_impl.cc
b/gr-dtv/lib/atsc_viterbi_decoder_impl.cc
index 6c093e2..8e9cbc0 100644
--- a/gr-dtv/lib/atsc_viterbi_decoder_impl.cc
+++ b/gr-dtv/lib/atsc_viterbi_decoder_impl.cc
@@ -28,6 +28,7 @@
#include "atsc_viterbi_decoder_impl.h"
#include "atsc_types.h"
#include <atsc_viterbi_mux.cc> // machine generated
+#include <emmintrin.h>
namespace gr {
namespace dtv {
@@ -45,7 +46,6 @@ namespace gr {
io_signature::make(1, 1,
sizeof(atsc_mpeg_packet_rs_encoded)))
{
set_output_multiple(NCODERS);
- debug = true;
/*
* These fifo's handle the alignment problem caused by the
@@ -58,7 +58,7 @@ namespace gr {
*/
// the -4 is for the 4 sync symbols
- int fifo_size = ATSC_DATA_SEGMENT_LENGTH - 4 - viterbi[0].delay ();
+ int fifo_size = ATSC_DATA_SEGMENT_LENGTH - 4 - viterbi[0].delay();
for (int i = 0; i < NCODERS; i++)
fifo[i] = new fifo_t(fifo_size);
@@ -74,10 +74,8 @@ namespace gr {
void
atsc_viterbi_decoder_impl::reset()
{
- for (int i = 0; i < NCODERS; i++) {
- viterbi[i].reset();
+ for (int i = 0; i < NCODERS; i++)
fifo[i]->reset();
- }
}
int
@@ -93,32 +91,34 @@ namespace gr {
// 12, so we should always get a mod 12 numbered first packet
assert(noutput_items % NCODERS == 0);
- int encoder;
int dbwhere;
int dbindex;
int shift;
- unsigned char dibit;
- float symbol;
+ float symbols[NCODERS][enco_which_max];
+ unsigned char dibits[NCODERS][enco_which_max];
unsigned char out_copy[OUTPUT_SIZE];
for (int i = 0; i < noutput_items; i += NCODERS) {
+ /* Build a continuous symbol buffer for each encoder */
+ for (unsigned int encoder = 0; encoder < NCODERS; encoder++)
+ for (unsigned int k = 0; k < enco_which_max; k++)
+ symbols[encoder][k] = in[i +
(enco_which_syms[encoder][k]/832)].data[enco_which_syms[encoder][k] % 832];
+
/* Now run each of the 12 Viterbi decoders over their subset of
the input symbols */
- for (encoder = 0; encoder < NCODERS; encoder++) {
- fifo_t *dibit_fifo = fifo[encoder];
+ for (unsigned int encoder = 0; encoder < NCODERS; encoder++)
+ for (unsigned int k = 0; k < enco_which_max; k++)
+ dibits[encoder][k] = viterbi[encoder].decode(symbols[encoder][k]);
- /* Feed all the incoming symbols into one decoder;
- pump them into the relevant dibits. */
+ /* Move dibits into their location in the output buffer */
+ for (unsigned int encoder = 0; encoder < NCODERS; encoder++) {
for (unsigned int k = 0; k < enco_which_max; k++) {
- symbol = in[i +
(enco_which_syms[encoder][k]/832)].data[enco_which_syms[encoder][k] % 832];
- dibit = dibit_fifo->stuff(viterbi[encoder].decode(symbol));
-
/* Store the dibit into the output data segment */
dbwhere = enco_which_dibits[encoder][k];
dbindex = dbwhere >> 3;
shift = dbwhere & 0x7;
- out_copy[dbindex] = (out_copy[dbindex] & ~(0x03 << shift)) |
(dibit << shift);
+ out_copy[dbindex] = (out_copy[dbindex] & ~(0x03 << shift)) |
(fifo[encoder]->stuff(dibits[encoder][k]) << shift);
} /* Symbols fed into one encoder */
} /* Encoders */
diff --git a/gr-dtv/lib/atsc_viterbi_decoder_impl.h
b/gr-dtv/lib/atsc_viterbi_decoder_impl.h
index 37b988f..b4fbbd1 100644
--- a/gr-dtv/lib/atsc_viterbi_decoder_impl.h
+++ b/gr-dtv/lib/atsc_viterbi_decoder_impl.h
@@ -57,8 +57,7 @@ namespace gr {
static const int INPUT_SIZE = (ATSC_DATA_SEGMENT_LENGTH * 12);
single_viterbi_t viterbi[NCODERS];
- fifo_t *fifo[NCODERS];
- bool debug;
+ fifo_t *fifo[NCODERS];
public:
atsc_viterbi_decoder_impl();
diff --git a/gr-dtv/python/dtv/atsc_rx.py b/gr-dtv/python/dtv/atsc_rx.py
index 9ca93fb..590e5f0 100644
--- a/gr-dtv/python/dtv/atsc_rx.py
+++ b/gr-dtv/python/dtv/atsc_rx.py
@@ -36,7 +36,7 @@ class atsc_rx(gr.hier_block2):
pll = dtv.atsc_fpll(output_rate)
# Remove pilot tone now at DC
- dcr = filter.dc_blocker_ff(1024)
+ dcr = filter.dc_blocker_ff(4096)
# Normalize signal to proper constellation amplitude
agc = analog.agc_ff(1e-5, 4.0)
- [Commit-gnuradio] [gnuradio] branch master updated (d09b971 -> d56fffb), git, 2014/07/22
- [Commit-gnuradio] [gnuradio] 05/09: dtv: move ATSC blocks into lib/atsc, git, 2014/07/22
- [Commit-gnuradio] [gnuradio] 02/09: dtv: adds remainder of atsc receive pipeline, git, 2014/07/22
- [Commit-gnuradio] [gnuradio] 03/09: dtv: misc. stylistic cleanup, add missing blocks to GRC block tree, git, 2014/07/22
- [Commit-gnuradio] [gnuradio] 09/09: Merge branch 'dtv', git, 2014/07/22
- [Commit-gnuradio] [gnuradio] 04/09: Fixed an algorithmic problem with the Viterbi decoder,
git <=
- [Commit-gnuradio] [gnuradio] 07/09: dtv: lowered nfilts for ATSC receiver filter for performance reasons, git, 2014/07/22
- [Commit-gnuradio] [gnuradio] 06/09: dtv: minor cleanups, git, 2014/07/22
- [Commit-gnuradio] [gnuradio] 08/09: dtv: added some example receivers, git, 2014/07/22
- [Commit-gnuradio] [gnuradio] 01/09: dtv: wip, porting gr-atsc blocks into new gr-dtv, git, 2014/07/22