pyecsca.sca.trace.align module

Provides functions for aligning traces in a trace set to a reference trace within it.

align_correlation(reference, *traces, reference_offset, reference_length, max_offset, min_correlation=0.5)[source]

Align traces to the reference trace using correlation.

Use the cross-correlation of a part of the reference trace starting at reference_offset with reference_length and try to match it to a part of the trace being matched that is at most max_offset mis-aligned from the reference, pick the alignment offset with the largest cross-correlation. If the maximum cross-correlation of the trace parts being matched is below min_correlation, do not include the trace.

Parameters:
  • reference (Trace) – Trace to align to.

  • traces (Trace) – Traces to align.

  • reference_offset (int) – Offset into the reference trace to start the aligning from.

  • reference_length (int) – Length of the part of the reference trace to align.

  • max_offset (int) – Maximum offset to try to align the traces by.

  • min_correlation (float) – Minimal correlation between the aligned trace and the reference trace.

Return type:

Tuple[List[Trace], List[int]]

Returns:

A tuple of: the list of the aligned traces (with the reference) and offsets used in alignment.

align_peaks(reference, *traces, reference_offset, reference_length, max_offset)[source]

Align traces to the reference trace using peaks.

Align so that the maximum value within the reference trace window from reference_offset of reference_length aligns with the maximum value of the trace being aligned within max_offset of the reference window.

Parameters:
  • reference (Trace) – Trace to align to.

  • traces (Trace) – Traces to align.

  • reference_offset (int) – Offset into the reference trace to start the aligning from.

  • reference_length (int) – Length of the part of the reference trace to align.

  • max_offset (int) – Maximum offset to try to align the traces by.

Return type:

Tuple[List[Trace], List[int]]

Returns:

A tuple of: the list of the aligned traces (with the reference) and offsets used in alignment.

align_offset(reference, *traces, reference_offset, reference_length, max_offset, dist_func, max_dist=inf)[source]

Align traces to the reference trace using a distance function.

Align so that the value of the dist_func is minimized between the reference trace window from reference_offset of reference_length and the trace being aligned within max_offset of the reference window.

Parameters:
  • reference (Trace) – Trace to align to.

  • traces (Trace) – Traces to align.

  • reference_offset (int) – Offset into the reference trace to start the aligning from.

  • reference_length (int) – Length of the part of the reference trace to align.

  • max_offset (int) – Maximum offset to try to align the traces by.

  • dist_func (Callable[[ndarray, ndarray], float]) – Distance function to use.

  • max_dist (float) – Maximum distance between the aligned trace and the reference trace.

Return type:

Tuple[List[Trace], List[int]]

Returns:

A tuple of: the list of the aligned traces (with the reference) and offsets used in alignment.

align_sad(reference, *traces, reference_offset, reference_length, max_offset)[source]

Align traces to the reference trace using Sum of Absolute Differences.

Align so that the Sum Of Absolute Differences between the reference trace window from reference_offset of reference_length and the trace being aligned within max_offset of the reference window is maximized.

Parameters:
  • reference (Trace) – Trace to align to.

  • traces (Trace) – Traces to align.

  • reference_offset (int) – Offset into the reference trace to start the aligning from.

  • reference_length (int) – Length of the part of the reference trace to align.

  • max_offset (int) – Maximum offset to try to align the traces by.

Return type:

Tuple[List[Trace], List[int]]

Returns:

A tuple of: the list of the aligned traces (with the reference) and offsets used in alignment.

align_dtw_scale(reference, *traces, radius=1, fast=True)[source]

Align traces to the reference trace.

Use fastdtw (Dynamic Time Warping) with scaling as per:

Jasper G. J. van Woudenberg, Marc F. Witteman, Bram Bakker: Improving Differential Power Analysis by Elastic Alignment

https://pdfs.semanticscholar.org/aceb/7c307098a414d7c384d6189226e4375cf02d.pdf

Parameters:
  • reference (Trace) – Trace to align to.

  • traces (Trace) – Traces to align.

  • radius (int)

  • fast (bool)

Return type:

List[Trace]

Returns:

List of the aligned traces (with the reference).

align_dtw(reference, *traces, radius=1, fast=True)[source]

Align traces to the reference trace.

Use fastdtw (Dynamic Time Warping) as per:

Stan Salvador, Philip Chan: FastDTW: Toward Accurate Dynamic Time Warping in Linear Time and Space

https://cs.fit.edu/~pkc/papers/tdm04.pdf

Parameters:
  • reference (Trace) – Trace to align to.

  • traces (Trace) – Traces to align.

  • radius (int)

  • fast (bool)

Return type:

List[Trace]

Returns:

List of the aligned traces (with the reference).