grrrr / nsgt

Non Stationary Gabor Transform (NSGT), Python implementation
http://grrrr.org/research/software/nsgt
Artistic License 2.0
95 stars 28 forks source link

[Feature Request] A stand alone spectrogram function. #34

Closed aphoffmann closed 1 year ago

aphoffmann commented 2 years ago

A very useful feature would be a standalone spectrogram function. For example:

nsgt = CQ_NSGT(lowf, fmax, bins, fs, length)
B = nsgt.forward(sig)
nsgt.spectrogram(B)

It could use matplotlib, or any common plotting library on the back end. I had a difficult time working through spectrogram.py to try to plot my numpy array of magnetic field data.

Another very useful function would be a coherence-gram.

Love your work!

grrrr commented 2 years ago

Thanks for your comment. I don't think that plotting should be included in the nsgt functionality. Apart from that, only a spectrogram matrix is needed which boils down to

nsgt = CQ_NSGT(lowf, fmax, bins, fs, length, real=True, matrixform=True)
B = numpy.abs(nsgt.forward(sig))

This matrix can then be plotted using, e.g., pyplot.imshow(B, aspect="auto", origin="lower")

aphoffmann commented 2 years ago

Thank you for the tip!

In this case, how would I find the frequencies for labeling the Y-axis? I noticed that nsgt.frqs has a different shape than the output matrix from nsgt.forward().

Thanks.

grrrr commented 2 years ago

The frequencies are given by nsgt.frqs. If the argument to CQ_NSGT reducedform=0, then there are additional spectral bins for zero and Nyquist. If reducedform=1, these will be omitted. With reducedform=2, also the fmin and fmax bins will be omitted. The fmax bin is often very dense, and omitting will reduce the spectrogram size. Clearly, only with reducedform=0 the transformation is invertible.