Giter Site home page Giter Site logo

jflamant / bispy Goto Github PK

View Code? Open in Web Editor NEW
23.0 4.0 9.0 9.91 MB

BiSPy : a python framework for signal processing of bivariate signals

License: Creative Commons Attribution 4.0 International

Python 5.11% Shell 0.05% Jupyter Notebook 94.84%
signal-processing bivariate-signals quaternion python-toolbox

bispy's Introduction

BiSPy : Bivariate Signal Processing with Python

docs-page PyPI version

BiSPy is an open-source python framework for processing bivariate signals. It supports our papers on time-frequency analysis [1], spectral analysis [2] and linear time-invariant filtering [3] of bivariate signals.

[1] Julien Flamant, Nicolas Le Bihan, Pierre Chainais: “Time-frequency analysis of bivariate signals”, In press, Applied and Computational Harmonic Analysis, 2017; arXiv:1609.0246, doi:10.1016/j.acha.2017.05.007

[2] Julien Flamant, Nicolas Le Bihan, Pierre Chainais: “Spectral analysis of stationary random bivariate signals”, 2017, IEEE Transactions on Signal Processing; arXiv:1703.06417, doi:10.1109/TSP.2017.2736494

[3] Julien Flamant, Pierre Chainais, Nicolas Le Bihan: “A complete framework for linear filtering of bivariate signals”, 2018; Accepted for publication in IEEE Transactions on Signal Processing; arXiv:1802.02469

These papers contains theoretical results and several applications that can be reproduced with this toolbox.

This python toolbox is currently under development and is hosted on GitHub. If you encounter a bug or something unexpected please let me know by raising an issue on the project page.

Install from PyPi

Due to name conflict the available version on PyPi is named ``bispy-polar''. To install from PyPi, simply type

pip install bispy-polar

It will automatically install dependencies (see also below).

To get started, simply use

import bispy as bsp

Requirements

BiSPy works with python 3.5+.

Dependencies:

To install dependencies:

pip install numpy scipy matplotlib numpy-quaternion

numpy-quaternion add quaternion dtype support to numpy. Implementation by [moble]. Since this python toolbox relies extensively on this module, you can check out first the nice introduction here.

License

This software is distributed under the CC-BY 4.0 license.

Cite this work

If you use this package for your own work, please consider citing it with this piece of BibTeX:

