Getting the window sizes on the Constant Q Transform

323 views
Skip to first unread message

Gorkem Yesiltas

unread,
May 8, 2021, 12:21:42 PM5/8/21
to librosa
Hello everyone,
I am using the Constant Q Transform (CQT) from librosa for a project and I am trying to know the exact time interval that the output frames hold. I understand that it uses different window sizes for different octaves to have a more suitable time and frequency resolution. But I don't understand how exactly it determines which window sizes to use and hence what is the exact length (or rather the range of lengths of the used window sizes) of 10 CQT frames in milliseconds for example. 

I thought perhaps someone could help me calculate it or show me a way to get it with librosa methods directly. 

I don't know if it will be of importance but here is the exact parameters I am using:
librosa.cqt(y, sr=44100, hop_length=256,filter_scale=1,n_bins=96,bins_per_octave=12)

Any help would be much appreciated!


Brian McFee

unread,
May 8, 2021, 12:28:09 PM5/8/21
to librosa
You can get this information from librosa.filters.constant_q_lengths with the same parameters as you use in the CQT.  This will give you the length in (potentially fractional) samples at the native sampling rate for each filter in the CQT bank.

This isn't *exactly* how the filter lengths are constructed, as the CQT function only builds the top octave worth of filters and then approximates the lower octaves by downsampling the signal by factors of 2.  The end result of this is that you might be off by a sample or two at the bottom octave, but using the full filter length calculation above ought to be close enough.

Note that this has nothing to do with the hop length (frame rate), which is independently controlled.  If you want to get a full receptive field calculation for a CQT patch, you may have to do some combination of window length calculation and a bit of overlap arithmetic.  The frames_to_time function might be helpful here.

Gorkem Yesiltas

unread,
May 9, 2021, 9:34:12 AM5/9/21
to librosa

Thank you very much for the quick response! 
Indeed, once I get the frame lengths, I should be able to do the calculations with the hop-size myself :)

Have a great day!
8 Mayıs 2021 Cumartesi tarihinde saat 19:28:09 UTC+3 itibarıyla Brian McFee şunları yazdı:
Reply all
Reply to author
Forward
0 new messages