public void CheckWithLinq(int channelCount, int sourceLength, int windowLength, int position)
        {
            var random = new Random(57);
            var source = new double[channelCount][];

            for (var ch = 0; ch < channelCount; ch++)
            {
                source[ch] = Enumerable.Range(0, sourceLength).Select(t => random.NextDouble()).ToArray();
            }
            var window = WindowFunctions.Hann(windowLength);

            var expected = new double[channelCount][];

            for (var ch = 0; ch < channelCount; ch++)
            {
                expected[ch] = source[ch].Skip(position).Take(windowLength).ToArray();
                for (var t = 0; t < expected.Length; t++)
                {
                    expected[ch][t] *= window[t];
                }
            }

            var actual = Framing.GetFrame(source, window, position);

            for (var ch = 0; ch < channelCount; ch++)
            {
                for (var t = 0; t < actual.Length; t++)
                {
                    Assert.AreEqual(expected[ch][t], actual[ch][t], 1.0E-9);
                }
            }
        }
Exemplo n.º 2
0
        [DataRow(10, 30, -20)]  // Source is shorter than frame
        public void CheckWithNaiveImplementation(int sourceLength, int windowLength, int position)
        {
            var random = new Random(57);
            var source = Enumerable.Range(0, sourceLength).Select(t => random.NextDouble()).ToArray();
            var window = WindowFunctions.Hann(windowLength);

            var expected = GetFrame_Naive(source, window, position);

            var actual = Framing.GetFrame(source, window, position);

            for (var t = 0; t < actual.Length; t++)
            {
                Assert.AreEqual(expected[t], actual[t], 1.0E-9);
            }
        }