Trait basic_dsp_vector::CrossCorrelationArgumentOps[][src]

pub trait CrossCorrelationArgumentOps<S, T>: ToFreqResult where
    S: ToSliceMut<T>,
    T: RealNumber
{ fn prepare_argument<B>(self, buffer: &mut B) -> Self::FreqResult
    where
        B: for<'a> Buffer<'a, S, T>
;
fn prepare_argument_padded<B>(self, buffer: &mut B) -> Self::FreqResult
    where
        B: for<'a> Buffer<'a, S, T>
; }

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!(1.0, 1.0, 2.0, 2.0, 3.0, 3.0).to_complex_time_vec();
let argument = vec!(3.0, 3.0, 2.0, 2.0, 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 = &[2.0, 0.0, 8.0, 0.0, 20.0, 0.0, 24.0, 0.0, 18.0, 0.0];
for i in 0..vector.len() {
    assert!(f32::abs(vector[i] - expected[i]) < 1e-4);
}

Unstable

This functionality has been recently added in order to find out if the definitions are consistent. However the actual implementation is lacking tests.

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

Prepares an argument to be used for convolution. Preparing an argument includes two steps:

  1. Calculate the plain FFT
  2. Calculate the complex conjugate

Prepares an argument to be used for convolution. The argument is zero padded to length of 2 * self.points() - 1 and then the same operations are performed as described for prepare_argument.

Implementors