@misc{BiSPy,
    title =   {{BiSPy: an Open-Source Python project for processing bivariate signals}},
    author =  {Julien Flamant},
    year =    {2018},
    url =     {https://github.com/jflamant/bispy/},
    howpublished = {Online at: \url{github.com/jflamant/bispy/}},
    note =    {Code at https://github.com/jflamant/bispy/, documentation at https://bispy.readthedocs.io/}
}

bispy's People

Contributors

derekmini avatar jflamant avatar srimbaud 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

Watchers

 avatar  avatar  avatar  avatar

bispy's Issues

Error in utils quat2Euler

Working with python 3.6.1
Running this script :

#Test for bivariate signal.
import numpy as np
import matplotlib.pyplot as plt
import bispy.bispy as bsp #bispy is in the folder bispy for me.
import quaternion as qtn

def main() :
    dt = 1*10**(-4) #Sampling at 10kHz.
    T = 4*10**(-2) #time lenght of the signal.

    time_axis = np.arange(start=0, stop = T, step = dt)
# Modulation function.
    f_a = 30 #modulating frequency 
    f0 = 2000 #Carrier frequency
    ampli_mod = lambda t: np.cos(2*np.pi*f_a*t)+3
    freq_mod = lambda t : 2*np.pi*f0*t
#buildind bivariate signal.
    amplitude = np.apply_along_axis(ampli_mod, 0, time_axis)
    phase = np.apply_along_axis(freq_mod, 0, time_axis)

    signal = amplitude*np.exp(qtn.x*phase)
    
#Generatic analytic signal :
    Hembedded_sig = bsp.timefrequency.Hembedding(signal)
    analytic_sig= Hembedded_sig.Hembedding

#plot
    stft = bsp.timefrequency.QSTFT(time_axis, analytic_sig,\
            bsp.utils.windows.rectangle(257),\
            spacing = 51)
    sig_fig, sig_ax = bsp.utils.visual.plot3D(time_axis,analytic_sig)
    fig, ax = stft.plotStokes()
    fig2, ax2 = stft.plotRidges()
    plt.show()


if __name__=='__main__':
    print("Running main")
    main()

Return :

ValueError                                Traceback (most recent call last)
./src/BiVarTools/bug_trace.py in <module>()
     36 if __name__=='__main__':
     37     print("Running main")
---> 38     main()
     39 

./src/BiVarTools/bug_trace.py in main()
     22 
     23 #Generatic analytic signal :
---> 24     analytic_sig = bsp.timefrequency.Hembedding(signal)
     25 
     26 #plot

./bispy/timefrequency.py in __init__(self, q)
     67 
     68         # Compute Euler angle form
---> 69         a, theta, chi, phi = utils.quat2euler(self.Hembedding)
     70 
     71         self.a = a

./bispy/utils.py in quat2euler(q)
    302 
    303     print("-----Running buggy line------")
--> 304     a, theta, chi = Stokes2geo(S0, S1, S2, S3)
    305 
    306     qi = quaternion.x

ValueError: too many values to unpack (expected 3)

This bug appear when we use Hembedding (which is not used in the tutorial )

name 'sympSplit' is not defined in signal.py

Salut Julien,

N = 100
a = theta = chi = phi = np.ones(N)
h = bsp.signals.bivariateAMFM(a, theta, chi, phi, Hembedding=False, complexOutput=True)

donne un erreur chez moi :

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-81-8ce21a300e11> in <module>
      1 N = 100
      2 a = theta = chi = phi = np.ones(N)
----> 3 h = bsp.signals.bivariateAMFM(a, theta, chi, phi, Hembedding=False, complexOutput=True)

~/Notes/16polar/gwpolar/20icassp/src/mlgw2/bispy/bispy/signals.py in bivariateAMFM(a, theta, chi, phi, Hembedding, complexOutput)
    111         return x
    112     else:
--> 113         x1, x2 = sympSplit(x)
    114         if complexOutput is True:
    115             return x1.real + 1j * x2.real

NameError: name 'sympSplit' is not defined

Error in timefrequency with plotStokes

import quaternion  # load the quaternion module
import numpy as np

#if BiSPy is not located in your python module directory
#import sys
#sys.path.append('/BiSPy_location_path/')
import bispy.bispy as bsp #My bispy module is in a folder named bispy.
pi = np.pi #Added 
N = 1024 # length of the signal

#linear chirps constants
a = 250*pi
b = 50*pi
c = 150*pi
#time vector
t = np.linspace(0, 1, N)

#first chirp
theta1 = pi/4 #constant orientation
chi1 = pi/6-t #reversing ellipticity
phi1 = b*t+a*t**2 #linear chirp

#second chirp
theta2 = pi/4*10*t #rotating orientation
chi2 = 0 #constant null ellipticity
phi2 = c*t+a*t**2 #linear chirp

#common amplitude -- simply a window
env = bsp.utils.windows.hanning(N)
#define chirps x1 and x2
x1 = bsp.utils.bivariateAMFM(env, theta1, chi1, phi1)
x2 = bsp.utils.bivariateAMFM(env, theta2, chi2, phi2)

#sum it
x = x1 + x2
fig, ax = bsp.utils.visual.plot3D(t, x)
fig.show()
window = bsp.utils.windows.hanning(101)
spacing = 1

S = bsp.timefrequency.QSTFT(t, x, window, spacing)

fig, ax = S.plotStokes()
fig.show()

Error at S.plotStokes() :

File "./bispy/timefrequency.py" line 262, in plotStokes
    im0 = ax[0].imshow(self.S1n[:self.Nfft / 2, :], origin='lower', interpolation='none', aspect='auto',cmap=cmap, extent=[self.t.min(), self.t.max(), 0, self.f[self.Nfft / 2-1]], vmin=-1, vmax=+1)
TypeError: slice indices must be integers or None or have an __index__ method

I'm working with python 3.6.1.
Extracted from : tutorial

im2 not defined in frequency.py

Working with python 3.6.1

Sometimes in the function plotRidges the var im2 is ot defined at line 374. When there is no ridges the for loop doesn't define im2 which rises bugs.

        for r in self.ridges: #sometimes self.ridges is empty.
            points = np.array([self.t[::self.spacing][r[1]], self.f[r[0]]]).T.reshape(-1, 1, 2)
            segments = np.concatenate([points[:-1], points[1:]], axis=1)

            lc = LineCollection(segments, cmap=plt.get_cmap(cmap_chi),
                                norm=plt.Normalize(-np.pi / 4, np.pi / 4))
            lc.set_array(chi[(r[0], r[1])])
            lc.set_linewidth(5)
            im2 = ax[2].add_collection(lc)

        #im2 = ax[2].imshow(chi, vmin=-np.pi/4, vmax=np.pi/4,  interpolation='none', origin='lower', aspect='auto', cmap='coolwarm', extent=[self.t.min(), self.t.max(), 0, self.f[N/2-1]])

        # adjust figure
        fig.subplots_adjust(left=0.05, top=0.8, right=0.99, wspace=0.05)

        cbarax0 = fig.add_axes([0.05, 0.83, 0.303, 0.03])
        cbar0 = fig.colorbar(im0, cax=cbarax0, orientation='horizontal', ticks=[0, np.max(self.S0)])
        cbar0.ax.set_xticklabels(['', ''])
        cbar0.ax.xaxis.set_ticks_position('top')

        cbarax1 = fig.add_axes([0.369, 0.83, 0.303, 0.03])
        cbar1 = fig.colorbar(im1, cax=cbarax1, orientation='horizontal', ticks=[-np.pi/2, 0, np.pi/2])
        cbar1.ax.set_xticklabels([r'$-\frac{\pi}{2}$', r'$0$', r'$\frac{\pi}{2}$'])
        cbar1.ax.xaxis.set_ticks_position('top')

        cbarax2 = fig.add_axes([0.686, 0.83, 0.303, 0.03])
        ###Consequently im2 is not defined here when self.ridges is empty.
        cbar2 = fig.colorbar(im2, cax=cbarax2, ticks=[-np.pi/4, 0, np.pi/4], orientation='horizontal') 
        ###
        cbar2.ax.set_xticklabels([r'$-\frac{\pi}{4}$', r'$0$', r'$\frac{\pi}{4}$'])

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.