* Constant frequency modulation (See :ref:`fmconst`)
    * -5 dB complex gaussian noise (See :ref:`noisecg` and :ref:`sigmerge`)

And how to plot its energy spectrum.

"""


import numpy as np
import matplotlib.pyplot as plt
from tftb.generators import amexpos, fmconst, sigmerge, noisecg

# Generate a noisy transient signal.
transsig = amexpos(64, kind="unilateral") * fmconst(64)[0]
signal = np.hstack((np.zeros((100,)), transsig, np.zeros((92,))))
signal = sigmerge(signal, noisecg(256), -5)
fig, ax = plt.subplots(2, 1)
ax1, ax2 = ax
ax1.plot(np.real(signal))
ax1.grid()
ax1.set_title("Noisy Transient Signal")
ax1.set_xlabel("Time")
ax1.set_xlim((0, 256))
ax1.set_ylim((np.real(signal).max(), np.real(signal.min())))

# Energy spectrum of the signal
dsp = np.fft.fftshift(np.abs(np.fft.fft(signal)) ** 2)
ax2.plot(np.arange(-128, 128, dtype=float) / 256, dsp)
ax2.set_title("Energy spectrum of noisy transient signal")
ax2.set_xlabel("Normalized frequency")
ax2.grid()
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
=======================================
Spectrogram of a Noisy Transient Signal
=======================================

This example demonstrates the simple use of a Spectrogram to localize a signal
in time and frequency. The transient signal appears at the normalized frequency
0.25 and between time points 125 and 160.

Figure 1.11 from the tutorial.
"""

import numpy as np
from scipy.signal import hamming
from tftb.generators import amexpos, fmconst, sigmerge, noisecg
from tftb.processing.cohen import Spectrogram

# Generate a noisy transient signal.
transsig = amexpos(64, kind='unilateral') * fmconst(64)[0]
signal = np.hstack((np.zeros((100, )), transsig, np.zeros((92, ))))
signal = sigmerge(signal, noisecg(256), -5)

fwindow = hamming(65)
spec = Spectrogram(signal, n_fbins=128, fwindow=fwindow)
spec.run()
spec.plot(kind="contour", threshold=0.1, show_tf=False)
# Distributed under terms of the MIT license.
"""
==========================================
Wigner-Ville Distribution of a Noisy Chirp
==========================================

Generate a noisy chirp and visualize its Wigner-Ville spectrum.

Figure 1.6 from the tutorial.
"""

from tftb.generators import fmlin, sigmerge, noisecg
from tftb.processing.cohen import WignerVilleDistribution

# Generate a chirp signal

n_points = 128
fmin, fmax = 0.0, 0.5

signal, _ = fmlin(n_points, fmin, fmax)

# Noisy chirp

noisy_signal = sigmerge(signal, noisecg(128), 0)

# Wigner-Ville spectrum of noisy chirp.

wvd = WignerVilleDistribution(noisy_signal)
wvd.run()
wvd.plot(kind='contour')
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
Example showing use of Hough transform on a Wigner-Ville distribution.
"""

import numpy as np
from tftb.generators import noisecg, sigmerge, fmlin
from tftb.processing.cohen import WignerVilleDistribution
from tftb.processing.postprocessing import hough_transform
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

N = 64
sig = sigmerge(fmlin(N, 0, 0.3)[0], noisecg(N), 1)
tfr, _, _ = WignerVilleDistribution(sig).run()

ht, rho, theta = hough_transform(tfr, N, N)
theta, rho = np.meshgrid(theta, rho)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_wireframe(theta, rho, ht)
ax.set_xlabel('Theta')
ax.set_ylabel('Rho')
plt.show()
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
Example from section 2.6 of the tutorial.
Embedding a mono-component nonstationary signal with linear frequency
modulation and Gaussian amplitude modulation into Gaussian colored noise.
"""

from tftb.generators import fmlin, amgauss, noisecg, sigmerge
from numpy import real
import matplotlib.pyplot as plt

fm, _ = fmlin(256)
am = amgauss(256)
signal = fm * am

noise = noisecg(256, .8)
sign = sigmerge(signal, noise, -10)

plt.plot(real(sign))
plt.xlabel('Time')
plt.ylabel('Real part')
plt.title('Gaussian transient signal embedded in -10 dB colored Gaussian noise')
plt.xlim(0, 256)
plt.grid()
plt.show()
Beispiel #6
0
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
Example from section 1.3.1 of the tutorial.
"""

from tftb.generators import fmlin, sigmerge, noisecg
import matplotlib.pyplot as plt
import numpy as np

# Generate a chirp signal

n_points = 128
fmin, fmax = 0.0, 0.5

signal, _ = fmlin(n_points, fmin, fmax)

# Noisy chirp

noisy_signal = sigmerge(signal, noisecg(128), 0)
plt.plot(np.real(noisy_signal))
plt.xlim(0, 128)
plt.title('Noisy chirp')
plt.ylabel('Real Part')
plt.xlabel('Time')
plt.grid()
plt.show()
Beispiel #7
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
import numpy as np
from tftb.generators import noisecg

noise = noisecg(512)
print noise.mean()
print noise.std()**2
plt.subplot(211), plt.plot(np.real(noise))
plt.xlim(0, 512)
plt.grid()
plt.title('Analytic complex Gaussian noise.')
plt.subplot(212), plt.plot(np.linspace(-0.5, 0.5, 512),
                           abs(np.fft.fftshift(np.fft.fft(noise)))**2)
plt.grid()
plt.title('Energy spectrum')
plt.xlim(-0.5, 0.5)
plt.show()
Beispiel #8
0
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
Example from section 2.6 of the tutorial.
Embedding a mono-component nonstationary signal with linear frequency
modulation and Gaussian amplitude modulation into Gaussian colored noise.
"""

from tftb.generators import fmlin, amgauss, noisecg, sigmerge
from numpy import real
import matplotlib.pyplot as plt

fm, _ = fmlin(256)
am = amgauss(256)
signal = fm * am

noise = noisecg(256, .8)
sign = sigmerge(signal, noise, -10)

plt.plot(real(sign))
plt.xlabel('Time')
plt.ylabel('Real part')
plt.title(
    'Gaussian transient signal embedded in -10 dB colored Gaussian noise')
plt.xlim(0, 256)
plt.grid()
plt.show()
Beispiel #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.

"""

"""

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

noise = noisecg(512)
print noise.mean()
print noise.std() ** 2
plt.subplot(211), plt.plot(np.real(noise))
plt.xlim(0, 512)
plt.grid()
plt.title("Analytic complex Gaussian noise.")
plt.subplot(212), plt.plot(np.linspace(-0.5, 0.5, 512), abs(np.fft.fftshift(np.fft.fft(noise))) ** 2)
plt.grid()
plt.title("Energy spectrum")
plt.xlim(-0.5, 0.5)
plt.show()