/// <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 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="manifest">A previously prepared template.</param> /// <param name="templateIndices">The actual dictionary of template arrays.</param> /// <returns>A similarity score.</returns> public static Dictionary <string, double[]> CreateBroadbandTemplate1(TemplateManifest manifest, Dictionary <string, double[, ]> templateIndices) { // Get the template provenance. Assume array contains only one element. var provenanceArray = manifest.Provenance; var provenance = provenanceArray[0]; var startRowId = provenance.StartOffset; var endRowId = provenance.EndOffset; var reductionFactor = manifest.SpectralReductionFactor; var dictionaryOfVector = DataProcessing.AverageIndicesOverMinutes(templateIndices, startRowId, endRowId); // remove first two freq bins and last four freq bins, i.e. bottomBin = 2 and topBin = 11; int freqBinCount = ContentSignatures.FreqBinCount / reductionFactor; int bottomFreq = manifest.BandMinHz; //Hertz int topFreq = manifest.BandMaxHz; //Hertz var freqBinBounds = DataProcessing.GetFreqBinBounds(bottomFreq, topFreq, freqBinCount); var reducedIndices = DataProcessing.ReduceIndicesByFactor(dictionaryOfVector, reductionFactor); reducedIndices = DataProcessing.ApplyBandPass(reducedIndices, freqBinBounds[0], freqBinBounds[1]); return(reducedIndices); }