コード例 #1
1
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
================================================================================
Sampling Effects on the Wigner-Ville Distribution of a Real Valued Gaussian Atom
================================================================================

This example shows the Wigner-Ville distribution of a real valued Gaussian
atom. If a signal is sampled at the Nyquist rate, the WVD is affected by
spectral aliasing and many additional interferences. To fix this, either the
signal may be oversampled, or an analytical signal may be used.

Figure 4.6 from the tutorial.
"""

import numpy as np
from tftb.generators import atoms
from tftb.processing import WignerVilleDistribution

x = np.array([[32, .15, 20, 1],
             [96, .32, 20, 1]])
g = atoms(128, x)
spec = WignerVilleDistribution(np.real(g))
spec.run()
spec.plot(kind="contour", show_tf=True, scale="log")
コード例 #2
0
ファイル: test_postprocessing.py プロジェクト: jaidevd/pytftb
 def test_renyi_information(self):
     """Check if Renyi entropy computation is correct."""
     sig = atoms(128, np.array([[64., 0.25, 20., 1.]]))
     tfr, _, _ = WignerVilleDistribution(sig).run()
     R1 = pproc.renyi_information(tfr)
     sig = atoms(128, np.array([[32., 0.25, 20., 1.], [96., 0.25, 20.,
                                                       1.]]))
     tfr, _, _ = WignerVilleDistribution(sig).run()
     R2 = pproc.renyi_information(tfr)
     self.assertAlmostEqual(R2 - R1, 0.98, places=1)
コード例 #3
0
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
===================================================================
Wigner Ville distribution of a Gaussian Atom and a Complex Sinusoid
===================================================================

This example demonstrates the Wigner Ville distribution of a signal
composed from a Gaussian atom and a complex sinusoid with constant frequency
modulation. Although the representation does isolate the atom and the sinusoid
as independent phenomena in the signal, it also produces some interference
between them.

"""

from tftb.generators import fmconst, amgauss
from tftb.processing import WignerVilleDistribution
import numpy as np

sig = fmconst(128, 0.15)[0] + amgauss(128) * fmconst(128, 0.4)[0]
tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(show_tf=True, kind='contour',
        freq_x=(abs(np.fft.fftshift(np.fft.fft(sig))) ** 2)[::-1][:64],
        freq_y=np.arange(sig.shape[0] / 2))
コード例 #4
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
=============================================
Wigner-Ville Distribution of a Doppler Signal
=============================================

This example shows the Wigner-Ville distribution of a Doppler signal. The
signal steadily rises and falls, but there are many interference terms present
in the time-friequency plane, due to the bilinearity of the signal.

Figure 4.2 from the tutorial.
"""

from tftb.generators import doppler
from tftb.processing import WignerVilleDistribution

fm, am, iflaw = doppler(256, 50.0, 13.0, 10.0, 200.0)
sig = am * fm
dist = WignerVilleDistribution(sig)
tfr, times, freqs = dist.run()
dist.plot(show_tf=True, kind="contour", scale="log")
コード例 #5
0
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
=========================================================
Wigner-Ville Distribution of Chirps with Different Slopes
=========================================================

This example demonstrates the Wigner-Ville distribution of a signal
composed of two chirps with Gaussian amplitude modulation but havind linear
frequency modulations with different slopes. Note that the AF interference
terms are located away from the origin. We can see the two distint signal
terms, but there is some interference around the middle.

"""

from tftb.generators import fmlin, amgauss
from tftb.processing import WignerVilleDistribution
import numpy as np

n_points = 64
sig1 = fmlin(n_points, 0.2, 0.5)[0] * amgauss(n_points)
sig2 = fmlin(n_points, 0.3, 0)[0] * amgauss(n_points)
sig = np.hstack((sig1, sig2))

tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(kind='contour', show_tf=True)
コード例 #6
0
ファイル: 4_1_1_wv_real_signal.py プロジェクト: kingjr/pytftb
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
Example from seciton 4.1.1 of the tutorial.
"""

import numpy as np
from tftb.generators import atoms
from tftb.processing import WignerVilleDistribution
import matplotlib.pyplot as plt

x = np.array([[32, .15, 20, 1], [96, .32, 20, 1]])
g = atoms(128, x)
tfr = WignerVilleDistribution(np.real(g)).run()[0]
threshold = (np.abs(tfr)**2) * 0.05
tfr[np.abs(tfr)**2 <= threshold] = 0.0

plt.contour(np.abs(tfr)**2, levels=range(5))
plt.show()
コード例 #7
0
def wigner_ville_dist(mag):
    from tftb.processing import WignerVilleDistribution
    wvd = WignerVilleDistribution(mag)
    wvd.run()
    wvd.plot(kind="contour" )#, scale="log")
コード例 #8
0
ファイル: ukazi.py プロジェクト: LoremasterLH/MatlabToPython
T=256
N=256
dT=T - 1
window = np.ones(T)
TFD = Spectrogram(sig, n_fbins=N, fwindow=window)
TFD.run()
TFD.plot(kind="contour", threshold=0.1, show_tf=False)

# plt.xlabel('t (s)','FontSize',12)
# plt.ylabel('f (Hz)','FontSize',12)
# plt.title(cat('T=',str(T),',N=',str(N),',dT=',str(dT)))

# ukazi.m:49 -- Note:
# Wigner-Villova časovno-frekvenčna porazdelitev - skoraj idealna časovna in frekvenčna ločljivost

wvd = WignerVilleDistribution(np.real(sig))
wvd.run()
wvd.plot(kind='contour')

tfr, rtfr, hat = pseudo_wigner_ville(np.real(sig))

TFD,t,f=tfrwv(sig,nargout=3)
# ukazi4.m:41
plt.figure()
imagesc(t,f,TFD)
plt.axis('tight')
plt.xlabel('t','FontSize',12)
plt.ylabel('f','FontSize',12)
plt.axis('tight')
plt.axis('xy')
plt.title(cat('Wigner-Villova asovno-frekvenna porazdelitev'))
コード例 #9
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
====================================
Wigner-Ville distribution of a Chirp
====================================

This example shows the wireframe plot of the Wigner-Ville distribution of a
chirp. The WV distribution can take negative values, and has almost perfect
localization in the time-frequency plane.

Figure 4.1 from the tutorial.
"""

from tftb.generators import fmlin
from tftb.processing import WignerVilleDistribution

sig = fmlin(256)[0]
tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(threshold=0.0, kind='wireframe')
コード例 #10
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
=====================================================
Wigner-Ville Distribution of a Dirac Impulse Function
=====================================================

This example demonstrates the Wigner-Ville distribution of a Dirac impulse
function, and shows the limitations of the WV distribution when applied to
broadband signals.

Figure 4.24 from the tutorial.
"""

from tftb.generators import anapulse
from tftb.processing import WignerVilleDistribution

sig = anapulse(128)
wvd = WignerVilleDistribution(sig)
wvd.run()
wvd.plot(kind="contour", scale="log")
コード例 #11
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
====================================
Wigner-Ville distribution of a Chirp
====================================

This example shows the wireframe plot of the Wigner-Ville distribution of a
chirp. The WV distribution can take negative values, and has almost perfect
localization in the time-frequency plane.

Figure 4.1 from the tutorial.
"""

from tftb.generators import fmlin
from tftb.processing import WignerVilleDistribution

sig = fmlin(256)[0]
tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(threshold=0.0, kind='wireframe')
コード例 #12
0
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
====================================================
Wigner Ville Distribution of Analytic Gaussian Atoms
====================================================

This example shows the WVD of and analytic Gaussian atom. As seen in Figure
4.6, the WVD of a real valued signal may present interference terms and
spectral aliasing. One of the ways to fix this is to use an analytic signal,
which divides the spectral domain into two parts: real and imaginary. Thus, the
number of interference terms is also halved. Secondly, analytic signals have no
negative components, so the terms present in the negative half plane also
vanish.

Figure 4.7 from the tutorial.
"""

import numpy as np
from tftb.generators import atoms
from tftb.processing import WignerVilleDistribution

x = np.array([[32, .15, 20, 1], [96, .32, 20, 1]])
g = atoms(128, x)
spec = WignerVilleDistribution(g)
spec.run()
spec.plot(show_tf=True, kind="contour", scale="log")
コード例 #13
0
ファイル: 4_1_2_sin_gauss_wv.py プロジェクト: kingjr/pytftb
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
Example from section 4.1.2 of the tutorials.
"""

from tftb.generators import fmconst, amgauss
from tftb.processing import WignerVilleDistribution
import numpy as np

sig = fmconst(128, 0.15)[0] + amgauss(128) * fmconst(128, 0.4)[0]
tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(show_tf=True, kind='contour',
        freq_x=(abs(np.fft.fftshift(np.fft.fft(sig))) ** 2)[::-1][:64],
        freq_y=np.arange(sig.shape[0] / 2))
