Trait basic_dsp_vector::CrossCorrelationOps

source ·
pub trait CrossCorrelationOps<A, S, T, N, D>
where S: ToSliceMut<T>, T: RealNumber, N: NumberSpace, D: Domain, A: GetMetaData<T, N, D>,
{ // Required method fn correlate<B>(&mut self, buffer: &mut B, other: &A) -> VoidResult where B: for<'a> Buffer<'a, S, T>; }
Expand description

Cross-correlation of data vectors. See also https://en.wikipedia.org/wiki/Cross-correlation.

The correlation is calculated in two steps. This is done to give you more control over two things:

  1. Should the correlation use zero padding or not? This is done by calling either prepare_argument or prepare_argument_padded.
  2. The lifetime of the argument. The argument needs to be transformed for the correlation and depending on the application that might be just fine, or a clone needs to be created or it’s okay to use one argument for multiple correlations.

To get the same behavior like GNU Octave or MATLAB prepare_argument_padded needs to be called before doing the correlation. See also the example section for how to do this.

§Example

use std::f32;
use basic_dsp_vector::*;
let mut vector = vec!(Complex::new(1.0, 1.0), Complex::new(2.0, 2.0), Complex::new(3.0, 3.0)).to_complex_time_vec();
let argument = vec!(Complex::new(3.0, 3.0), Complex::new(2.0, 2.0), Complex::new(1.0, 1.0)).to_complex_time_vec();
let mut buffer = SingleBuffer::new();
let argument = argument.prepare_argument_padded(&mut buffer);
vector.correlate(&mut buffer, &argument).expect("Ignoring error handling in examples");
let expected = &[Complex::new(2.0, 0.0), Complex::new(8.0, 0.0), Complex::new(20.0, 0.0), Complex::new(24.0, 0.0), Complex::new(18.0, 0.0)];
for i in 0..vector.len() {
    assert!((vector[i] - expected[i]).norm() < 1e-4);
}

§Failures

TransRes may report the following ErrorReason members:

  1. VectorMustBeComplex: if self is in real number space.
  2. VectorMetaDataMustAgree: in case self and function are not in the same number space and same domain.

Required Methods§

source

fn correlate<B>(&mut self, buffer: &mut B, other: &A) -> VoidResult
where B: for<'a> Buffer<'a, S, T>,

Calculates the correlation between self and other. other needs to be a time vector which went through one of the prepare functions prepare_argument or prepare_argument_padded. See also the trait description for more details.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<S, T, N, D, DF, O, NO> CrossCorrelationOps<O, S, T, NO, DF> for DspVec<S, T, N, D>
where DspVec<S, T, N, D>: ScaleOps<T>, S: ToSliceMut<T>, T: RealNumber, N: ComplexNumberSpace, D: TimeDomain, DF: FrequencyDomain, O: Vector<T> + GetMetaData<T, NO, DF>, NO: PosEq<N> + NumberSpace,