Beispiel #1
0
        public static IEnumerable <string> CompareSamplingRates()
        {
            const float filterFrequency = 150;
            const float frameSizeInS    = 0.1f;
            var         sampleRates     = new[] { 600, 8000, 48000 };
            var         hammings        = sampleRates.Select(sr => FFTWindowBuilder.Hamming((int)(sr * frameSizeInS))).ToArray();
            var         responses       = new float[sampleRates.Length];

            for (int i = 1; i < 300; i++)
            {
                for (int j = 0; j < sampleRates.Length; j++)
                {
                    var signal = SignalGenerator.Sinus(sampleRates[j], frameSizeInS, i).ToArray();
                    responses[j] = GoertzelMag(signal, sampleRates[j], filterFrequency, hammings[j], out _);
                }

                yield return($"{i};" + string.Join(";", responses.Select(r => r.ToString(CultureInfo.InvariantCulture))));
            }
        }
Beispiel #2
0
        public static IEnumerable <string> CompareFrameSizes()
        {
            const float filterFrequency = 150;
            var         frameSizesInS   = new float[] { 0.1f, 0.5f };
            var         sampleRate      = 48000;
            var         hammings        = frameSizesInS.Select(fs => FFTWindowBuilder.Hamming((int)(fs * sampleRate))).ToArray();
            var         responses       = new float[frameSizesInS.Length];

            for (int i = 1; i < 300; i++)
            {
                for (int j = 0; j < frameSizesInS.Length; j++)
                {
                    var signal = SignalGenerator.Sinus(sampleRate, frameSizesInS[j], i).ToArray();
                    responses[j] = GoertzelMag(signal, sampleRate, filterFrequency, hammings[j], out _);
                }

                yield return($"{i};" + string.Join(";", responses.Select(r => r.ToString(CultureInfo.InvariantCulture))));
            }
        }
Beispiel #3
0
        public static IEnumerable <string> CompareFilterWindows()
        {
            const float filterFrequency = 150;
            const float frameSizeInS    = 0.1f;
            const int   sampleRate      = 48000;
            int         windowSize      = (int)(frameSizeInS * sampleRate);
            var         windows         = new[] {
                FFTWindowBuilder.Blackmann(windowSize),
                FFTWindowBuilder.Hamming(windowSize),
                FFTWindowBuilder.Hann(windowSize),
                FFTWindowBuilder.Door(windowSize)
            };
            var responses = new float[windows.Length];

            for (int i = 1; i < 300; i++)
            {
                var signal = SignalGenerator.Sinus(sampleRate, frameSizeInS, i).ToArray();
                for (int j = 0; j < windows.Length; j++)
                {
                    responses[j] = GoertzelMag(signal, sampleRate, filterFrequency, windows[j], out _);
                }
                yield return($"{i};" + string.Join(";", responses.Select(r => r.ToString(CultureInfo.InvariantCulture))));
            }
        }