#
# 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)
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
====================================================================================================================
Monocomponent Nonstationary Signal with Constant Frequency Modulation and One-Sided Exponential Amplitude Modulation
====================================================================================================================

Generate a monocomponent nonstationary signal with constant frequency
modulation and one-sided exponential amplitude modulation.

"""

from tftb.generators import fmconst, amexpos
import matplotlib.pyplot as plt
from numpy import real

fm, _ = fmconst(256, 0.2)
am = amexpos(256, 100, kind='unilateral')
signal = am * fm

plt.plot(real(signal))
plt.xlabel('Time')
plt.ylabel('Real part')
plt.title('Constant Frequency, One-sided Exponential Amplitude')
plt.xlim(0, 256)
plt.grid()
plt.show()
Ejemplo n.º 3
0
characteristics:
    * One-sided exponential amplitude modulation (See :ref:`amexpos`)
    * 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")
Ejemplo 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.

"""

"""

from tftb.generators import amexpos
import matplotlib.pyplot as plt

x = amexpos(160)
plt.plot(x)
plt.grid()
plt.title("Two sided exponential amplitude modulation")
plt.show()
Ejemplo n.º 5
0
    * One-sided exponential amplitude modulation (See :ref:`amexpos`)
    * Constant frequency modulation (See :ref:`fmconst`)
    * -5 dB complex gaussian noise (See :ref:`noisecg` and :ref:`sigmerge`)

And how to plot its energy spectrum.

Figure 1.10 of the tutorial.
"""


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')
Ejemplo 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.
"""

"""

from tftb.generators import amexpos
import matplotlib.pyplot as plt

x = amexpos(160, kind='unilateral')
plt.plot(x)
plt.grid()
plt.title("One sided exponential amplitude modulation")
plt.show()
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
====================================================================================================================
Monocomponent Nonstationary Signal with Constant Frequency Modulation and One-Sided Exponential Amplitude Modulation
====================================================================================================================

Generate a monocomponent nonstationary signal with constant frequency
modulation and one-sided exponential amplitude modulation.

Figure 2.7 from the tutorial.
"""

from tftb.generators import fmconst, amexpos
import matplotlib.pyplot as plt
from numpy import real

fm, _ = fmconst(256, 0.2)
am = amexpos(256, 100, kind='unilateral')
signal = am * fm

plt.plot(real(signal))
plt.xlabel('Time')
plt.ylabel('Real part')
plt.title('Constant Frequency, One-sided Exponential Amplitude')
plt.xlim(0, 256)
plt.grid()
plt.show()
Ejemplo n.º 8
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 amexpos
import matplotlib.pyplot as plt

x = amexpos(160, kind='unilateral')
plt.plot(x)
plt.grid()
plt.title("One sided exponential amplitude modulation")
plt.show()