/// <summary> /// Computes the cross-correlation of a finite and a enumerable signal. /// </summary> /// <param name="s1">The finite signal.</param> /// <param name="s2">The enumerable signal.</param> /// <returns></returns> /// <exception cref="SamplerateMismatchException"></exception> public static IEnumerableSignal CrossCorrelate(this IFiniteSignal s1, IEnumerableSignal s2) { if (s1.SampleRate != s2.SampleRate) { throw new SamplerateMismatchException(); } return(new EnumerableSignal(Dsp.CrossCorrelate(s2.Signal, s1.Signal), s1.SampleRate, s1.Start - s2.Start) { DisplayName = "cross correlation" }); }
public void TestCrossCorrelate2() { Fft.FftProvider = new FftwProvider(); var x = new[] { 0.616044676146639, 0.473288848902729, 0.351659507062997, 0.830828627896291, 0.585264091152724, 0.549723608291140, 0.917193663829810, 0.285839018820374, 0.757200229110721, 0.753729094278495 }; var y = new[] { 0.380445846975357, 0.567821640725221, 0.075854289563064, 0.053950118666607, 0.530797553008973, 0.779167230102011, 0.934010684229183, 0.129906208473730, 0.568823660872193, 0.469390641058206 }; var target = new[] { 0.289165605456966, 0.572578144138708, 0.514311605265986, 1.226890899803151, 1.715053887382157, 1.723096881636733, 2.153707981735077, 2.180225109104805, 2.452308536614765, 2.991904576873709, 2.274857481454638, 2.194310061297180, 2.185291802257769, 1.609001416200661, 1.192553191608914, 0.609348760441016, 0.595874529034391, 0.716057373469512, 0.286753103662751 }; var result = Dsp.CrossCorrelate((IEnumerable <double>)x, y).ToReadOnlyList(); FilterAssert.ListsAreReasonablyClose(target, result); Assert.That(Dsp.CrossCorrelate(Enumerable.Empty <double>(), y).ToReadOnlyList().Count == 0); Assert.That(Dsp.CrossCorrelate((IEnumerable <double>)x, new List <double>()).ToReadOnlyList().Count == 0); Assert.Throws <ArgumentNullException>(() => Dsp.CrossCorrelate((IEnumerable <double>)null, y).ToReadOnlyList()); Assert.Throws <ArgumentNullException>(() => Dsp.CrossCorrelate((IEnumerable <double>)x, null).ToReadOnlyList()); }