Giter Club home page Giter Club logo

tftb's Introduction

About

scikit-signal is a Python module for signal processing built on top of SciPy and distributed under the 3-Clause BSD license.

For the working branch of the repository please go to: http://github.com/jaidevd/scikit-signal

tftb's People

Contributors

anielsen001 avatar aradhyamathur avatar casabre avatar dietbru avatar jaidevd avatar markyoder avatar omersayli avatar souravsingh avatar wangwuqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tftb's Issues

QA

  • Set up CI
  • Set up landscape checks
  • Set up coveralls
  • Numerical tests for all TF distributions
  • Other miscellaneous tests

Sklearn-like API

Should be able to do things like:

model.fit()
model.fit_transform()
model.transform()

where only the model (which is a BaseTFRepresentation) changes.

Maybe add support for pipelines too.

how do I fftshift my complex spectrogram?

I'm looking at complex-valued radio signals caught from my SDR and normally process spectrograms in their human-understandable (fftshift'd) form.

Here's what scipy produces:
image

and, here's what I get with pytftb:
image

Is there a simple way to make everything conformant?

Thanks,
Russell

Possible optimisation for processing.Scalogram ?

Hi,

I'm not quite sure this is the right place to notify that but here I go.

I've been using the Scalogram method recently and noticed two possible improvements that can help it scale (much) better.

In affine.py, line 173 :
the conversion of self.tfr to complex type is probably not needed here, since it's already created as a complex array in base.py, line 52.

In affine.py, line 164 :
No kwargs are passed in the super method. In turn, the AffineDistribution class cannot pass such kwargs to BaseTFRepresentation. This has the consequence to set the self.tfr size to N x N ( base.py, line 38-39) with N being the length of the signal processed. This causes MemoryError for relatively small signal length.

I don't know if these are by design or not, but by modifying the files on my end I see not difference in output and significant performances improvements.

Thanks for you work,
Best,
Victor

Create gallery of plots

Make a gallery of all plots in the examples. These plots should be entirely compatible with sphinx directives. Each script should produce exactly one plot. Add sufficient description in each plot so that each plot becomes standalone.

