fastlib / fCWT

The fast Continuous Wavelet Transform (fCWT) is a library for fast calculation of CWT.
Apache License 2.0
263 stars 53 forks source link

How to extract actual periods or frequencies used in Python version? Normalization? #35

Open bjunor opened 1 year ago

bjunor commented 1 year ago

I'd like to be able to plot the actual frequencies or actual periods on my scaleograms. I'm using code based on the advanced Python examples so that I can use the optimization. But fcwt returns scales as a SWIG object and I'm not sure what to do with that. (<fcwt.fcwt.Scales; proxy of <Swig Object of type 'Scales *' at 0x000002154D2B70F0> >) Is there a way get to some approximation of the actual periods or frequencies used?

Also what does the normalization option do? Normalized to what?

felixdollack commented 1 year ago

There is the function getFrequencies you can call on the scales object.

fs = 1000
f0 = 0.1 #lowest frequency
f1 = 5 #highest frequency
fn = 300 #number of frequencies

#initialize Morlet wavelet with wavelet parameter (sigma) 2.0
morl = fcwt.Morlet(2.0)

#initialize scales
scales = fcwt.Scales(morl, fcwt.FCWT_LINFREQS, fs, f0, f1, fn)

#initialize output array
freqs = np.zeros((fn,), dtype=np.float32)

# get frequencies from swig scale object
scales.getFrequencies(freqs)

Just watch out, it seems that the frequencies coming out of that call are in decreasing order. Here the first is around 5 (f1) and the last one is 0.1 (f0).