Exemple #1
0
        /// <summary>
        /// Performs Spectral Peak Tracking on a recording
        /// Returns a matrix derived from the sonogram
        /// </summary>
        /// <param name="sonogram">the sonogram</param>
        /// <param name="intensityThreshold">Intensity threshold in decibels above backgorund</param>
        /// <param name="smallLengthThreshold">remove event swhose length is less than this threshold</param>
        /// <returns></returns>
        public static Tuple <double[, ]> doSPT(BaseSonogram sonogram, double intensityThreshold, int smallLengthThreshold)
        {
            // Sonograms in Matlab (which F# AED was modelled on) are orientated the opposite way
            var m = MatrixModule.transpose(MatrixModule.ofArray2D(sonogram.Data));

            //Log.WriteLine("Wiener filter start");
            var w = Matlab.wiener2(7, m);

            //Log.WriteLine("Wiener filter end");

            //Log.WriteLine("Remove subband mode intensities start");
            var s = AcousticEventDetection.removeSubbandModeIntensities(w);

            //Log.WriteLine("Remove subband mode intensities end");

            Log.WriteLine("SPT start");
            int nh = 3;
            var p  = SpectralPeakTrack.spt(s, intensityThreshold, nh, smallLengthThreshold);

            Log.WriteLine("SPT finished");

            var r = MatrixModule.toArray2D(MatrixModule.transpose(p));

            return(Tuple.Create(r));
        }
Exemple #2
0
        public static EventCommon[] CallAed(BaseSonogram sonogram, AedConfiguration aedConfiguration, TimeSpan segmentStartOffset, TimeSpan segmentDuration)
        {
            Log.Info("AED start");

            var aedOptions = new AedOptions(sonogram.Configuration.NyquistFreq)
            {
                IntensityThreshold = aedConfiguration.IntensityThreshold,
                SmallAreaThreshold = aedConfiguration.SmallAreaThreshold,
                DoNoiseRemoval     = aedConfiguration.NoiseReductionType == NoiseReductionType.None,
            };

            if (aedConfiguration.BandpassMinimum.HasValue && aedConfiguration.BandpassMaximum.HasValue)
            {
                var bandPassFilter =
                    Tuple.Create(
                        (double)aedConfiguration.BandpassMinimum.Value,
                        (double)aedConfiguration.BandpassMaximum.Value);
                aedOptions.BandPassFilter = new FSharpOption <Tuple <double, double> >(bandPassFilter);
            }

            IEnumerable <Oblong> oblongs = AcousticEventDetection.detectEvents(aedOptions, sonogram.Data);

            Log.Info("AED finished");

            var unitConverters = new UnitConverters(
                segmentStartOffset.TotalSeconds,
                sonogram.SampleRate,
                sonogram.Configuration.WindowSize,
                sonogram.Configuration.WindowOverlap);

            var events = oblongs.Select(
                o =>
            {
                var blob = new BlobEvent()
                {
                    SegmentDurationSeconds = segmentDuration.TotalSeconds,
                    Name = "AED Event",
                };

                unitConverters.SetBounds(blob, o);

                if (aedConfiguration.IncludeHitElementsInOutput)
                {
                    o.HitElements
                    .Select(p => unitConverters.ConvertPointToSpectralPoint(p, 1.0))
                    .ForEach(sp => blob.Points.Add(sp));
                }

                return(blob);
            });

            return(events.ToArray());
        }
Exemple #3
0
        public static AcousticEvent[] CallAed(BaseSonogram sonogram, AedConfiguration aedConfiguration, TimeSpan segmentStartOffset, TimeSpan segmentDuration)
        {
            Log.Info("AED start");

            var aedOptions = new AedOptions(sonogram.Configuration.NyquistFreq)
            {
                IntensityThreshold = aedConfiguration.IntensityThreshold,
                SmallAreaThreshold = aedConfiguration.SmallAreaThreshold,
                DoNoiseRemoval     = aedConfiguration.NoiseReductionType == NoiseReductionType.None,
            };

            if (aedConfiguration.BandpassMinimum.HasValue && aedConfiguration.BandpassMaximum.HasValue)
            {
                var bandPassFilter =
                    Tuple.Create(
                        (double)aedConfiguration.BandpassMinimum.Value,
                        (double)aedConfiguration.BandpassMaximum.Value);
                aedOptions.BandPassFilter = new FSharpOption <Tuple <double, double> >(bandPassFilter);
            }

            IEnumerable <Oblong> oblongs = AcousticEventDetection.detectEvents(aedOptions, sonogram.Data);

            Log.Info("AED finished");

            var events = oblongs.Select(
                o =>
            {
                if (!aedConfiguration.IncludeHitElementsInOutput)
                {
                    o.HitElements = null;
                }

                return(new AcousticEvent(
                           segmentStartOffset,
                           o,
                           sonogram.NyquistFrequency,
                           sonogram.Configuration.FreqBinCount,
                           sonogram.FrameDuration,
                           sonogram.FrameStep,
                           sonogram.FrameCount)
                {
                    BorderColour = aedConfiguration.AedEventColor,
                    HitColour = aedConfiguration.AedHitColor,
                    SegmentDurationSeconds = segmentDuration.TotalSeconds,
                });
            }).ToArray();

            return(events);
        }