/// <summary> /// This algorithm is used for broad band events such as a bird chorus. /// It selects acoustic content over a band of several kHz and calculates a content score based on a template match to what is in the band. /// </summary> /// <param name="oneMinuteOfIndices">Derived from the source recording.</param> /// <param name="template">A previously prepared template.</param> /// <param name="templateIndices">The actual dictionary of template arrays.</param> /// <returns>A similarity score.</returns> public static double GetBroadbandContent1(Dictionary <string, double[]> oneMinuteOfIndices, TemplateManifest template, Dictionary <string, double[]> templateIndices) { // copy over the recording indices required by the template. var requiredIndices = DataProcessing.GetRequiredIndices(oneMinuteOfIndices, templateIndices.Keys.ToArray()); //reduce indices and convert to vector. var reductionFactor = template.SpectralReductionFactor; int freqBinCount = ContentSignatures.FreqBinCount / reductionFactor; int bottomFreq = template.BandMinHz; //Hertz int topFreq = template.BandMaxHz; //Hertz var freqBinBounds = DataProcessing.GetFreqBinBounds(bottomFreq, topFreq, freqBinCount); var reducedIndices = DataProcessing.ReduceIndicesByFactor(requiredIndices, reductionFactor); // remove top freq bins and bottom freq bins; reducedIndices = DataProcessing.ApplyBandPass(reducedIndices, freqBinBounds[0], freqBinBounds[1]); var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices); var templateVector = DataProcessing.ConvertDictionaryToVector(templateIndices); //Get Euclidean distance and normalize the distance var distance = DataTools.EuclideanDistance(templateVector, oneMinuteVector); // Normalize the distance distance /= Math.Sqrt(templateVector.Length); return(1 - distance); }
/// <summary> /// This algorithm is used for full band width events such as a rain and wind. /// It calculates a content score based on a template match to what is in the full spectrum. /// </summary> /// <param name="oneMinuteOfIndices">Derived from the source recording.</param> /// <param name="template">A previously prepared template.</param> /// <param name="templateIndices">The actual dictionary of template arrays.</param> /// <returns>A similarity score.</returns> public static double GetFullBandContent1(Dictionary <string, double[]> oneMinuteOfIndices, TemplateManifest template, Dictionary <string, double[]> templateIndices) { // copy over the recording indices required by the template. var requiredIndices = DataProcessing.GetRequiredIndices(oneMinuteOfIndices, templateIndices.Keys.ToArray()); //reduce indices and convert to vector. var reducedIndices = DataProcessing.ReduceIndicesByFactor(requiredIndices, template.SpectralReductionFactor); var oneMinuteVector = DataProcessing.ConvertDictionaryToVector(reducedIndices); var templateVector = DataProcessing.ConvertDictionaryToVector(templateIndices); var distance = DataTools.EuclideanDistance(templateVector, oneMinuteVector); // Normalize the distance distance /= Math.Sqrt(templateVector.Length); return(1 - distance); }