From 77f372050725535234d4cdedb308e006bbff2df4 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Fri, 11 Jul 2025 22:39:35 +0200 Subject: [PATCH] output min, median and max papr --- common.hh | 1 + encode.cc | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/common.hh b/common.hh index d219998..0f90071 100644 --- a/common.hh +++ b/common.hh @@ -16,6 +16,7 @@ struct Common static const int code_max = 16; static const int bits_max = 1 << code_max; static const int data_max = 4096; + static const int symbols_max = 44; static const int mls0_poly = 0x331; static const int mls0_seed = 214; static const int mls1_poly = 0x43; diff --git a/encode.cc b/encode.cc index 98d968d..aecfaea 100644 --- a/encode.cc +++ b/encode.cc @@ -11,6 +11,7 @@ Copyright 2021 Ahmet Inan #include "xorshift.hh" #include "complex.hh" #include "utils.hh" +#include "quick.hh" #include "bitman.hh" #include "decibel.hh" #include "fft.hh" @@ -41,7 +42,7 @@ struct Encoder : public Common cmplx prev[tone_count]; cmplx temp[tone_count]; value weight[guard_len]; - value worst_papr = -1000; + value papr[symbols_max]; static int bin(int carrier) { @@ -112,9 +113,9 @@ struct Encoder : public Common mean += power; } mean /= symbol_len; - value papr(peak / mean); - if (papr < best_papr) { - best_papr = papr; + value cand_papr(peak / mean); + if (cand_papr < best_papr) { + best_papr = cand_papr; for (int i = 0; differential && symbol_number >= 0 && i < tone_count; ++i) prev[i] = temp[i]; for (int i = 0; i < symbol_len; ++i) @@ -124,7 +125,7 @@ struct Encoder : public Common if (symbol_number >= 0) { for (int i = 0; i < symbol_len; ++i) tdom[i] = best[i]; - worst_papr = std::max(worst_papr, best_papr); + papr[symbol_number] = best_papr; } clipping_and_filtering(scale); if (symbol_number != -1) { @@ -292,9 +293,10 @@ struct Encoder : public Common } symbol(j); } + DSP::quick_sort(papr, symbol_count); + std::cerr << "PAPR (dB): " << std::fixed << std::setprecision(1) << DSP::decibel(papr[0]) << " .. " << DSP::decibel(papr[symbol_count/2]) << " .. " << DSP::decibel(papr[symbol_count-1]) << std::endl; } finish(); - std::cerr << "PAPR (dB): " << DSP::decibel(worst_papr) << std::endl; } };