Commit c662bd3d authored by Stefan Westerfeld's avatar Stefan Westerfeld

Better normalization for the "all" pattern.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 30ac6799
...@@ -692,7 +692,7 @@ normalize_soft_bits (const vector<float>& soft_bits) ...@@ -692,7 +692,7 @@ normalize_soft_bits (const vector<float>& soft_bits)
vector<float> vector<float>
mix_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<float>>>& fft_orig_out, int n_channels) mix_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<float>>>& fft_orig_out, int n_channels)
{ {
vector<float> soft_bit_vec; vector<float> raw_bit_vec;
const int n_blocks = fft_out.size() / (Params::block_size * Params::frames_per_bit) / n_channels; const int n_blocks = fft_out.size() / (Params::block_size * Params::frames_per_bit) / n_channels;
for (int block = 0; block < n_blocks; block++) for (int block = 0; block < n_blocks; block++)
...@@ -725,19 +725,19 @@ mix_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<float ...@@ -725,19 +725,19 @@ mix_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<float
} }
if ((f % Params::frames_per_bit) == (Params::frames_per_bit - 1)) if ((f % Params::frames_per_bit) == (Params::frames_per_bit - 1))
{ {
soft_bit_vec.push_back (umag - dmag); raw_bit_vec.push_back (umag - dmag);
umag = 0; umag = 0;
dmag = 0; dmag = 0;
} }
} }
} }
return normalize_soft_bits (soft_bit_vec); return raw_bit_vec;
} }
vector<float> vector<float>
linear_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<float>>>& fft_orig_out, int n_channels) linear_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<float>>>& fft_orig_out, int n_channels)
{ {
vector<float> soft_bit_vec; vector<float> raw_bit_vec;
double umag = 0, dmag = 0; double umag = 0, dmag = 0;
const int frame_count = fft_out.size() / n_channels; const int frame_count = fft_out.size() / n_channels;
...@@ -768,12 +768,12 @@ linear_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<fl ...@@ -768,12 +768,12 @@ linear_decode (vector<vector<complex<float>>>& fft_out, vector<vector<complex<fl
} }
if ((f % Params::frames_per_bit) == (Params::frames_per_bit - 1)) if ((f % Params::frames_per_bit) == (Params::frames_per_bit - 1))
{ {
soft_bit_vec.push_back (umag - dmag); raw_bit_vec.push_back (umag - dmag);
umag = 0; umag = 0;
dmag = 0; dmag = 0;
} }
} }
return normalize_soft_bits (soft_bit_vec); return raw_bit_vec;
} }
double double
...@@ -957,8 +957,10 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern) ...@@ -957,8 +957,10 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern)
SyncFinder sync_finder; SyncFinder sync_finder;
vector<SyncFinder::Score> sync_scores = sync_finder.search (wav_data); vector<SyncFinder::Score> sync_scores = sync_finder.search (wav_data);
auto decode_single = [&] (vector<float> soft_bit_vec, SyncFinder::Score sync_score) auto decode_single = [&] (const vector<float>& raw_bit_vec, SyncFinder::Score sync_score)
{ {
vector<float> soft_bit_vec = normalize_soft_bits (raw_bit_vec);
/* truncate to the required length */ /* truncate to the required length */
assert (soft_bit_vec.size() >= conv_code_size (Params::payload_size)); assert (soft_bit_vec.size() >= conv_code_size (Params::payload_size));
soft_bit_vec.resize (conv_code_size (Params::payload_size)); soft_bit_vec.resize (conv_code_size (Params::payload_size));
...@@ -991,7 +993,7 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern) ...@@ -991,7 +993,7 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern)
total_count++; total_count++;
}; };
vector<float> soft_bit_vec_all (conv_code_size (Params::payload_size)); vector<float> raw_bit_vec_all (conv_code_size (Params::payload_size));
SyncFinder::Score score_all { 0, 0 }; SyncFinder::Score score_all { 0, 0 };
for (auto sync_score : sync_scores) for (auto sync_score : sync_scores)
...@@ -1004,29 +1006,26 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern) ...@@ -1004,29 +1006,26 @@ decode_and_report (const WavData& wav_data, const string& orig_pattern)
{ {
vector<vector<complex<float>>> junk; vector<vector<complex<float>>> junk;
vector<float> soft_bit_vec; vector<float> raw_bit_vec;
if (Params::mix) if (Params::mix)
{ {
soft_bit_vec = mix_decode (fft_range_out, junk, wav_data.n_channels()); raw_bit_vec = mix_decode (fft_range_out, junk, wav_data.n_channels());
} }
else else
{ {
soft_bit_vec = linear_decode (fft_range_out, junk, wav_data.n_channels()); raw_bit_vec = linear_decode (fft_range_out, junk, wav_data.n_channels());
} }
decode_single (soft_bit_vec, sync_score); decode_single (raw_bit_vec, sync_score);
score_all.quality += sync_score.quality; score_all.quality += sync_score.quality;
for (size_t i = 0; i < soft_bit_vec_all.size(); i++) for (size_t i = 0; i < raw_bit_vec_all.size(); i++)
soft_bit_vec_all[i] += soft_bit_vec[i]; raw_bit_vec_all[i] += raw_bit_vec[i];
} }
} }
if (total_count > 1) /* all pattern: average soft bits of all watermarks and decode */ if (total_count > 1) /* all pattern: average soft bits of all watermarks and decode */
{ {
score_all.quality /= total_count; score_all.quality /= total_count;
for (auto& sbit : soft_bit_vec_all) decode_single (raw_bit_vec_all, score_all);
sbit /= total_count;
decode_single (soft_bit_vec_all, score_all);
} }
if (!orig_pattern.empty()) if (!orig_pattern.empty())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment