As you know the STFT has a matrix result, with the dimension given by:
number of frequency bins * number of time frames.
For example, suppose that I have a signal with characteristics and I want to apply STFT method with the following input parameters:
nftt=625
samples;With those parameters my STFT will have an output with size: 313*3987
(the method to calculate these values exists in some websites)
Now, my question is how can I define a limit for frequency dimension of STFT output? I think I should calculate my threshold values as an index number in STFT output, if so, how can I do it?
I have the frequency resolution, but when I multiply it by nfft
, it's half of the value of sampling rate.
You haven't provided how you calculated the frequency resolution, but here is what it should be:
frequency_resolution = sampling_rate / nfft;
In your particular case with a sampling rate of 250,000Hz and nfft=625
, this should give you a frequency resolution of 400Hz. You can verify that 625*400
is indeed equal to 250000
.
Then, if you want to include frequencies from 0Hz to frequencies no greater than max_frequency
as part of your STFT output, the maximum size along the frequency axis should be given by:
size_frequency_axis = 1 + floor(max_frequency / frequency_resolution);
As a special case you can also verify that when max_frequency
is set to the Nyquist frequency (250000/2 = 125000
), the computed size is 1+floor(125000/400) = 313
(which matches your full spectrum STFT output size).
As a generalization, if you want to include a range of frequencies not starting at 0Hz, then you can compute in a similar fashion the index of the minimum and maximum frequencies, and obtain the corresponding size with:
min_frequency_index = 1 + floor(min_frequency / frequency_resolution);
max_frequency_index = 1 + floor(max_frequency / frequency_resolution);
size_frequency_axis = max_frequency_index - min_frequency_index + 1;