The creation of this program was inspired by the need to include a CQT package with minimal size and dependency for SHARCNET (ComputeCanada) Supercomputer Clusters.
x# IMPORTANT DISCLAIMER: All credits for the original Q transform algorithm go to the authors of *GWpy* and *Omega* pipeline.# See original algorithms at: [Omega Scan] https://gwdetchar.readthedocs.io/en/stable/omega/# [GWpy] https://gwpy.github.io/docs/stable/# particularly [GWpy qtransform]# - https://github.com/gwpy/gwpy/blob/26f63684db17104c5d552c30cdf01248b2ec76c9/gwpy/signal/qtransform.py## The license information does NOT imply this package (constantQ) as the original q transform/q scan algorithm.# NOTE: Referenced programs are under the GNU license # for more information on the license visit: https://www.gnu.org/licenses/gpl-faq.en.htmlHow to use it:
Step 1: Generating a chirp signal
x
import numpy as np# Generate np.array chirp signaldt = 0.001t = np.arange(0,3,dt)f0 = 50f1 = 250t1 = 2x = np.cos(2*np.pi*t*(f0 + (f1 - f0)*np.power(t, 2)/(3*t1**2)))fs = 1/dtplt.plot(x) # plot the chirp signalplt.show() # displayStep 2: Generating a TimeSeries object
x
from constantQ.timeseries import TimeSeriesseries = TimeSeries(x, dt = 0.001, unit='m', name='test', t0=0) #np.array --> constantQ.timeseries Step 3: Q Transform
x
hdata = seriessq = hdata.q_transform(search=None) # q transformprint(len(sq[0])) # freq array lengthprint(len(sq)) # time array lengthplt.imshow(sq.T, origin='lower') # plot the spectrogramplt.colorbar() # colorbarplt.show() # displayTo compare the result with a Scipy Spectrogram
x
from scipy import signal as scisignalfreq, ts, Sxx = scisignal.spectrogram(x) # scipy spectrogramplt.pcolor(ts, freq, Sxx, shading='auto') # plot the spectrogramplt.colorbar() # colorbarplt.show() # displayThis test version 0.0.1 largely follows the GWpy architecture. Changes will be made in future updates if a different structure is better for this package.