Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The MaxFormantGap parameter is broken or needs clarification #471

Closed
atruskie opened this issue Apr 1, 2021 · 2 comments · Fixed by #498
Closed

The MaxFormantGap parameter is broken or needs clarification #471

atruskie opened this issue Apr 1, 2021 · 2 comments · Fixed by #498
Assignees

Comments

@atruskie
Copy link
Member

atruskie commented Apr 1, 2021

Actual behaviour:

The documentation for the HarmonicAlgorithm states:

There are only two parameters that are specific to `Harmonics`,
`MinFormantGap` and `MaxFormantGap`. These specify the minimum and maximum
allowed gap (measured in Hertz) between adjacent formants/harmonics. Note that
for these purposes the terms `harmonic` and `formant` are equivalent.
By default, the DCT is calculated over all bins in the search band.

But I've found that the MaxFormatGap parameter must be set to values much larger than the size of the gap between formants for the algorithm to detect anything.

Expected behavior:

Clarify the intended use of MaxFormantGapt in the documentation or treat this as a bug and ensure the code works as advertised.

How to reproduce this bug:

  1. Create a generic recognizer that used a harmonic algorithm detector
  2. Apply it a recording with a harmonic
  3. Examine detection results when MaxFormantGap is set appropriately versus when it is set to approximately the total bandwidth of the target event.

Additional Details

image

Config excerpt:

    Bark: !HarmonicParameters
        <<: *common_parameters

        # min and max of the freq band to search
        MinHertz: 350
        MaxHertz: 2700
        MinDuration: 0.1
        MaxDuration: 0.3
        MinFormantGap: 150
        MaxFormantGap: 2400
        DctThreshold: 0.15
        # Scan the frequency band at these thresholds
        DecibelThresholds:
          - 3.0
          - 6.0
          - 9.0

Note the harmonic detector works, but the MaxFormantGap is set to a value that is much larger the true max formant gap (which would be about 300 Hz)

@atruskie
Copy link
Member Author

Full config file:

ksh23_1766_510096_20171102_170621_30_0_3054_3084_0-0.5min.wav
kmu16_1817_507136_20171029_103134_30_0_161_191_0-0.5min.wav

atruskie added a commit that referenced this issue Jun 9, 2021
Also adds some test assertions for validating objects.

Related to #471
towsey added a commit that referenced this issue Jun 11, 2021
Issue #471 In order to condition the array of DCT coefficient values nicely, I have  removed the linear trend. This helps to lower the long-wavelenth coefficients making it more likely to find the correct maximum.
towsey added a commit that referenced this issue Jun 11, 2021
Issue #471 When searching for harmonic events, sometimes small gaps appear in the harmonic score array which means the events are too short and therefore rejected. This hack fills in gaps of one or two frames. This problem arises because the maximum DCT coefficient is sometimes of a longer wavelength (lower array index) than the the expected wavelength.
towsey added a commit that referenced this issue Jun 11, 2021
Issue #471 Reworked these test. They now both pass. The problem lies in the return DCT coefficients being unduly sensitive to noise. The harmonic recognizer still appears to be sensitive to the minHertz and maxHertz parameter values in ways that I would not expect. THis remains to be checked.
towsey added a commit that referenced this issue Jun 12, 2021
Issue #471 Create a new method to detect harmonic events in a score array. Create new property in the HarmonicEvent class.
towsey added a commit that referenced this issue Jun 12, 2021
Issue #471 Add more detailed comments on the harmonic detection and DCT. Also clean out some unused code.
towsey added a commit that referenced this issue Jun 12, 2021
Issue #471 More explanatory comments.
towsey added a commit that referenced this issue Jun 12, 2021
Issue #471 The Harmonic Algorithm tests are now working as one would expect.
towsey added a commit that referenced this issue Jun 13, 2021
Issue #471 Refactor the method that draws a matrix as an image so that the method returns the image. This had side effect on the Oscillations2010 class.
towsey added a commit that referenced this issue Jun 13, 2021
Issue #471 Create a unit test for the method that draws a matrix of cosine basis functions.
towsey added a commit that referenced this issue Jun 13, 2021
Issue #471 Adjust this unit test following all previous changes to the methods that find harmonic events.
towsey added a commit that referenced this issue Jun 13, 2021
Issue #471 Removed the only useful method from this class and placed in HarmonicPArameters.cs.
THis CrossCorrelations.cs class is now redundant and could possibly be removed except that it contains methods previously used in recognition of crow calls and human speech. However I doubt they of use any longer.
towsey added a commit that referenced this issue Jun 13, 2021
Issue #471 Shifted method DetectHarmonicsInSpectrogramData() to a location where it better belongs.
@towsey
Copy link
Contributor

