Skip to content

Commit 8d3feb9

Browse files
committed
qpsk-demod: Exclude trailing noise from level and confidence
1 parent eed634c commit 8d3feb9

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

lib/iridium_qpsk_demod_impl.cc

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -183,50 +183,61 @@ float iridium_qpsk_demod_impl::qpskFirstOrderPLL(const gr_complex* x,
183183
size_t iridium_qpsk_demod_impl::demod_qpsk(
184184
const gr_complex* burst, size_t n_symbols, int* out, float* level, int* confidence)
185185
{
186-
int index;
187-
float sum = 0;
188186
float max = 0;
189187
int low_count = 0;
190-
int n_ok = 0;
188+
int n = 0;
189+
float offsets[n_symbols];
191190

192191
volk_32fc_magnitude_32f(d_magnitude_f, burst, n_symbols);
193192

194-
for (index = 0; index < n_symbols; index++) {
195-
sum += d_magnitude_f[index];
196-
if (max < d_magnitude_f[index]) {
197-
max = d_magnitude_f[index];
193+
for (int i = 0; i < n_symbols; i++) {
194+
if (max < d_magnitude_f[i]) {
195+
max = d_magnitude_f[i];
198196
}
199197

200198
// demodulating circuit
201-
if (burst[index].real() >= 0 && burst[index].imag() >= 0) {
202-
out[index] = d_symbol_mapping[0];
203-
} else if (burst[index].real() >= 0 && burst[index].imag() < 0) {
204-
out[index] = d_symbol_mapping[3];
205-
} else if (burst[index].real() < 0 && burst[index].imag() < 0) {
206-
out[index] = d_symbol_mapping[2];
199+
if (burst[i].real() >= 0 && burst[i].imag() >= 0) {
200+
out[i] = d_symbol_mapping[0];
201+
} else if (burst[i].real() >= 0 && burst[i].imag() < 0) {
202+
out[i] = d_symbol_mapping[3];
203+
} else if (burst[i].real() < 0 && burst[i].imag() < 0) {
204+
out[i] = d_symbol_mapping[2];
207205
} else {
208-
out[index] = d_symbol_mapping[1];
206+
out[i] = d_symbol_mapping[1];
209207
}
210208

211209
// Keep some quality estimate
212210
// If the phase is off too much, we lower the reported confidence
213-
int phase = (gr::fast_atan2f(burst[index]) + M_PI) * 180 / M_PI;
211+
int phase = (gr::fast_atan2f(burst[i]) + M_PI) * 180 / M_PI;
214212
int offset = 45 - (phase % 90);
215-
if (abs(offset) <= 22) {
216-
n_ok++;
217-
}
213+
offsets[i] = offset;
218214

219-
if (d_magnitude_f[index] < max / 8.) {
215+
n++;
216+
if (d_magnitude_f[i] < max / 8.) {
220217
low_count++;
221-
if (low_count > 2) {
218+
if (low_count == 3) {
219+
// We don't want to consider noise at the end of the frame
220+
n -= 3;
222221
break;
223222
}
223+
} else {
224+
low_count = 0;
225+
}
226+
}
227+
228+
int n_ok = 0;
229+
float sum = 0;
230+
231+
for (int i = 0; i < n; i++) {
232+
if (abs(offsets[i]) <= 22) {
233+
n_ok++;
224234
}
235+
sum += d_magnitude_f[i];
225236
}
226237

227-
*level = sum / index;
228-
*confidence = (int)(100. * n_ok / index);
229-
return index;
238+
*level = sum / n;
239+
*confidence = (int)(100. * n_ok / n);
240+
return n;
230241
}
231242

232243
void iridium_qpsk_demod_impl::decode_deqpsk(int* demodulated_burst, size_t n_symbols)

0 commit comments

Comments
 (0)