コード例 #14
0
ファイル: 4_1_1_wv_surf.py プロジェクト: kingjr/pytftb
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
Examples from section 4.1.1 of the tutorial.
"""

from tftb.generators import fmlin
from tftb.processing import WignerVilleDistribution

sig = fmlin(256)[0]
tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(kind='surf', sqmod=True)
コード例 #15
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
================================================================================
Sampling Effects on the Wigner-Ville Distribution of a Real Valued Gaussian Atom
================================================================================

This example shows the Wigner-Ville distribution of a real valued Gaussian
atom. If a signal is sampled at the Nyquist rate, the WVD is affected by
spectral aliasing and many additional interferences. To fix this, either the
signal may be oversampled, or an analytical signal may be used.

Figure 4.6 from the tutorial.
"""

import numpy as np
from tftb.generators import atoms
from tftb.processing import WignerVilleDistribution

x = np.array([[32, .15, 20, 1], [96, .32, 20, 1]])
g = atoms(128, x)
spec = WignerVilleDistribution(np.real(g))
spec.run()
spec.plot(kind="contour", show_tf=True, scale="log")
コード例 #16
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
===================================================================
Wigner Ville distribution of a Gaussian Atom and a Complex Sinusoid
===================================================================

This example demonstrates the Wigner Ville distribution of a signal
composed from a Gaussian atom and a complex sinusoid with constant frequency
modulation. Although the representation does isolate the atom and the sinusoid
as independent phenomena in the signal, it also produces some interference
between them.

Figure 4.8 from the tutorial.
"""

from tftb.generators import fmconst, amgauss
from tftb.processing import WignerVilleDistribution

sig = fmconst(128, 0.15)[0] + amgauss(128) * fmconst(128, 0.4)[0]
tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(show_tf=True, kind='contour')
コード例 #17
0
sig = np.hstack((sig1, np.zeros((8, )), sig2 + sig3))
iflaw = np.zeros((2, 128))
iflaw[0, :] = np.hstack((if1, np.nan * np.ones((8, )), if2))
iflaw[1, :] = np.hstack((np.nan * np.ones((68, )), if3))

tfr, t, f = ideal_tfr(iflaw)

plt.figure(figsize=(10, 8))
plt.subplot(221)
plt.contour(t, f, tfr, 1)
plt.gca().set_xticklabels([])
plt.grid(True)
plt.title("Ideal instantaneous frequencies")
plt.ylabel('Normalized Frequencies')

tfr = WignerVilleDistribution(sig).run()[0]
threshold = np.amax(np.abs(tfr)**2) * 0.05
tfr[np.abs(tfr)**2 <= threshold] = 0.0
plt.subplot(222)
plt.imshow(np.abs(tfr)**2,
           extent=[0, 128, 0, 0.5],
           aspect='auto',
           origin='lower')
plt.grid(True)
plt.title("WV distro")
plt.gca().set_xticklabels([])
plt.gca().set_yticklabels([])

tfr = smoothed_pseudo_wigner_ville(sig)
threshold = np.amax(np.abs(tfr)**2) * 0.05
tfr[np.abs(tfr)**2 <= threshold] = 0.0
コード例 #18
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
===================================================================
Wigner Ville distribution of a Gaussian Atom and a Complex Sinusoid
===================================================================

This example demonstrates the Wigner Ville distribution of a signal
composed from a Gaussian atom and a complex sinusoid with constant frequency
modulation. Although the representation does isolate the atom and the sinusoid
as independent phenomena in the signal, it also produces some interference
between them.

Figure 4.8 from the tutorial.
"""

from tftb.generators import fmconst, amgauss
from tftb.processing import WignerVilleDistribution

sig = fmconst(128, 0.15)[0] + amgauss(128) * fmconst(128, 0.4)[0]
tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(show_tf=True, kind='contour')
コード例 #19
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
=============================================
Wigner-Ville Distribution of a Doppler Signal
=============================================

This example shows the Wigner-Ville distribution of a Doppler signal. The
signal steadily rises and falls, but there are many interference terms present
in the time-friequency plane, due to the bilinearity of the signal.

Figure 4.2 from the tutorial.
"""

from tftb.generators import doppler
from tftb.processing import WignerVilleDistribution

fm, am, iflaw = doppler(256, 50.0, 13.0, 10.0, 200.0)
sig = am * fm
dist = WignerVilleDistribution(sig)
tfr, times, freqs = dist.run()
dist.plot(show_tf=True, kind="contour", scale="log")
コード例 #20
0
ファイル: 4_1_1_wv_surf.py プロジェクト: dafx/pytftb
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
Examples from section 4.1.1 of the tutorial.
"""

from tftb.generators import fmlin
from tftb.processing import WignerVilleDistribution

sig = fmlin(256)[0]
tfr = WignerVilleDistribution(sig)
tfr.run()
tfr.plot(kind='surf', sqmod=True)