towsey commented Jun 13, 2021

I believe I have fixed the the problem identified in this issue. The problem lay in determining the maximum DCT coefficient.

towsey added a commit that referenced this issue Jun 15, 2021
Issue #471 Make spectrogram smoothing accessible to user. The default is no spectrogram smoothing.
towsey added a commit that referenced this issue Jun 15, 2021
Issue #471 Remove hard coded path.
towsey added a commit that referenced this issue Jun 15, 2021
Issue #471 Small changes requested by Anthony.
towsey added a commit that referenced this issue Jun 15, 2021
Issue #471 Editing of the md file for Harmonics, taking account of recent changes.
atruskie added a commit that referenced this issue Jun 16, 2021
* Adds test cases for harmonic algoirthm

Also adds some test assertions for validating objects.

Related to #471

* Update CrossCorrelation.cs

Issue #471 In order to condition the array of DCT coefficient values nicely, I have  removed the linear trend. This helps to lower the long-wavelenth coefficients making it more likely to find the correct maximum.

* Fill in the gaps in the harmonic score array.

Issue #471 When searching for harmonic events, sometimes small gaps appear in the harmonic score array which means the events are too short and therefore rejected. This hack fills in gaps of one or two frames. This problem arises because the maximum DCT coefficient is sometimes of a longer wavelength (lower array index) than the the expected wavelength.

* Update HarmonicAlgorithmTests.cs

Issue #471 Reworked these test. They now both pass. The problem lies in the return DCT coefficients being unduly sensitive to noise. The harmonic recognizer still appears to be sensitive to the minHertz and maxHertz parameter values in ways that I would not expect. THis remains to be checked.

* Create a new method to detect harmonic events

Issue #471 Create a new method to detect harmonic events in a score array. Create new property in the HarmonicEvent class.

* Add comments on the harmonic detection and DCT

Issue #471 Add more detailed comments on the harmonic detection and DCT. Also clean out some unused code.

* Update MFCCStuff.cs

Issue #471 More explanatory comments.

* Rework two test classes

Issue #471 The Harmonic Algorithm tests are now working as one would expect.

* Refactor image method

Issue #471 Refactor the method that draws a matrix as an image so that the method returns the image. This had side effect on the Oscillations2010 class.

* Create a new unit test

Issue #471 Create a unit test for the method that draws a matrix of cosine basis functions.

* Update GenericRecognizerTests.cs

Issue #471 Adjust this unit test following all previous changes to the methods that find harmonic events.

* Update CrossCorrelation.cs

Issue #471 Removed the only useful method from this class and placed in HarmonicPArameters.cs.
THis CrossCorrelations.cs class is now redundant and could possibly be removed except that it contains methods previously used in recognition of crow calls and human speech. However I doubt they of use any longer.

* Update HarmonicParameters.cs

Issue #471 Shifted method DetectHarmonicsInSpectrogramData() to a location where it better belongs.

* Update src/AudioAnalysisTools/Events/Types/HarmonicEvent.cs

Co-authored-by: Anthony Truskinger <anthony.truskinger@gmail.com>

* Make spectrogram smoothing accessible to user

Issue #471 Make spectrogram smoothing accessible to user. The default is no spectrogram smoothing.

* Adjust expected values in unit tests

Issue $471 Adjust expected values in unit tests. Returned frequency bounds to previous values. Added in the HarmonicInterval as a value to be checked.

* Update GenericRecognizerTests.cs

Issue #471 Remove hard coded path.

* Small changes

Issue #471 Small changes requested by Anthony.

* Update HarmonicParameters.md

Issue #471 Editing of the md file for Harmonics, taking account of recent changes.

* Update HarmonicEvent.cs

Restored Value in xml doc

Co-authored-by: Anthony Truskinger <anthony.truskinger@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants