Trait basic_dsp::CrossCorrelationOps [−][src]
pub trait CrossCorrelationOps<A, S, T, N, D> where
N: NumberSpace,
T: RealNumber,
S: ToSliceMut<T>,
D: Domain,
A: GetMetaData<T, N, D>, { fn correlate<B>(
&mut self,
buffer: &mut B,
other: &A
) -> Result<(), ErrorReason>
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:
- Should the correlation use zero padding or not? This is done by calling either
prepare_argumentorprepare_argument_padded. - 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:
VectorMustBeComplex: ifselfis in real number space.VectorMetaDataMustAgree: in caseselfandfunctionare not in the same number space and same domain.
Required methods
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.
Implementors
impl<S, T, N, D, DF, O, NO> CrossCorrelationOps<O, S, T, NO, DF> for DspVec<S, T, N, D> where
N: ComplexNumberSpace,
T: RealNumber,
S: ToSliceMut<T>,
O: Vector<T> + GetMetaData<T, NO, DF>,
D: TimeDomain,
NO: PosEq<N> + NumberSpace,
DF: FrequencyDomain,
DspVec<S, T, N, D>: ScaleOps<T>, [src]
impl<S, T, N, D, DF, O, NO> CrossCorrelationOps<O, S, T, NO, DF> for DspVec<S, T, N, D> where
N: ComplexNumberSpace,
T: RealNumber,
S: ToSliceMut<T>,
O: Vector<T> + GetMetaData<T, NO, DF>,
D: TimeDomain,
NO: PosEq<N> + NumberSpace,
DF: FrequencyDomain,
DspVec<S, T, N, D>: ScaleOps<T>, [src]impl<S, T, N, D, O, V> CrossCorrelationOps<O, S, T, N, D> for Matrix2xN<V, S, T> where
N: NumberSpace,
T: RealNumber,
V: CrossCorrelationOps<V, S, T, N, D> + GetMetaData<T, N, D> + Vector<T>,
S: ToSliceMut<T>,
O: Matrix<V, T> + GetMetaData<T, N, D>,
D: Domain, [src]
impl<S, T, N, D, O, V> CrossCorrelationOps<O, S, T, N, D> for Matrix2xN<V, S, T> where
N: NumberSpace,
T: RealNumber,
V: CrossCorrelationOps<V, S, T, N, D> + GetMetaData<T, N, D> + Vector<T>,
S: ToSliceMut<T>,
O: Matrix<V, T> + GetMetaData<T, N, D>,
D: Domain, [src]impl<S, T, N, D, O, V> CrossCorrelationOps<O, S, T, N, D> for Matrix3xN<V, S, T> where
N: NumberSpace,
T: RealNumber,
V: CrossCorrelationOps<V, S, T, N, D> + GetMetaData<T, N, D> + Vector<T>,
S: ToSliceMut<T>,
O: Matrix<V, T> + GetMetaData<T, N, D>,
D: Domain, [src]
impl<S, T, N, D, O, V> CrossCorrelationOps<O, S, T, N, D> for Matrix3xN<V, S, T> where
N: NumberSpace,
T: RealNumber,
V: CrossCorrelationOps<V, S, T, N, D> + GetMetaData<T, N, D> + Vector<T>,
S: ToSliceMut<T>,
O: Matrix<V, T> + GetMetaData<T, N, D>,
D: Domain, [src]impl<S, T, N, D, O, V> CrossCorrelationOps<O, S, T, N, D> for Matrix4xN<V, S, T> where
N: NumberSpace,
T: RealNumber,
V: CrossCorrelationOps<V, S, T, N, D> + GetMetaData<T, N, D> + Vector<T>,
S: ToSliceMut<T>,
O: Matrix<V, T> + GetMetaData<T, N, D>,
D: Domain, [src]
impl<S, T, N, D, O, V> CrossCorrelationOps<O, S, T, N, D> for Matrix4xN<V, S, T> where
N: NumberSpace,
T: RealNumber,
V: CrossCorrelationOps<V, S, T, N, D> + GetMetaData<T, N, D> + Vector<T>,
S: ToSliceMut<T>,
O: Matrix<V, T> + GetMetaData<T, N, D>,
D: Domain, [src]impl<S, T, N, D, O, V> CrossCorrelationOps<O, S, T, N, D> for MatrixMxN<V, S, T> where
N: NumberSpace,
T: RealNumber,
V: CrossCorrelationOps<V, S, T, N, D> + GetMetaData<T, N, D> + Vector<T>,
S: ToSliceMut<T>,
O: Matrix<V, T> + GetMetaData<T, N, D>,
D: Domain, [src]
impl<S, T, N, D, O, V> CrossCorrelationOps<O, S, T, N, D> for MatrixMxN<V, S, T> where
N: NumberSpace,
T: RealNumber,
V: CrossCorrelationOps<V, S, T, N, D> + GetMetaData<T, N, D> + Vector<T>,
S: ToSliceMut<T>,
O: Matrix<V, T> + GetMetaData<T, N, D>,
D: Domain, [src]