Better error message when using wrong number of FFT samples
See original GitHub issueWhen I call a FFT-related function with incorrect parameters, I run into the same error message which I find hard to interpret: ValueError: range() arg 3 must not be zero
Reproducible example:
import librosa
import numpy as np
audio = np.random.random(10000)
fft = librosa.stft(audio.astype('float64'), n_fft=100000)
returns:
/usr/local/Caskroom/miniconda/base/envs/deep-music/lib/python3.6/site-packages/librosa/core/spectrum.py in stft(y, n_fft, hop_length, win_length, window, center, dtype, pad_mode)
233 stft_matrix.itemsize))
234
--> 235 for bl_s in range(0, stft_matrix.shape[1], n_columns):
236 bl_t = min(bl_s + n_columns, stft_matrix.shape[1])
237
ValueError: range() arg 3 must not be zero
I was also getting the same error message with librosa.cqt
but I can’t remember what settings it was with. I was trying to maximise the frequency resolution (maximising n_bins and bins_per_octave) across a single time bin (hop_length=audio.shape[0]) so I imagine the cause of the error was the same as the one in my example above.
Could you please add an error message for this?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (6 by maintainers)
Top Results From Across the Web
FFT error when number of samples growth - Matlab/octave
Your error grows with N in absolute terms, but stays constant in relative terms (all frequency components grow as you increase N). I...
Read more >incorrect result of fft phase calculation - MATLAB Answers
I have a strange issue in calculating phase from fft data. On a high level: I am using 100kHz sampling frequency to sample...
Read more >TMS320F28335: FFT results in Bins not correct in Example ...
> My input signal is 50 Hz and I want to perform FFT on that so I corrected my code . I got...
Read more >FFT / Inverse FFT producing small compounding error
Hello All! I am using an FFT and inverse FFT as a sort of band pass ... A better way to say it...
Read more >The Fundamentals of FFT-Based Signal Analysis and ...
x-axis of a spectrum plot depend on the sampling rate and the number of points acquired ... between two signals by using some...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I vote for (1). I work with bird calls, which are very short sounds (3k-10k samples). If i were to accidentally set an
n_fft
above the duration of the sound while computing the STFT, i would prefer to be notified, update my code, and start again; rather than to have librosa perform some padding under the hood without telling me.@JulianFerry cases where n_fft is exactly equal to the input length are best addressed by
np.fft.fft
https://numpy.org/doc/stable/reference/generated/numpy.fft.fft.htmlHaving never contributed to open source it didn’t even occur to me I could PR this myself. I’m happy to give this a shot