Hi, can I know why you: X = X.^2; if you said magnitude is should be X = X; only.. correct me if I’m wrong..
You are correct, the comment and the implementation do not fit together perfectly. I should remove the square in future revisions.
In my defense I can only note that there are many different definitions of the Spectral Centroid, and none of them is more correct than the other one…
By looking to your code for spectral centroid and spectral rolloff.. the last answer you convert to Hz. If we want to use as features, it is need in Hz or index?
% convert from index to Hz vsc = vsc / size(X,1) * f_s/2;
It is really up to you how you want to scale the output. Usually, features will be normalized before the next processing step so it does not really matter. The advantage of Hz is that it is independent of FFT size.
Thank you very much.. understood now… do you have any publish paper that can I refer the formula for all the Feature spectral?
Well, best would be to cite my book. You can find the amazon link on the start page or you can find individual chapters online, e.g. here: http://xplqa30.ieee.org/xpl/bkabstractplus.jsp?reload=true&bkn=6266785
I just try log in my university account..unfortunately:
“This content is outside your institutional subscription”
Any suggestion.. maybe from your previous publish paper..?
Sorry, I don’t recall anything that would serve as a definition.
Ok.. thank you very much..
Sir, I am trying to use the code bit I am getting these errors. Do I have to put some other values. Kindly Reply:
Error in ComputeFeature (line 79) v = hFeatureFunc(X, f_s);
Error in trial (line 2) [v, t] = ComputeFeature (‘SpectralCentroid’, x, fs);
Sir, that error I got when I tried to run: [x,fs] = wavread(‘abc.wav’); [v, t] = ComputeFeature (‘SpectralCentroid’, x, fs); Sir, I really need your help. If its possible.
Don’t you get a more elaborate error message? It’s hard to see what’s going on without having more info. Alexander
sir, first problem I am getting is that how to use the code actually. I have both computefeature file as well as other feature files. But how to compute any feature. I tried that spectral centroid eg you gave in the other site and I am getting the above error. Also @param afAudioData: time domain sample data, dimension channels X samples I don’t know how to find the time domain sample data from the wav file. Actually I am new to matlab that is why its hard for me to understand this.
Why don’t you look at a Matlab tutorial first online, and then try to figure the code out? I think that would be a more efficient approach.
sir, I have seen many codes but these are the ones which suits my problem best. The only problem I am having here is to which program to run to get the values for the feature. Sir, I am working on classification of musical instruments.
Hello, reading your Book and comparing it with the code here I got a small question: On p. 196 it is written that it is enough to compute K/2 fourier coefficients of the DFT. It did not fully understand why, but this is ok so far. But still – the DFT “consists of exactly K complex values” (with K = Framelength). With this said I still have K frequency bins in my spectrum X, don’t I? In the code above you iterate the complete vector, or not? But on p. 45 in your book the range goes from k=0 until K/2 – 1. Iterating up to K would feel intuitive, but I do not understand the K/2 – 1. Thanks in advance for your help! Elke
the short answer to this is that for the spectral centroid we are dealing with the magnitude spectrum, not the complex spectrum.
There are, however, several points in your comment that are confusing to many students:
I hope this answers your question. I realize that the long answer might even be more confusing – sorry if that is the case. Alexander
Thank you very much for your detailed answer! It helped – especially it helped to formulate a more detailed question:
For the spectral centroid we’re basically iterating over all k frequency bins of the magnitude spectrum. So I could write the sum as \sum_k=0^#k if #k would be the numbers of frequency bins, right?
Given K = block size (= framelength = num of samples per frame). –> Now I need to know how #k relates to K So because of the above mentioned facts #k = K/2.
Do I really only ‘have’ K/2 frequency bins?
Could I, for the sake of simplicity, also write the sum as mentioned above (without relation to K, but by simply introducing a new variable #k)?
Thank you again very much for your help!
It is the weighted sum, yes. So if you wanted, you could replace the vector multiplication in my code [0:size(X,1)-1]*X with (untested) numerator = 0; for (k = 1:size(X,1)) numerator = numerator + (k-1)*X(k, blockindex); end
As for the number of frequency bins: why don’t you just experiment with matlab’s fft and abs functions to see how many bins you have and if they are redundant or not?
Well at the moment I am just working with your book and not with matlab (I usually work only with pythons matlab-like matplotlib) – but you’re right this would be a good idea to explore everything in a more intuitive way.
Thank for your help!
Your email address will not be published. Required fields are marked *
Current ye@r *
Leave this field empty
Your feedback has been received.