Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
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'))
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
Exemplo n.º 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.
"""
================================================================================
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")
Exemplo n.º 5
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")
Exemplo n.º 6
0
#! /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()
# 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")