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

Stft output frequency bin count doesn't match Stft constructor parameters? #31

Closed
Bambofy opened this issue Sep 14, 2020 · 2 comments
Closed

Comments

@Bambofy
Copy link

Bambofy commented Sep 14, 2020

Hi!

I'm currently using the Stft feature, when i provide these parameters

Stft stft = new Stft( windowSize: 1024, hopSize: 256, window: NWaves.Windows.WindowTypes.Hann, fftSize: 256);

The output spectrums result in a length 513 not 256?

See the image below that displays the number of bins in a single spectrum of the Stft spectrogram

Screenshot 2020-09-14 at 09 24 38

Additionally:
Q1) What is the resulting Y Axis graph representing, is it power?
Q2) The Y values output from the Stft are normalized, how are they normalized? e.g:
Screenshot 2020-09-14 at 09 32 29

@Bambofy Bambofy changed the title Stft output frequency bin count doesn't match Sftf constructor parameters? Stft output frequency bin count doesn't match Stft constructor parameters? Sep 14, 2020
@ar1st0crat
Copy link
Owner

ar1st0crat commented Sep 14, 2020

Hi!

Regarding the STFT parameters - take a look here at n_fft and win_length parameters.

In short, the FFT size can not be smaller than the size of analysis window (so NWaves sets FFT size to 1024 automatically in your case). I guess what you're trying to do is analyze signal in the 1024-samples window and then obtain FFT with lower frequency resolution (256 samples). So essentially, you need to compute 1024-point FFT and then sum values inside each group of 4 adjacent samples. Something like this:

for (int i = 1, k = 0; i < s.Length; i+=4, k++)
    low[k] = s[i] + s[i+1] + s[i+2] + s[i+3]

Q1: yes, Y represents power (spectrogram is the sequence of power spectra).
Q2: each power spectrum is normalized by FFT size (by default). Unfortunately, I didn't add the boolean parameter for normalization in Spectrogram() method (Fft.PowerSpectrum() has this parameter, though). This parameter will be added in next version of the lib.

Regards,
Tim

@Bambofy
Copy link
Author

Bambofy commented Sep 15, 2020

Hi!

Regarding the STFT parameters - take a look here at n_fft and win_length parameters.

In short, the FFT size can not be smaller than the size of analysis window (so NWaves sets FFT size to 1024 automatically in your case). I guess what you're trying to do is analyze signal in the 1024-samples window and then obtain FFT with lower frequency resolution (256 samples). So essentially, you need to compute 1024-point FFT and then sum values inside each group of 4 adjacent samples. Something like this:

for (int i = 1, k = 0; i < s.Length; i+=4, k++)
    low[k] = s[i] + s[i+1] + s[i+2] + s[i+3]

Q1: yes, Y represents power (spectrogram is the sequence of power spectra).
Q2: each power spectrum is normalized by FFT size (by default). Unfortunately, I didn't add the boolean parameter for normalization in Spectrogram() method (Fft.PowerSpectrum() has this parameter, though). This parameter will be added in next version of the lib.

Regards,
Tim

Thank you for the detailed reply!

@Bambofy Bambofy closed this as completed Sep 15, 2020
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

2 participants