GithubHelp home page GithubHelp logo

xli2522 / tfchirp Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 368 KB

Time Frequency Decomposition Toolbox for Chirp Signals - S transform and its quick inverse.

Home Page: https://pypi.org/project/TFchirp/

License: GNU General Public License v3.0

Python 16.66% HTML 83.34%
s-transform stockwell-transform fourier-transform inverse-fourier-transform spectrogram timefrequency

tfchirp's Introduction

PyPI version Downloads Downloads

Time Frequency 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.0001
rate = int(1/dt)
ts = np.linspace(0, 1, int(1/dt))
data = scipy.signal.chirp(ts, 10, 1, 120, method='quadratic')

Step 2: S Transform Spectrogram

import TFchirp

# Compute S Transform Spectrogram
spectrogram = TFchirp.sTransform(data, sample_rate=rate)
plt.imshow(abs(spectrogram), origin='lower', aspect='auto')
plt.title('Original Spectrogram')
plt.show()

Original Spectrogram

Step 3: Quick recovery of full ts from S transform * 0 frequency row*

(This recovered ts is computed based on the fact that the 0 frequency row always contain the full FFT result of the ts in this program by design.)

# Quick Recovery of ts from S Transform 0 frequency row
recovered_ts = TFchirp.recoverS(spectrogram)
plt.plot(recovered_ts-data)
plt.title('Time Series Reconstruction Error')
plt.show()

Reconstruction Error

Step 4: Recovered spectrogram:

# Compute S Transform Spectrogram on the recovered time series
recoveredSpectrogram = TFchirp.sTransform(recovered_ts, sample_rate=rate, frange=[0,500])
plt.imshow(abs(recoveredSpectrogram), origin='lower', aspect='auto')
plt.title('Recovered Specctrogram')
plt.show()

Recovered

Step 5: The real inverse S transform

# Quick Inverse of ts from S Transform
inverse_ts, inverse_tsFFT = TFchirp.inverseS(spectrogram)
plt.plot(inverse_ts)
plt.plot(inverse_ts-data)
plt.title('Time Series Reconstruction Error')
plt.legend(['Recovered ts', 'Error'])
plt.show()

Recovered ts and Error

Step 6: Recovered spectrogram on the real inverse S transform ts

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

Recovered Spectrogram

tfchirp's People

Contributors

xli2522 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.