Inheritance: SpectrogramConfig
        public float[][] CreateSpectrogram(AudioSamples audioSamples, int overlap, int wdftSize)
        {
            float[] window = new DefaultSpectrogramConfig().Window.GetWindow(wdftSize);
            float[] samples = audioSamples.Samples;
            int width = (samples.Length - wdftSize) / overlap;
            float[][] frames = new float[width][];
            for (int i = 0; i < width; i++)
            {
                float[] complexSignal = fftService.FFTForward(samples, i * overlap, wdftSize, window);
                float[] band = new float[(wdftSize / 2) + 1];
                for (int j = 0; j < (wdftSize / 2) + 1; j++)
                {
                    double re = complexSignal[2 * j];
                    double img = complexSignal[(2 * j) + 1];

                    re /= (float)wdftSize / 2;
                    img /= (float)wdftSize / 2;

                    band[j] = (float)((re * re) + (img * img));
                }

                frames[i] = band;
            }

            return frames;
        }
Exemplo n.º 2
0
 public LomontFFT()
 {
     A = 0;
     B = 1;
     var config = new DefaultSpectrogramConfig();
     Initialize(config.WdftSize);
 }
 public DefaultFingerprintConfiguration()
 {
     SpectrogramConfig = new DefaultSpectrogramConfig();
     HashingConfig = new DefaultHashingConfig();
     TopWavelets = 200;
     SampleRate = 5512;
     NormalizeSignal = false;
     Clusters = Enumerable.Empty<string>();
 }
        public void CreateLogSpectrogramFromSamplesLessThanFourierTransformWindowLength()
        {
            var configuration = new DefaultSpectrogramConfig();
            var samples = TestUtilities.GenerateRandomAudioSamples(configuration.WdftSize - 1);

            var result = spectrumService.CreateLogSpectrogram(samples, configuration);

            Assert.AreEqual(0, result.Count);
        }
 public DefaultFingerprintConfiguration()
 {
     SpectrogramConfig = new DefaultSpectrogramConfig();
     HashingConfig     = new DefaultHashingConfig();
     TopWavelets       = 200;
     SampleRate        = 5512;
     NormalizeSignal   = false;
     Clusters          = Enumerable.Empty <string>();
 }
 public DefaultFingerprintConfiguration()
 {
     SpectrogramConfig = new DefaultSpectrogramConfig();
     HashingConfig     = new DefaultHashingConfig();
     TopWavelets       = 200;
     SampleRate        = 5512;
     HaarWaveletNorm   = System.Math.Sqrt(2);
     Clusters          = Enumerable.Empty <string>();
 }
Exemplo n.º 7
0
 public DefaultFingerprintConfiguration()
 {
     SpectrogramConfig          = new DefaultSpectrogramConfig();
     HashingConfig              = new DefaultHashingConfig();
     TopWavelets                = 200;
     SampleRate                 = 5512;
     HaarWaveletNorm            = System.Math.Sqrt(2);
     FingerprintLengthInSeconds = (double)SamplesPerFingerprint / SampleRate;
     OriginalPointSaveTransform = null;
 }
        public void CutLogarithmizedSpectrumOfJustOneFingerprintTest()
        {
            var stride = new StaticStride(0, 0);
            var configuration = new DefaultSpectrogramConfig { Stride = stride };
            int logSpectrumLength = configuration.ImageLength; // 128
            var logSpectrum = GetLogSpectrum(logSpectrumLength);

            var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, SampleRate, configuration);

            Assert.AreEqual(1, cutLogarithmizedSpectrum.Count);
        }
        public void CreateLogSpectrogramFromMinimalSamplesLengthTest()
        {
            var configuration = new DefaultSpectrogramConfig { NormalizeSignal = false };
            var samples = TestUtilities.GenerateRandomAudioSamples(new DefaultFingerprintConfiguration().SamplesPerFingerprint + configuration.WdftSize); // 8192 + 2048
            SetupFftService(configuration, samples);

            var result = spectrumService.CreateLogSpectrogram(samples, configuration);

            logUtility.Verify(utility => utility.GenerateLogFrequenciesRanges(SampleRate, configuration), Times.Once());
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(configuration.ImageLength, result[0].Image.Length);
        }
