Skip to content

Commit

Permalink
Final changes to spectral centroid classes
Browse files Browse the repository at this point in the history
Issue #292 Added in reference to literature to justify calculation of the spectral centroid and fix a failing unit test.
  • Loading branch information
towsey committed Jul 7, 2020
1 parent 4df0b60 commit 058b9a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
26 changes: 20 additions & 6 deletions src/AudioAnalysisTools/SpectralCentroid.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
using AudioAnalysisTools.StandardSpectrograms;
using System;
using System.Collections.Generic;
using System.Text;
using TowseyLibrary;
// <copyright file="SpectralCentroid.cs" company="QutEcoacoustics">
// All code in this file and all associated files are the copyright and property of the QUT Ecoacoustics Research Group (formerly MQUTeR, and formerly QUT Bioacoustics Research Group).
// </copyright>

namespace AudioAnalysisTools
{
using AudioAnalysisTools.StandardSpectrograms;
using System;
using System.Collections.Generic;
using System.Text;
using TowseyLibrary;

/// <summary>
/// Calculates the spectral centroid of a spectrum, or a recording segment.
/// The spectral centroid is a considred to be a reliable estimate of the brightness of a recording.
/// Bright recordings contain mre high frequency content. See following for good intro:
/// Bright recordings contain more high frequency content.
/// It is included here as a summary index because it was found to be correlated with degree of "naturalness" of a bush soundscape.
/// See recent papers from Sussex University (Alice Eldridge and colleagues)
/// (1) Eldridge, Alice and Guyot, Patrice and Moscoso, Paola and Johnston, Alison and Eyre-Walker, Ying and Peck, Mika
/// "Sounding out ecoacoustic metrics: Avian species richness is predicted by acoustic indices in temperate but not tropical habitats."
/// (2018) Ecological Indicators, 95 (1). 939-952. ISSN 1470-160X
/// (2) Carruthers-Jones, Jonathan, Eldridge, Alice, Guyot, Patrice, Hassal, Christopher and Holmes, George
/// "The call of the wild: investigating the potential for ecoacoustic methods in mapping wilderness areas."
/// (2019) Science of The Total Environment, 695. p. 133797. ISSN 0048-9697
///
/// See following for good intro to calculating the Spectral Centroid:
/// https://www.cs.cmu.edu/~music/icm/slides/05-algorithmic-composition.pdf
/// Also Wikipedia entry: https://en.wikipedia.org/wiki/Spectral_centroid
/// The spectral centroid is derived from the values in the AMPLITUDE spectrogram.
Expand Down
4 changes: 2 additions & 2 deletions tests/Acoustics.Test/Shared/CsvTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ public void TestBaseTypesAreNotSerializedAsArray()
var baseExpected = $@"{nameof(SummaryIndexBase.RankOrder)},{nameof(SummaryIndexBase.FileName)},{nameof(SummaryIndexBase.ResultStartSeconds)},{nameof(SummaryIndexBase.SegmentDurationSeconds)},{nameof(SummaryIndexBase.ResultMinute)}
0,,0,0,0
".NormalizeToCrLf();
var childExpected = $@"ZeroSignal,HighAmplitudeIndex,ClippingIndex,AvgSignalAmplitude,BackgroundNoise,Snr,AvgSnrOfActiveFrames,Activity,EventsPerSecond,HighFreqCover,MidFreqCover,LowFreqCover,AcousticComplexity,TemporalEntropy,EntropyOfAverageSpectrum,EntropyOfVarianceSpectrum,EntropyOfPeaksSpectrum,EntropyOfCoVSpectrum,ClusterCount,ThreeGramCount,Ndsi,SptDensity,{nameof(SummaryIndexBase.RankOrder)},{nameof(SummaryIndexBase.FileName)},{nameof(SummaryIndexBase.ResultStartSeconds)},{nameof(SummaryIndexBase.SegmentDurationSeconds)},{nameof(SummaryIndexBase.ResultMinute)}
0,0,0,-100,-100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0
var childExpected = $@"ZeroSignal,HighAmplitudeIndex,ClippingIndex,AvgSignalAmplitude,BackgroundNoise,Snr,AvgSnrOfActiveFrames,Activity,EventsPerSecond,SpectralCentroid,HighFreqCover,MidFreqCover,LowFreqCover,AcousticComplexity,TemporalEntropy,EntropyOfAverageSpectrum,EntropyOfVarianceSpectrum,EntropyOfPeaksSpectrum,EntropyOfCoVSpectrum,ClusterCount,ThreeGramCount,Ndsi,SptDensity,{nameof(SummaryIndexBase.RankOrder)},{nameof(SummaryIndexBase.FileName)},{nameof(SummaryIndexBase.ResultStartSeconds)},{nameof(SummaryIndexBase.SegmentDurationSeconds)},{nameof(SummaryIndexBase.ResultMinute)}
0,0,0,-100,-100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0
".NormalizeToCrLf();

Csv.WriteToCsv(this.testFile, childArray);
Expand Down

0 comments on commit 058b9a4

Please sign in to comment.