0
$\begingroup$

On my wav-file (music), I do a short-time Fourier transform (STFT). I have spectrum, which spans from $0\textrm{ Hz}$ to $f_s/2$. I took out the range between $1$ and $1000\textrm{ Hz}$, which I divided in $3$ frequency bands. My STFT is performed every $50\textrm{ ms}$ so I can see the changes over the time.

At this point I am not quite sure, if i am right or wrong. I want to get the overall performance of my frequency band every $50\textrm{ ms}$. Which means, I get $3$ values every $50\textrm{ ms}$ because I have $3$ frequency bands.

I think I need to calculate the bins of my frequency band to do that. Any idea? Btw, my code is in MATLAB.


I see. In my code, i did a full stft, for which i have defined a frequency vector. It looks like this:

f=0:1:fftlen-1;
f=f/(fftlen-1)*fs;

fftlen is 4096 and fs is 44100. I have written it so, that i took out 0-1000Hz and divided it up in 3 frequency bands, which for exmaple is a

lowband=(1:200); 

and then defined a frequency vector for my lowband, otherwise it wouldn't have worked.(Maybe there is another simpler solution...) which looks like this:

fL = 1:1:200;

I am not sure if i can see the connection behind this, but fs/fftlen = 10.76660156.... This must mean that 19th bin is about 204.56..., which is close to my predefined frequency vector (200Hz) of my lower band. I got this value by doing 200/(44100/4096), which is 18.5759.. by rounding it off, the 19th bin. Afterwards i multiplied 19 with 10.7666..., which is 204.56..

If i am right then i will simply take all values from the first bin to the 18th bin. And make a arithmetical mean of it. Is my calculation then correct?

$\endgroup$
0
$\begingroup$

Frequency bins corresponding to the frequency bands could be found using the fact that each bin will represent band of $(fs/\mathbf{fft}_{pt})$.
$\mathbf{fft}_{pt}$ is the number of fft points you used for stft.

Hence you can find bins corresponding to your band of requirement.

$\endgroup$
0
$\begingroup$

To find the number of vector elements below a given frequency (in your case 200Hz) you can do:

Imagine that "f" is your vector with the frequencies, then the last position of that vector with value below 200Hz can be calculated as:

k = sum(f<200)

To better explain: f<200 will give you a vector with 0 and 1. The first elements will be 1 because they are below 200. If you sum all the 1's the you will have the position of the vector that mark the boundary.

$\endgroup$
0
$\begingroup$

If i am right then i will simply take all values from the first bin to the 18th bin. And make a arithmetical mean of it. Is my calculation then correct?

To get a overall value of some RMS you need to calculate a RMS again: $RMS_{1...n} = \sqrt{1/n (RMS_1² + RMS_2² + ... + RMS_n²)} $

Matlab: RMS_L = rms(frequencybins)

However there will be an error with not meeting your desired 200 Hz band. For clearing that, I suggest to proceed as described in the answer of arpit jain and make your bins fitting to your band (or a fraction of your band(s)).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.