예제 #1
0
    def test_wigner_ville_regionprops(self):
        """Test the regional property of the Wigner Ville representation."""
        signal, _ = fmsin(128)
        signal[64:] = 0
        tfr, _, _ = cohen.WignerVilleDistribution(signal).run()
        self.assertTrue(np.all(tfr[:, 64:] == 0))

        signal, _ = fmsin(128)
        signal[:64] = 0
        tfr, _, _ = cohen.WignerVilleDistribution(signal).run()
        self.assertTrue(np.all(tfr[:, :64] == 0))
예제 #2
0
    def test_wigner_ville_regionprops(self):
        """Test the regional property of the Wigner Ville representation."""
        signal, _ = fmsin(128)
        signal[64:] = 0
        tfr, _, _ = cohen.WignerVilleDistribution(signal).run()
        self.assertTrue(np.all(tfr[:, 64:] == 0))

        signal, _ = fmsin(128)
        signal[:64] = 0
        tfr, _, _ = cohen.WignerVilleDistribution(signal).run()
        self.assertTrue(np.all(tfr[:, :64] == 0))
예제 #3
0
 def test_wigner_ville_projection(self):
     """Test the projection property of the Wigner Ville representation."""
     signal, _ = fmsin(128)
     tfr, _, _ = cohen.WignerVilleDistribution(signal).run()
     x = np.abs(signal)**2
     y = np.sum(tfr, axis=0) / 128
     np.testing.assert_allclose(x, y)
예제 #4
0
 def test_wigner_ville_projection(self):
     """Test the projection property of the Wigner Ville representation."""
     signal, _ = fmsin(128)
     tfr, _, _ = cohen.WignerVilleDistribution(signal).run()
     x = np.abs(signal) ** 2
     y = np.sum(tfr, axis=0) / 128
     np.testing.assert_allclose(x, y)
예제 #5
0
 def test_pseudo_wv_energy(self):
     """Test the energy property of the pseudo WV representation."""
     signal, _ = fmsin(128)
     signal = signal / 128.0
     tfr = cohen.pseudo_wigner_ville(signal)
     x = np.sum(np.sum(tfr))
     y = np.sum(np.abs(signal)**2) * 128
     self.assertAlmostEqual(x, y, places=3)
예제 #6
0
 def test_pseudo_wv_energy(self):
     """Test the energy property of the pseudo WV representation."""
     signal, _ = fmsin(128)
     signal = signal / 128.0
     tfr, _, _ = cohen.PseudoWignerVilleDistribution(signal).run()
     x = np.sum(np.sum(tfr))
     y = np.sum(np.abs(signal)**2) * 128
     self.assertAlmostEqual(x, y, places=3)
예제 #7
0
 def test_wigner_ville_energy(self):
     """Test the energy property of the Wigner Ville representation."""
     signal, _ = fmsin(128)
     signal = signal / 128.0
     tfr, _, _ = cohen.WignerVilleDistribution(signal).run()
     x = np.sum(np.sum(tfr))
     y = np.sum(np.abs(signal)**2) * 128
     self.assertEqual(x, y)
예제 #8
0
 def test_pseudo_wv_energy(self):
     """Test the energy property of the pseudo WV representation."""
     signal, _ = fmsin(128)
     signal = signal / 128.0
     tfr, _, _ = cohen.PseudoWignerVilleDistribution(signal).run()
     x = np.sum(np.sum(tfr))
     y = np.sum(np.abs(signal) ** 2) * 128
     self.assertAlmostEqual(x, y, places=3)
예제 #9
0
 def test_wigner_ville_energy(self):
     """Test the energy property of the Wigner Ville representation."""
     signal, _ = fmsin(128)
     signal = signal / 128.0
     tfr, _, _ = cohen.WignerVilleDistribution(signal).run()
     x = np.sum(np.sum(tfr))
     y = np.sum(np.abs(signal) ** 2) * 128
     self.assertEqual(x, y)
예제 #10
0
파일: test_cohen.py 프로젝트: dafx/pytftb
 def test_pseudo_wv_energy(self):
     """Test the energy property of the pseudo WV representation."""
     signal, _ = fmsin(128)
     signal = signal / 128.0
     tfr = cohen.pseudo_wigner_ville(signal)
     x = np.sum(np.sum(tfr))
     y = np.sum(np.abs(signal) ** 2) * 128
     self.assertAlmostEqual(x, y, places=3)
