Exemplo n.º 1
0
        /// <summary>
        /// Checks that the passed acoustic event does not have acoustic activity that spills outside the kiwi bandwidth.
        /// </summary>
        /// <param name="ae"></param>
        /// <param name="sonogramMatrix"></param>
        /// <returns></returns>
        public static double CalculateKiwiBandWidthScore(AcousticEvent ae, double[,] sonogramMatrix)
        {
            int eventLength = (int)Math.Round(ae.Duration * ae.FramesPerSecond);

            double[] event_dB = new double[eventLength]; //dB profile for event
            double[] upper_dB = new double[eventLength]; //dB profile for bandwidth above event
            double[] lower_dB = new double[eventLength]; //dB profile for bandwidth below event
            int      eventHt  = ae.oblong.ColWidth;
            int      halfHt   = eventHt / 2;
            int      buffer   = 20; //avoid this margin around the event

            //get acoustic activity within the event bandwidth and above it.
            for (int r = 0; r < eventLength; r++)
            {
                for (int c = 0; c < eventHt; c++)
                {
                    event_dB[r] += sonogramMatrix[ae.oblong.r1 + r, ae.oblong.c1 + c];                               //event dB profile
                }
                for (int c = 0; c < halfHt; c++)
                {
                    upper_dB[r] += sonogramMatrix[ae.oblong.r1 + r, ae.oblong.c2 + c + buffer];
                }
                for (int c = 0; c < halfHt; c++)
                {
                    lower_dB[r] += sonogramMatrix[ae.oblong.r1 + r, ae.oblong.c1 - halfHt - buffer + c];
                }
                //for (int c = 0; c < eventHt; c++) noiseReducedMatrix[ae.oblong.r1 + r, ae.oblong.c1 + c]     = 20.0; //mark matrix
                //for (int c = 0; c < eventHt; c++) noiseReducedMatrix[ae.oblong.r1 + r, ae.oblong.c2 + 5 + c] = 40.0; //mark matrix
            }
            for (int r = 0; r < eventLength; r++)
            {
                event_dB[r] /= eventHt;                                   //calculate average.
            }
            for (int r = 0; r < eventLength; r++)
            {
                upper_dB[r] /= halfHt;
            }
            for (int r = 0; r < eventLength; r++)
            {
                lower_dB[r] /= halfHt;
            }

            //event_dB = DataTools.normalise(event_dB);
            //upper_dB = DataTools.normalise(upper_dB);

            double upperCC = DataTools.CorrelationCoefficient(event_dB, upper_dB);
            double lowerCC = DataTools.CorrelationCoefficient(event_dB, lower_dB);

            if (upperCC < 0.0)
            {
                upperCC = 0.0;
            }
            if (lowerCC < 0.0)
            {
                lowerCC = 0.0;
            }
            double CCscore = upperCC + lowerCC;

            if (CCscore > 1.0)
            {
                CCscore = 1.0;
            }
            return(1 - CCscore);
        }