Пример #1
0
        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 Complex[channelCount][];

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

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

            for (var ch = 0; ch < channelCount; ch++)
            {
                for (var t = 0; t < actual.Length; t++)
                {
                    Assert.AreEqual(expected[ch][t].Real, actual[ch][t].Real, 1.0E-9);
                    Assert.AreEqual(expected[ch][t].Imaginary, actual[ch][t].Imaginary, 1.0E-9);
                }
            }
        }
        [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 = GetFrameComplex_Naive(source, window, position);

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

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