Skip to content

An accurate S transform (Stockwell transform) and its quick inverse approximation in Python.

License

Notifications You must be signed in to change notification settings

xli2522/S-Transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Supported in: PyPI version

[References]

  • R. G. Stockwell, L. Mansinha, and R. P. Lowe, Localization of the Complex Spectrum: The S Transform. IEEE Transactions on Signal Processing, Vol. 44, No. 4, Apr. 1996
  • Stockwell, RG (1999). S-transform analysis of gravity wave activity from a small scale network of airglow imagers. PhD thesis, University of Western Ontario, London, Ontario, Canada.

S (Stockwell) Transform for Chirp Signals

Step 1: Quadratic chirp signal

Generate a quadratic chirp signal from 10 Hz to 120 Hz in 1 second with 10,000 sampling points.

import numpy as np
import scipy
import matplotlib.pyplot as plt

# Generate a quadratic chirp signal
dt = 0.001; t = 3
rate = int(1/dt)
ts = np.linspace(0, t, int(1/dt))
data = scipy.signal.chirp(ts, 10, 1, 120, method='quadratic')

Step 2: S Transform Spectrogram

from s import *

# Compute S Transform Spectrogram
spectrogram = sTransform(data, sample_rate=rate, frate=rate/len(data),
                                    downsample=None, frange=[0,500])
plt.imshow(abs(spectrogram), origin='lower', aspect='auto')
plt.title('Original Spectrogram')
plt.colorbar()
plt.show()

Original Spectrogram

Step 3: The inverse S transform

# Quick Inverse of ts from S Transform
inverse_ts, inverse_tsFFT = inverseS(spectrogram)

# Magnitude Compensation: 
# with the assumption that ts is real and only positive freqs are kept
inverse_ts_comp = inverse_ts*2
# Plot the original signal and the recovered, magnitude compensated signal
fig, axs = plt.subplots(2,1)
axs[0].plot(data)
axs[1].plot(inverse_ts_comp.real)
axs[0].set_title('Original Signal')
axs[1].set_title('(inverseS) Freq-passed, down-sampled Signal')
plt.show()
plt.plot(inverse_ts_comp)
plt.plot(inverse_ts_comp-data)
plt.title('Time Series Reconstruction Error')
plt.legend(['Recovered ts', 'Error'])
plt.show()

Recovered ts and Error

Step 4: Recovered inverse S transform spectrogram

# Compute S Transform Spectrogram on the recovered time series
inverseSpectrogram = sTransform(inverse_ts, 
                        sample_rate=len(inverse_ts)/len(data)*rate, 
                                                    frange=[0,500])
plt.imshow(abs(inverseSpectrogram), origin='lower', aspect='auto')
plt.title('Recovered Spectrogram (inverseS)')
plt.colorbar()
plt.show()

Recovered Spectrogram

One of the original copies of Dr. Stockwell's PhD thesis.

Thesis