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

problem with nchroma in stChromaFeatures #30

Closed
jmw67 opened this issue Sep 4, 2016 · 7 comments
Closed

problem with nchroma in stChromaFeatures #30

jmw67 opened this issue Sep 4, 2016 · 7 comments

Comments

@jmw67
Copy link

jmw67 commented Sep 4, 2016

Hi,
I got the following error :
Traceback (most recent call last):
File "/home/jmw/Bureau/bacasable/musiques-stream/testpydub.py", line 42, in
F = pafe.stFeatureExtraction(mysample[:2*w], Fs, w, pas)
File "/home/jmw/Bureau/bacasable/musiques-stream/pyAudioAnalysis-master/pyAudioAnalysis/audioFeatureExtraction.py", line 591, in stFeatureExtraction
chromaNames, chromaF = stChromaFeatures(X, Fs, nChroma, nFreqsPerChroma)
File "/home/jmw/Bureau/bacasable/musiques-stream/pyAudioAnalysis-master/pyAudioAnalysis/audioFeatureExtraction.py", line 283, in stChromaFeatures
print "nFreqsPerChroma[nChroma]",nFreqsPerChroma[nChroma]
IndexError: index 56 is out of bounds for axis 1 with size 55
if the windows is small, e.g. below the max(nChroma), in my case the Win size is 110 (10ms with Fs=11000), half window is 55 then C /= nFreqsPerChroma[nChroma] crashes.

This error happens only with a small window, e.g. Fs=11000 with 10ms window so I set Win=110 samples and half window =55 for FFT.

I put a few prints in the code and saw that he nChroma table contains 92 samples) so that the code :
C /= nFreqsPerChroma[nChroma]
in stChromaFeatures crashes.
This is because the nFreqPerChroma array is of size nChroma (=55) but nChroma contains values larger than 55.
I think you should have a look at this code.
best regards

@tyiannak
Copy link
Owner

tyiannak commented Sep 5, 2016

Thanx alot for the info.
Indeed there seems to be a problem with such small short-term windows, due to the chroma vector computation. Strange I have never faced this problem.
I am looking into it and will let you know as soon as possible.
However, 10ms window is very small, especially for Fs = 11KHz, since the frequency resolution will be almost 50Hz, which means that you won't be able to discrinate between different chroma classes.

@tyiannak
Copy link
Owner

tyiannak commented Sep 5, 2016

Hi again. It should work now, please update and retry.
Regards

@jmw67
Copy link
Author

jmw67 commented Sep 7, 2016

Hi,
I will check. For the 10ms size I know it is small it was a mistake I wanted to set to 100ms. And this error led to the bug.
Best regards

@jmw67
Copy link
Author

jmw67 commented Sep 7, 2016

Hi,
I am puzzled by your bug fix. Correct me if I am wrong. But based on my example with 10 ms / 110 sample per frame I get 55 frequencies with midi values up to 94 so larger than 55 the max size.
Spec=X2 and nChroma have the same length (frequency axis)
So I would write the following code :
C=spec #X
2
C/=nFreqPerChroma #normalize according to nb of frequency bin duplicates
Il will obtain 5 octaves (55/12 ~4+1==> 60=5*12) and sum the 12 chroma.
Why adding the max test at the beginning of stChromaFeature?
Best regards

@jmw67
Copy link
Author

jmw67 commented Sep 7, 2016

OK, I missed one part.
I think you should work with a C array of 120 (10*12 midi sounds) and sum up the duplicate bin frequencies you have normalized.

@jmw67
Copy link
Author

jmw67 commented Sep 7, 2016

Would the code below be correct ?
def stChromaFeatures(X, fs, nChroma, nFreqsPerChroma):
#TODO: 1 complexity
#TODO: 2 bug with large windows
chromaNames = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']
spec = X**2
cN=int(numpy.ceil((nChroma.max()+1) / 12.0) * 12)
spec/=nFreqsPerChroma
C=numpy.bincount(nChroma, spec, cN)
finalC = numpy.zeros((12, 1))
C2 = C.reshape(cN/12, 12)

finalC = numpy.matrix(numpy.sum(C2, axis=0)).T
finalC /= spec.sum()


return chromaNames, finalC

@kacperbazylinski
Copy link

At last i found the solution. Thanks! Faced this problem week ago. when was training my SER model with shorten samples, and then wanted to test real-life, longer examples.

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

3 participants