[][src]Trait basic_dsp::CrossCorrelationArgumentOps

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

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

fn prepare_argument<B>(self, buffer: &mut B) -> Self::FreqResult where
    B: Buffer<'a, S, T>, 

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

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

fn prepare_argument_padded<B>(self, buffer: &mut B) -> Self::FreqResult where
    B: Buffer<'a, S, T>, 

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.

Loading content...

Implementors

impl<S, T, N, D> CrossCorrelationArgumentOps<S, T> for DspVec<S, T, N, D> where
    D: TimeDomain,
    N: ComplexNumberSpace,
    S: ToSliceMut<T>,
    T: RealNumber,
    DspVec<S, T, N, D>: ToFreqResult,
    DspVec<S, T, N, D>: TimeToFrequencyDomainOperations<S, T>,
    <DspVec<S, T, N, D> as ToFreqResult>::FreqResult: FrequencyDomainOperations<S, T>,
    <DspVec<S, T, N, D> as ToFreqResult>::FreqResult: ComplexOps<T>, 
[src]

impl<V, S, T> CrossCorrelationArgumentOps<S, T> for Matrix2xN<V, S, T> where
    S: ToSliceMut<T>,
    T: RealNumber,
    V: Vector<T> + CrossCorrelationArgumentOps<S, T>,
    <V as ToFreqResult>::FreqResult: Vector<T>, 
[src]

impl<V, S, T> CrossCorrelationArgumentOps<S, T> for Matrix3xN<V, S, T> where
    S: ToSliceMut<T>,
    T: RealNumber,
    V: Vector<T> + CrossCorrelationArgumentOps<S, T>,
    <V as ToFreqResult>::FreqResult: Vector<T>, 
[src]

impl<V, S, T> CrossCorrelationArgumentOps<S, T> for Matrix4xN<V, S, T> where
    S: ToSliceMut<T>,
    T: RealNumber,
    V: Vector<T> + CrossCorrelationArgumentOps<S, T>,
    <V as ToFreqResult>::FreqResult: Vector<T>, 
[src]

impl<V, S, T> CrossCorrelationArgumentOps<S, T> for MatrixMxN<V, S, T> where
    S: ToSliceMut<T>,
    T: RealNumber,
    V: Vector<T> + CrossCorrelationArgumentOps<S, T>,
    <V as ToFreqResult>::FreqResult: Vector<T>, 
[src]

Loading content...