Esempio n. 1
0
        /// <summary>
        /// Calculates the average amplitude in the frequency just above the whistle.
        /// If it contains above threshold acoustic content, this is unlikely to be a whistle.
        /// </summary>
        /// <param name="ev">The event.</param>
        /// <param name="sonogramData">The spectrogram data as matrix with origin top/left.</param>
        /// <param name="bufferBins">THe badnwidth of the buffer zone in bins.</param>
        /// <param name="converter">A converter to convert seconds/Hertz to frames/bins.</param>
        /// <returns>Average of the spectrogram amplitude in buffer band above whistler.</returns>
        public static double GetAverageAmplitudeInNeighbourhood(SpectralEvent ev, double[,] sonogramData, int bufferBins, UnitConverters converter)
        {
            var bottomBufferBin    = converter.GetFreqBinFromHertz(ev.HighFrequencyHertz) + 5;
            var topBufferBin       = bottomBufferBin + bufferBins;
            var frameStart         = converter.FrameFromStartTime(ev.EventStartSeconds);
            var frameEnd           = converter.FrameFromStartTime(ev.EventEndSeconds);
            var subMatrix          = MatrixTools.Submatrix <double>(sonogramData, frameStart, bottomBufferBin, frameEnd, topBufferBin);
            var averageRowDecibels = MatrixTools.GetRowAverages(subMatrix);
            var av = averageRowDecibels.Average();

            return(av);
        }
Esempio n. 2
0
        public void TestBackwardsAndForwardsConversionSpectrograms(int frame, int bin)
        {
            UnitConverters converter = new UnitConverters(
                60,
                22050,
                512,
                256);

            var endFrame = frame + 1;

            var secondsStart = converter.GetStartTimeInSecondsOfFrame(frame);
            var secondsEnd   = converter.GetEndTimeInSecondsOfFrame(endFrame);
            var hertz        = converter.GetHertzFromFreqBin(bin);

            var outFrame    = converter.FrameFromStartTime(secondsStart);
            var endOutFrame = converter.FrameFromEndTime(secondsEnd);
            var outBin      = converter.GetFreqBinFromHertz(hertz);

            Assert.AreEqual(frame, outFrame, $"Frames do not match, expected: {frame}, actual: {outFrame}, seconds was: {secondsStart}");
            Assert.AreEqual(endFrame, endOutFrame, $"Frame ends do not match, expected: {endFrame}, actual: {endOutFrame}, seconds was: {secondsEnd}");
            Assert.AreEqual(bin, outBin, $"Bins do not match, expected: {bin}, actual: {outBin}, hertz was: {hertz}");
        }