예제 #11
0
 def test_page_reality(self):
     """Test the reality property of the Page distribution."""
     signal, _ = fmsin(128)
     signal = signal / 128.0
     tfr, _, _ = cohen.PageRepresentation(signal).run()
     self.assertTrue(np.all(np.isreal(tfr)))
예제 #12
0
 def test_pseudo_wv_reality(self):
     """Test the reality property of the pseudo WV representation."""
     signal, _ = fmsin(128)
     tfr, _, _ = cohen.PseudoWignerVilleDistribution(signal).run()
     self.assertTrue(np.all(np.isreal(tfr)))
Comparison of a Spectrogram and a Reassigned Spectrogram
========================================================

This example compares the spectrogram and the reassigned spectrogram of a
hybrid signal (containing sinusoidal, constant and linear frequency
modulations), against its ideal time-frequency characteristics.

"""

from tftb.generators import fmsin, fmhyp
from tftb.processing import ideal_tfr, reassigned_spectrogram, Spectrogram
import numpy as np
import matplotlib.pyplot as plt

n_points = 128
sig1, if1 = fmsin(n_points, 0.15, 0.45, 100, 1, 0.4, -1)
sig2, if2 = fmhyp(n_points, [1, .5], [32, 0.05])
sig = sig1 + sig2
ideal, t, f = ideal_tfr(np.vstack((if1, if2)))
_, re_spec, _ = reassigned_spectrogram(sig)
spec, t3, f3 = Spectrogram(sig).run()

# Ideal tfr
plt.subplot(221)
plt.contour(t, f, ideal, 1)
plt.grid(True)
plt.gca().set_xticklabels([])
plt.title("Ideal time-frequency distro")
plt.ylabel('Normalized Frequency')

# Spectrogram
예제 #14
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""

"""

from tftb.generators import fmsin
import numpy as np
import matplotlib.pyplot as plt

z = fmsin(140, period=100, t0=20.0, fnorm0=0.3, pm1=-1)[0]
plt.plot(np.real(z))
plt.grid()
plt.title('Sinusoidal Frequency Modulation')
plt.show()
Friedman's Instantaneous Frequency Density Calculation
======================================================

This example uses Friedman's method to calculate the instantaneous frequency
density of a hybrid signal. The method consists of computing the histograms of
frequency displacements of the spectrogram of the signal.

"""

import numpy as np
import matplotlib.pyplot as plt
from tftb.generators import fmlin, fmsin, fmconst
from tftb.processing.reassigned import pseudo_wigner_ville
from tftb.processing.postprocessing import friedman_density

sig1, if1 = fmsin(60, 0.16, 0.35, 50, 1, 0.35, 1)
sig2, if2 = fmlin(60, 0.3, 0.1)
sig3, if3 = fmconst(60, 0.4)
sig = np.hstack((sig1, np.zeros((8,)), sig2 + sig3))

t = np.arange(1, 128, step=2)
tfr, rtfr, hat = pseudo_wigner_ville(sig, timestamps=t)
tifd = friedman_density(tfr, hat, t)
f = np.linspace(0, 0.5, tifd.shape[0])

plt.contour(t, f, tifd, 4)
plt.grid(True)
plt.title("Friedman's instantaenous frequency density")
plt.xlabel('Time')
plt.ylabel('Frequency')
plt.show()
예제 #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.
"""

"""

from tftb.generators import fmlin, fmodany, fmsin
import numpy as np
import matplotlib.pyplot as plt

y1, ifl1 = fmlin(100)
y2, ifl2 = fmsin(100)
iflaw = np.append(ifl1, ifl2)
sig = fmodany(iflaw)

plt.subplot(211), plt.plot(np.real(sig))
plt.grid()
plt.title('Linear and Sinusoidal modulated signal')
plt.subplot(212), plt.plot(iflaw)
plt.grid()
plt.title('Instantaneous frequency')
plt.show()
예제 #17
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""

"""


import matplotlib.pyplot as plt
from tftb.processing import inst_freq
from tftb.generators import fmsin

x = fmsin(70, 0.05, 0.35, 25)[0]
instf, timestamps = inst_freq(x)
plt.plot(timestamps, instf)
plt.xlim(0, 70)
plt.grid()
plt.title("Instantaneous frequency estimation")
plt.xlabel('Time')
plt.ylabel('Frequency')
plt.show()
예제 #18
0
========================================================