Exemplo n.º 10
0
 public DefaultFingerprintConfiguration()
 {
     SpectrogramConfig           = new DefaultSpectrogramConfig();
     HashingConfig               = new DefaultHashingConfig();
     TopWavelets                 = 200;
     SampleRate                  = 5512;
     HaarWaveletNorm             = Math.Sqrt(2);
     FingerprintLengthInSeconds  = (double)SamplesPerFingerprint / SampleRate;
     OriginalPointSaveTransform  = (_ => Array.Empty <byte>());
     GaussianBlurConfiguration   = GaussianBlurConfiguration.None;
     FrameNormalizationTransform = new LogSpectrumNormalization();
 }
        public void CreateLogSpectrogramTest()
        {
            var configuration = new DefaultSpectrogramConfig { ImageLength = 2048 };
            var samples = TestUtilities.GenerateRandomAudioSamples((configuration.Overlap * configuration.WdftSize) + configuration.WdftSize); // 64 * 2048
            SetupFftService(configuration, samples);

            var result = spectrumService.CreateLogSpectrogram(samples, configuration);

            logUtility.Verify(utility => utility.GenerateLogFrequenciesRanges(SampleRate, configuration), Times.Once());
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(configuration.WdftSize, result[0].Image.Length);
            Assert.AreEqual(32, result[0].Image[0].Length);
        }
        public void CutLogarithmizedSpectrumTest()
        {
            var stride = new StaticStride(0, 0);
            var configuration = new DefaultSpectrogramConfig { Stride = stride };
            const int LogSpectrumLength = 1024;
            var logSpectrum = GetLogSpectrum(LogSpectrumLength);

            var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, SampleRate, configuration);

            Assert.AreEqual(8, cutLogarithmizedSpectrum.Count);
            double lengthOfOneFingerprint = (double)configuration.ImageLength * configuration.Overlap / SampleRate;
            for (int i = 0; i < cutLogarithmizedSpectrum.Count; i++)
            {
                Assert.IsTrue(
                    System.Math.Abs(cutLogarithmizedSpectrum[i].StartsAt - (i * lengthOfOneFingerprint)) < Epsilon);
            }
        }
        public void GenerateLogFrequenciesRangesTest()
        {
            var defaultConfig = new DefaultSpectrogramConfig { UseDynamicLogBase = false, LogBase = 10 };
            float[] logSpacedFrequencies = new[] // generated in matlab with logspace(2.50242712, 3.3010299957, 33)
                {
                    318.00f, 336.81f, 356.73f, 377.83f, 400.18f, 423.85f, 448.92f, 475.47f, 503.59f, 533.38f, 564.92f,
                    598.34f, 633.73f, 671.21f, 710.91f, 752.96f, 797.50f, 844.67f, 894.63f, 947.54f, 1003.58f, 1062.94f,
                    1125.81f, 1192.40f, 1262.93f, 1337.63f, 1416.75f, 1500.54f, 1589.30f, 1683.30f, 1782.86f, 1888.31f,
                    2000f
                };

            int[] indexes = logUtility.GenerateLogFrequenciesRanges(defaultFingerprintConfiguration.SampleRate, defaultConfig);

            for (int i = 0; i < logSpacedFrequencies.Length; i++)
            {
                var logSpacedFrequency = logSpacedFrequencies[i];
                int index = logUtility.FrequencyToSpectrumIndex(logSpacedFrequency, defaultFingerprintConfiguration.SampleRate, defaultConfig.WdftSize);
                Assert.AreEqual(index, indexes[i]);
            }
        }
        public void CutLogarithmizedSpectrumWithSpectrumWhichIsLessThanMinimalLengthOfOneFingerprintTest()
        {
            var stride = new StaticStride(0, 0);
            var config = new DefaultSpectrogramConfig { Stride = stride };
            int logSpectrumLength = config.ImageLength - 1;
            var logSpectrum = GetLogSpectrum(logSpectrumLength);

            var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, SampleRate, config);

            Assert.AreEqual(0, cutLogarithmizedSpectrum.Count);
        }
        public void ShouldCreateCorrectNumberOfSubFingerprints()
        {
            var configuration = new DefaultSpectrogramConfig { Stride = new StaticStride(0) };
            var tenMinutes = 10 * 60;
            var samples = TestUtilities.GenerateRandomAudioSamples(tenMinutes * SampleRate);
            SetupFftService(configuration, samples);

            var result = spectrumService.CreateLogSpectrogram(samples, configuration);

            Assert.AreEqual((tenMinutes * SampleRate) / (configuration.ImageLength * configuration.Overlap), result.Count);
        }
 private void SetupFftService(DefaultSpectrogramConfig configuration, AudioSamples samples)
 {
     logUtility.Setup(utility => utility.GenerateLogFrequenciesRanges(SampleRate, configuration))
         .Returns(new[]
                 {
                     118, 125, 133, 141, 149, 158, 167, 177, 187, 198, 210, 223, 236, 250, 264, 280, 297, 314,
                     333, 352, 373, 395, 419, 443, 470, 497, 527, 558, 591, 626, 663, 702, 744,
                 });
     fftService.Setup(service => service.FFTForward(samples.Samples, It.IsAny<int>(), configuration.WdftSize, It.IsAny<float[]>()))
         .Returns(TestUtilities.GenerateRandomFloatArray(2048));
 }
        public void CutLogarithmizedSpectrumWithDefaultStride()
        {
            var config = new DefaultSpectrogramConfig();
            int logSpectrumlength = config.ImageLength * 10;
            var logSpectrum = GetLogSpectrum(logSpectrumlength);

            var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, SampleRate, config);

            // Default stride between 2 consecutive images is 1536, but because of rounding issues and the fact
            // that minimal step is 11.6 ms, timestamp is roughly .37155 sec
            const double TimestampOfFingerprints = (double)1536 / SampleRate;
            Assert.AreEqual(49, cutLogarithmizedSpectrum.Count);
            for (int i = 0; i < cutLogarithmizedSpectrum.Count; i++)
            {
                Assert.IsTrue(System.Math.Abs(cutLogarithmizedSpectrum[i].StartsAt - (i * TimestampOfFingerprints)) < Epsilon);
            }
        }
        public void CutLogarithmizedSpectrumWithAnIncrementalStaticStride()
        {
            var stride = new IncrementalStaticStride(new DefaultFingerprintConfiguration().SamplesPerFingerprint / 2);
            var config = new DefaultSpectrogramConfig { Stride = stride };
            int logSpectrumLength = (config.ImageLength * 24) + config.Overlap;
            var logSpectrum = GetLogSpectrum(logSpectrumLength);

            var cutLogarithmizedSpectrum = spectrumService.CutLogarithmizedSpectrum(logSpectrum, SampleRate, config);

            Assert.AreEqual(48, cutLogarithmizedSpectrum.Count);
            double lengthOfOneFingerprint = (double)config.ImageLength * config.Overlap / SampleRate;
            for (int i = 0; i < cutLogarithmizedSpectrum.Count; i++)
            {
                Assert.IsTrue(System.Math.Abs(cutLogarithmizedSpectrum[i].StartsAt - (i * lengthOfOneFingerprint / 2)) < Epsilon);
            }
        }