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:
- Should the correlation use zero padding or not? This is done by calling either
prepare_argument
orprepare_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!(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:
VectorMustBeComplex
: ifself
is in real number space.VectorMetaDataMustAgree
: in caseself
andfunction
are not in the same number space and same domain.
Required Methods
fn prepare_argument<B>(self, buffer: &mut B) -> Self::FreqResult where
B: for<'a> Buffer<'a, S, T>,
B: for<'a> Buffer<'a, S, T>,
Prepares an argument to be used for convolution. Preparing an argument includes two steps:
- Calculate the plain FFT
- Calculate the complex conjugate
fn prepare_argument_padded<B>(self, buffer: &mut B) -> Self::FreqResult where
B: for<'a> Buffer<'a, S, T>,
B: for<'a> 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
.
Implementors
impl<S, T, N, D> CrossCorrelationArgumentOps<S, T> for DspVec<S, T, N, D> where
DspVec<S, T, N, D>: ToFreqResult + TimeToFrequencyDomainOperations<S, T>,
<DspVec<S, T, N, D> as ToFreqResult>::FreqResult: FrequencyDomainOperations<S, T> + ComplexOps<T>,
S: ToSliceMut<T>,
T: RealNumber,
N: ComplexNumberSpace,
D: TimeDomain,