This example compares the spectrogram and the reassigned spectrogram of a
hybrid signal (containing sinusoidal, constant and linear frequency
modulations), against its ideal time-frequency characteristics.

Figure 4.34 from the tutorial.
"""

from tftb.generators import fmsin, fmhyp
from tftb.processing import ideal_tfr, reassigned_spectrogram, Spectrogram
import numpy as np
import matplotlib.pyplot as plt

n_points = 128
sig1, if1 = fmsin(n_points, 0.15, 0.45, 100, 1, 0.4, -1)
sig2, if2 = fmhyp(n_points, [1, .5], [32, 0.05])
sig = sig1 + sig2
ideal, t, f = ideal_tfr(np.vstack((if1, if2)))
_, re_spec, _ = reassigned_spectrogram(sig)
spec, t3, f3 = Spectrogram(sig).run()

# Ideal tfr
plt.subplot(221)
plt.contour(t, f, ideal, 1)
plt.grid(True)
plt.gca().set_xticklabels([])
plt.title("Ideal time-frequency distro")
plt.ylabel('Normalized Frequency')

# Spectrogram
예제 #19
0
 def test_pseudo_wv_reality(self):
     """Test the reality property of the pseudo WV representation."""
     signal, _ = fmsin(128)
     tfr = cohen.pseudo_wigner_ville(signal)
     self.assertTrue(np.all(np.isreal(tfr)))
예제 #20
0
파일: test_cohen.py 프로젝트: dafx/pytftb
 def test_pseudo_wv_reality(self):
     """Test the reality property of the pseudo WV representation."""
     signal, _ = fmsin(128)
     tfr = cohen.pseudo_wigner_ville(signal)
     self.assertTrue(np.all(np.isreal(tfr)))
예제 #21
0
import numpy as np
from tftb.generators import fmsin, fmconst, amgauss
from scipy.signal import kaiser
from tftb.processing.reassigned import spectrogram
from pyhht.emd import EMD
import matplotlib.pyplot as plt

N = 2001
T = np.arange(1, N + 1, step=4)
t = np.arange(1, N + 1)

p = N / 2

fmin1 = 1.0 / 64
fmax1 = 1.5 * 1.0 / 8
x1 = fmsin(N, fmin1, fmax1, p, N / 2, fmax1)[0]

fmin2 = 1.0 / 32
fmax2 = 1.5 * 1.0 / 4
x2 = fmsin(N, fmin2, fmax2, p, N / 2, fmax2)[0]

f0 = 1.5 * 1.0 / 16

x3 = amgauss(N, N / 2, N / 8) * fmconst(N, f0)[0]

a1 = 1
a2 = 1
a3 = 1

x = np.real(a1 * x1 + a2 * x2 + a3 * x3)
x = x / np.max(np.abs(x))
예제 #22
0
 def test_pseudo_wv_reality(self):
     """Test the reality property of the pseudo WV representation."""
     signal, _ = fmsin(128)
     tfr, _, _ = cohen.PseudoWignerVilleDistribution(signal).run()
     self.assertTrue(np.all(np.isreal(tfr)))
예제 #23
0
 def test_page_reality(self):
     """Test the reality property of the Page distribution."""
     signal, _ = fmsin(128)
     signal = signal / 128.0
     tfr, _, _ = cohen.PageRepresentation(signal).run()
     self.assertTrue(np.all(np.isreal(tfr)))
# Distributed under terms of the MIT license.
"""
Comparison of the Wigner Ville distribution with its smoothed and reassinged
counterparts.

Figure 4.35 from the tutorial.
"""

import numpy as np
import matplotlib.pyplot as plt
from tftb.generators import fmsin, fmlin, fmconst
from tftb.processing import (ideal_tfr, WignerVilleDistribution,
                             smoothed_pseudo_wigner_ville,
                             reassigned_smoothed_pseudo_wigner_ville)

sig1, if1 = fmsin(60, 0.16, 0.35, 50, 1, 0.35, 1)
sig2, if2 = fmlin(60, 0.3, 0.1)
sig3, if3 = fmconst(60, 0.4)

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)
예제 #25
0
파일: fmsin.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.

"""

"""

from tftb.generators import fmsin
import numpy as np
import matplotlib.pyplot as plt

z = fmsin(140, period=100, t0=20.0, fnorm0=0.3, pm1=-1)[0]
plt.plot(np.real(z))
plt.grid()
plt.title('Sinusoidal Frequency Modulation')
plt.show()