List of examples to be fixed

  • Remove all bat sonar examples
  • The subplots in fig 1.10 are produced as two different plots.
  • Spectrogram of noisy transient signal (fig 1.11)
  • STFT of multicomponent nonstationary signal (fig 2.11)
  • Try to generate the data for fig 3.4 (won't fix)
  • Fix the tick angles and positions in all plots
  • Fix all colormaps
  • Set the X axis limits for fig 3.10
  • Add Morlet scalograms (fig 3.19, 3.20, 4.18)
  • fig 4.2 is wholly broken
  • Use proper wireframe in fig 4.1
  • Fix the contour plots for pseudo WV - fig 4.4, fig 4.5, fig 4.6, fig 4.7
  • Contour plots of WV, PWV are wrong in many places
  • Contour plot for the narrow band ambiguity function seems to be flipped upside down
  • Add Bertrand distribution (fig 4.21)
  • Add D-Flandrin distribution (fig 4.22)
  • Add Untberger distribution (fig 4.23)
  • Contour plot of WV of a Dirac impulse (fig 4.24) is showing much fewer contours
  • Add fig 4.25: Wide-band ambiguity function of an Altes signal
  • Figure 5.7, 5.8 : Scalogram of a Lipschitz singularity
  • Figure 5.5: the spectrogram is flipped upside down.
  • Section 5.3: Renyi information computation is wrong

Explicit timestamps as indices

By default. if timestamps of a signal are not provided, integer indices are used. When they are provided, they cannot be arbitrary timestamps since the signal is sliced using timestamps directly, as follows:

self.tfr[indices, self.ts] = self.fwindow[lh + tau] * self.signal[self.ts + tau] * \
    np.conj(self.signal[self.ts - tau])

This needs to be fixed by converting the timestamp indices to intermediate integer indices, and using them to slice the signal.

Possible error in tftb.processing.reassigned.smoothed_pseudo_wigner_ville

I got two questions and truly hope someone can answer. Thank you in advance!!
1.
Considering the following has been given,

tfr[0, icol] = (g2 * xx).sum()
tf2[0, icol] = (tg2 * xx).sum()
tf3[0, icol] = dh[lh + 1] * tfr[0, icol]

Should tau starts from 1 in "for tau in range(int(taumax)):"? Or, it should be something like

for tau in range(int(taumax)):
        points = np.arange(-min([lg, xrow - ti - tau]),
                           min([lg, ti - tau - 1]) + 1)
        g2 = twindow[lg + points]
        g2 = g2 / g2.sum()
        tg2 = g2 * points
        xx = signal[ti + tau - 1 - points] * np.conj(signal[ti - tau - 1 - points])
        tfr[1+tau, icol] = (g2 * xx).sum() * fwindow[1+lh + tau]
        tf2[1+tau, icol] = fwindow[1+lh + tau] * (tg2 * xx).sum()
        tf3[1+tau, icol] = dh[1+lh + tau] * (g2 * xx).sum()
        tfr[n_fbins - tau - 1, icol] = (g2 * np.conj(xx)).sum() * fwindow[1+lh - tau]
        tf2[n_fbins - tau - 1, icol] = (tg2 * np.conj(xx)).sum() * fwindow[1+lh - tau]
        tf3[n_fbins - tau - 1, icol] = dh[1+lh - tau] * (g2 * np.conj(xx)).sum()

Otherwise, tfr will be unequal to SPWVD.

  1. The results in this module, tfr and rtfr are equal due to the following code at the end of the module.
for icol in range(tcol):
        for jcol in range(n_fbins):
            if np.abs(tfr[jcol, icol]) > threshold:
                icolhat = min(max([icol - tf2[jcol, icol], 1]), tcol)
                jcolhat = jcol - tf3[jcol, icol]
                jcolhat = (((int(jcolhat) - 1) % n_fbins) + n_fbins) % n_fbins + 1
                rtfr[jcol, icol] += tfr[jcol, icol]
                tf2[jcol, icol] = jcolhat + 1j * icolhat
            else:
                tf2[jcol, icol] = np.inf * (1 + 1j)
                rtfr[jcol, icol] += tfr[jcol, icol]

I don't think it's reassigning the result.
Should it be like following?

for icol in range(tcol):
    for jcol in range(n_fbins):
        if np.abs(tfr[jcol, icol]) > threshold:
            icolhat = icol - np.round(np.abs(tf2[jcol, icol]))
            icolhat = min([max([icolhat, 1]), tcol])

            jcolhat = jcol - tf3[jcol, icol]
            jcolhat = (((int(jcolhat) - 1) % n_fbins) + n_fbins) % n_fbins + 1
            rtfr[int(jcolhat) - 1, int(icolhat) - 1] += tfr[jcol, icol]
            tf2[jcol, icol] = jcolhat + 1j * icolhat
        else:
            tf2[jcol, icol] = np.inf * (1 + 1j)
            rtfr[jcol, icol] += tfr[jcol, icol]

I'm new to this field, so please forgive me for asking such simple questions.

Create an API similar to the one in the MATLAB toolbox

Like the MATLAB toolbox, the Python API needs to consist of:

  • Signal generation functions:
    • instantaneous amplitude and frequency modulated signals
    • analytic complex noise generation
  • Processing functions
    • time and frequency domain processing
    • visualization and plotting functions

Basic documentation

Set up basic sphix documentation, write detailed docstrings with examples, which render plots wherever applicable.

High level documentation

  • Scope of the toolbox
  • Real world examples
  • Expose toolbox as generators and processing utilities

WignerVillerDistriubtion crashes for different signal lenghts

Hello,

This crashes:

import tftb
import numpy as np
signal = np.zeros(13)
wvd = tftb.processing.WignerVilleDistribution(signal)
wvd.run()

and gives:
Traceback (most recent call last):
File "", line 3, in
File "/Users/[...]/opt/anaconda3/envs/tftb/lib/python3.8/site-packages/tftb/processing/cohen.py", line 165, in run
self.tfr[tausec, icol] = self.signal[icol + tausec, 0] *
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

but this doesn't

import tftb
import numpy as np
signal = np.zeros(12)
wvd = tftb.processing.WignerVilleDistribution(signal)
wvd.run()

Is there are reason for that?

Disambiguate time_samples, timestamps and sampling frequencies

Function parameters like time_samples and timestamps are used in multiple places varyingly, but they mean the same thing. Secondly, many distributions don't accept sampling frequency as an input. This needs to be clarified in all generators and processors.

Wigner Ville Memory Error

I am trying to compute the Wigner Ville Distribution for short audio clips. While it works correctly with small premade signals, the situation changes for wav files. The kernel crashes due to memory error. Huge arrays are needed when a NumPy array of zeroes is initiated. I can bypass this by downsampling my signal. The most I can get is around 20000 samples. More samples and the kernel dies due to the memory error. Am I doing something wrong or is the implementation that memory hungry?

3D plots not working on RTFD

All examples containing 3D plots fail with this error:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/pytftb/envs/latest/local/lib/python2.7/site-packages/sphinx_gallery/gen_rst.py", line 417, in execute_script
    exec(code_block, example_globals)
  File "<string>", line 18, in <module>
  File "/home/docs/checkouts/readthedocs.org/user_builds/pytftb/envs/latest/local/lib/python2.7/site-packages/matplotlib/figure.py", line 1268, in gca
    return self.add_subplot(1, 1, 1, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pytftb/envs/latest/local/lib/python2.7/site-packages/matplotlib/figure.py", line 958, in add_subplot
    a = subplot_class_factory(projection_class)(self, *args, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pytftb/envs/latest/local/lib/python2.7/site-packages/matplotlib/axes/_subplots.py", line 78, in __init__
    self._axes_class.__init__(self, fig, self.figbox, **kwargs)
  File "/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 91, in __init__
    *args, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pytftb/envs/latest/local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 436, in __init__
    self.cla()
  File "/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 1045, in cla
    Axes.cla(self)
  File "/home/docs/checkouts/readthedocs.org/user_builds/pytftb/envs/latest/local/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 897, in cla
    self.grid(self._gridOn, which=rcParams['axes.grid.which'])
  File "/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 1256, in grid
    self._draw_grid = maxes._string_to_bool(b)
AttributeError: 'module' object has no attribute '_string_to_bool'

Plot results separately

Hi @jaidevd,

amazing package, thanks very much!
I might find the answer by locating in the code, but if you could answer that would speed it up:
I was wondering if it's possible to get the computed data and plot the results separately? (eg as a subplot of an other big plot...)

wvd = WignerVilleDistribution(sig)
wvd.run()
# get values from wvd
#wvd.plot(kind="contour", scale="log")  # replace this with ax.plot(...)

1j ?

Quite a few methods in frequency_modulated.py contain np.exp(1j * ... And I noticed this in the mfiles of the origina tftb source. Where is j defined? Did I miss something?

Reassigned spectrogram for an audio signal

Congrats for this library!

I'd like to plot the reassigned spectrogram of an audio frequency sweep (from 100hz to 20khz), available for download here as a WAV file.

from scipy.io import wavfile
from tftb.processing import *
import matplotlib.pyplot as plt

sr, x = wavfile.read('test.wav')
x = x[:1000]
s = reassigned_spectrogram(x)
plt.imshow(s[0])
plt.show()

Problem:

  • With a length of 1000 samples only (i.e. only 23ms), it already takes nearly one minute to compute!
    So it's nearly impossible to test this reassigned spectrogram on a 10 seconds audio file.
    How to improve the performance in this specific case (non-complex real audio signal)?
    (Some audio editors are able to plot reassigned spectrograms quickly, such as Izotope RX, see here)

  • Even on the small portion of audio I tested, I couldn't get a nice plot of the reassigned spectrogram. Would you have a code example of plot of a reassigned spectrogram? Thank you in advance!

Result that I'm looking for:

Easier plotting

Write a unified framework for plotting various distributions, replace the existing plots with this.

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.