ber_functions#

BER and bit and symbol stream calculation methods.

exception qampy.core.ber_functions.DataSyncError#
qampy.core.ber_functions.adjust_data_length(data_tx, data_rx, method=None, offset=0)#

Adjust the length of data_tx to match data_rx, either by truncation or repeating the data.

Parameters:
  • data_tx (array_like) – known input data sequence, received data sequence

  • data_rx (array_like) – known input data sequence, received data sequence

  • method (string, optional) –

    method to use for adjusting the length. This can be either None, “extend” or “truncate”. Description:

    ”extend” - pad the short array with its data from the beginning. This assumes that the data is periodic “truncate” - cut the shorter array to the length of the longer one None - (default) either truncate or extend data_tx

  • offset (int, optional) – offset where the start of the to extended array sits in the reference array

Returns:

data_tx_new, data_rx_new – adjusted data sequences

Return type:

array_like

qampy.core.ber_functions.cal_ber_nosyncd(data_rx, data_tx)#

Calculate the BER between a received bit stream and a known bit sequence which is not synchronised. If data_tx is shorter than data_rx it is assumed that data_rx is repetitive. This function automatically inverts the data if it fails to sync.

Parameters:
  • data_tx (array_like) – the known input data sequence.

  • data_rx (array_like) – the received data sequence which might contain errors.

  • Lsync (int) – the number of elements to use for syncing.

  • imax (imax, optional) – maximum number of tries before giving up (the default is 200).

Returns:

  • ber (float) – bit error rate in linear units

  • errs (int) – number of counted errors

  • N (int) – length of data

qampy.core.ber_functions.cal_ber_syncd(data_rx, data_tx, threshold=0.2)#

Calculate the bit-error rate (BER) between two synchronised binary data signals in linear units.

Parameters:
  • data_tx (array_like) – the known input data sequence.

  • data_rx (array_like) – the received data signal stream

  • threshold (float, optional) – threshold BER value. If calculated BER is larger than the threshold, an error is return as this likely indicates a wrong sync (default is 0.2).

Returns:

  • ber (float) – bit-error rate in linear units

  • errs (int) – number of counted errors.

  • N (int) – length of data_tx

Raises:

ValueError – if ber>threshold, as this indicates a sync error.

qampy.core.ber_functions.find_sequence_offset(x, y, show_cc=False)#

Find the time shift between two input signals that might contain errors might contain errors, using cross-correlation between data_rx and data_tx. Calculates np.fftconvolve(data_rx, data_tx, ‘same’). This calculates how data_rx has to be shifted to align with data_tx

Parameters:
  • x (array_like) – The first signal

  • y (array_like) – second signal, this is the signal that will need to be shifted

  • show_cc (bool, optional) – if true return the calculated crosscorrelation

Returns:

  • offset index (int) – the index to shift y in order to align both signals

  • crosscorrelation (array_like, optional) – the “full” crosscorrelation between x and y

qampy.core.ber_functions.find_sequence_offset_complex(x, y)#

Find the offset of one sequence in the other even if both sequences are complex.

Parameters:
  • x (array_like) – transmitted data sequence

  • y (array_like) – received data sequence

Returns:

  • idx (integer) – offset index

  • y (array_like) – y array possibly rotated to correct 1.j**i for complex arrays

  • ii (integer) – power for complex rotation angle 1.j**ii

qampy.core.ber_functions.sync_and_adjust(data_tx, data_rx, adjust='tx')#

Synchronize and adjust length of received and transmitted data sequence. When the length differs between sequences the sequence length will be adjusted based on the adjust parameter and the length of the sequences. If the to adjusting sequence is shorter than the other sequence, we will assume that the pattern is repetitive and therefore pad the sequence. If it is longer than the other sequence we will truncate after adjusting the offset. Note that if sequences are complex we will rotate around the complex plane to remove abiguities.

Parameters:
  • data_tx (array_like) – transmitted symbol or bit sequence

  • data_rx (array_like) – received symbol sequence can be noisy

  • adjust (string, optional) – parameter that determines which data sequence to adjust. If “tx” truncate or extend data_tx if “rx” truncate or extend data_rx

Returns:

  • tx (array_like) – (possibly adjusted) tx data

  • rx (array_like) – (possibly adjusted) rx data

qampy.core.ber_functions.sync_rx2tx(data_tx, data_rx, Lsync, imax=200)#

Sync the received data sequence to the transmitted data, which might contain errors. Starts to with data_rx[:Lsync] if it does not find the offset it will iterate through data[i*Lsync:Lsync*(i+1)] until offset is found or imax is reached.

Parameters:
  • data_tx (array_like) – the known input data sequence.

  • data_rx (array_like) – the received data sequence which might contain errors.

  • Lsync (int) – the number of elements to use for syncing.

  • imax (imax, optional) – maximum number of tries before giving up (the default is 200).

Returns:

  • offset index (int) – the index where data_rx starts in data_rx

  • data_rx_sync (array_like) – data_rx which is synchronized to data_tx

Raises:

DataSyncError – If no position can be found.

qampy.core.ber_functions.sync_tx2rx(data_tx, data_rx, Lsync, imax=200)#

Sync the transmitted data sequence to the received data, which might contain errors. Starts to with data_rx[:Lsync] if it does not find the offset it will iterate through data[i:Lsync+i] until offset is found or imax is reached.

Parameters:
  • data_tx (array_like) – the known input data sequence.

  • data_rx (array_like) – the received data sequence which might contain errors.

  • Lsync (int) – the number of elements to use for syncing.

  • imax (imax, optional) – maximum number of tries before giving up (the default is 200).

Returns:

  • offset index (int) – the index where data_rx starts in data_tx

  • data_tx_sync (array_like) – data_tx which is synchronized to data_rx

Raises:

DataSyncError – If no position can be found.