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

ChromaFeature indexing issues #235

Open
kkawabat opened this issue Aug 15, 2019 · 1 comment
Open

ChromaFeature indexing issues #235

kkawabat opened this issue Aug 15, 2019 · 1 comment

Comments

@kkawabat
Copy link

kkawabat commented Aug 15, 2019

I believe there's an error in the implementation of the chromaFeatures. In stChromaFeaturesInit if values of freq is smaller than Cp=27.5 the nChroma values will have negative index due to the log(freq/Cp) term on line 246 this will happen when fs/nfft < Cp

The down stream effect of this is that in stChromaFeatures, nChroma is used as indices to initialize C C[nChroma] = spec, which, if the indices are negative, will incorrectly index C from the end of the array. Also if nChroma has multiple of the same index it would override each other.

Is the ChromaFeature in pyAudioAnalysis a similar implementation to http://www.ctralie.com/Teaching/ECE381_DataExpeditions_Lab1/? if so there is a chroma matrix generator in librosa that might be useful or this custom implementation of chroma matrix by myself might also be helpful

def _stChromaFeaturesInit(nfft, fs):
    """
    This function initializes the chroma matrices used in the calculation of the chroma features
    """
    chroma_matrix = np.zeros((12, nfft))
    freqs = np.array([((f + 1) * fs) / (2 * int(nfft)) for f in range(int(nfft))])
    base_freq = 880  # reference hz for the A note
    freqs_halfstep_approx = (np.log2(freqs / base_freq) * 12)
    note_indices = (np.round(freqs_halfstep_approx) % 12).astype(int)
    halfsteps_freq = base_freq*2**(np.round(freqs_halfstep_approx)/12)
    for i in range(12):
        chroma_matrix[i, note_indices == i] = 1
    return chroma_matrix, halfsteps_freq

if __name__ == '__main__':
    nfft = 1000
    fs = 16000
    chroma_matrix, _ = _stChromaFeaturesInit(nfft, fs)
    import matplotlib.pyplot as plt
    plt.imshow(chroma_matrix, aspect='auto')
    plt.yticks(range(12), ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'], fontsize=9)
    plt.ylabel('frequency bins 8hz per bin')
    plt.show()
    pass

this will produce the following chroma matrix

chromamtx

which can then be used with spec to generate chromaF (assuming the implementation is the same as the link above).

@kkawabat
Copy link
Author

Is the chromaF calculated in pyAudioAnalysis suppose to be a vector of the sum of the frame's chromagram energy at each of the 12 notes, normalized by the energy of the frame?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant