#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
==================================================
Linear Frequency and Gaussian Amplitude Modulation
==================================================

Generate a mono-component nonstationary signal with linear frequency
modulation and Gaussian amplitude modulation.

"""

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


fm, _ = fmlin(256)
am = amgauss(256)
signal = fm * am
plt.plot(real(signal))
plt.xlabel("Time")
plt.ylabel("Real part")
plt.title("Linear Frequency, Gaussian Amplitude")
plt.xlim(0, 256)
plt.grid()
plt.show()
Beispiel #2
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 amgauss
import matplotlib.pyplot as plt

x = amgauss(160, 90, 40.0)
plt.plot(x)
plt.grid()
plt.title('Gaussian Amplitude Modulation')
plt.show()
Beispiel #3
0
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
Example in section 2.4 of the tutorial.
"""

import numpy as np
import matplotlib.pyplot as plt
from tftb.generators import amgauss, fmlin
from tftb.processing import loctime, locfreq, inst_freq, group_delay

time_instants = np.arange(2, 256)
sig1 = amgauss(256, 128, 90) * fmlin(256)[0]
tm, T1 = loctime(sig1)
fm, B1 = locfreq(sig1)
ifr1 = inst_freq(sig1, time_instants)[0]
f1 = np.linspace(0, 0.5 - 1.0 / 256, 256)
gd1 = group_delay(sig1, f1)

plt.subplot(211)
plt.plot(time_instants, ifr1, '*', label='inst_freq')
plt.plot(gd1, f1, '-', label='group delay')
plt.xlim(0, 256)
plt.grid(True)
plt.legend()
plt.title("Time-Bandwidth product: {0}".format(T1 * B1))
plt.xlabel('Time')
plt.ylabel('Normalized Frequency')
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
Example in section 2.2.2 of the tutorial.
"""

from tftb.generators import amgauss
from tftb.processing import loctime, locfreq
import numpy as np
import matplotlib.pyplot as plt

# generate signal
signal = amgauss(256)
plt.subplot(211), plt.plot(np.real(signal))
plt.xlim(0, 256)
plt.xlabel('Time')
plt.ylabel('Real part')
plt.title('Signal')
plt.grid()
fsig = np.fft.fftshift(np.abs(np.fft.fft(signal)) ** 2)
plt.subplot(212), plt.plot(np.linspace(0, 0.5, 256), fsig)
plt.xlabel('Normalized frequency')
plt.ylabel('Squared modulus')
plt.title('Spectrum')
plt.grid()
plt.subplots_adjust(hspace=0.5)
plt.show()
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
==========================================================================
Pseudo-Wigner-Ville Distribution of a Gaussian Atom and a Complex Sinusoid
==========================================================================

This example demonstrates the pseudo Wigner Ville distribution of a signal
composed from a Gaussian atom and a complex sinusoid with constant frequency
modulation. Note that the frequency resolution is relatively worse than that of
the Wigner-Ville representation, and the interferences have not been resolved
properly.

Figure 4.9 from the tutorial.
"""

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

sig = fmconst(128, 0.15)[0] + amgauss(128) * fmconst(128, 0.4)[0]
tfr = PseudoWignerVilleDistribution(sig)
tfr.run()
tfr.plot(show_tf=True, kind="contour")
Beispiel #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 amgauss, fmlin
import numpy as np
import matplotlib.pyplot as plt

z = amgauss(128, 50.0, 30.0) * fmlin(128, 0.05, 0.3, 50)[0]
plt.plot(np.real(z))
plt.xlim(0, 128)
plt.grid()
plt.title('Linear Frequency Modulation')
plt.show()
Beispiel #7
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()
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
==========================================================================
Pseudo-Wigner-Ville Distribution of a Gaussian Atom and a Complex Sinusoid
==========================================================================

This example demonstrates the pseudo Wigner Ville distribution of a signal
composed from a Gaussian atom and a complex sinusoid with constant frequency
modulation. Note that the frequency resolution is relatively worse than that of
the Wigner-Ville representation, and the interferences have not been resolved
properly.

"""

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

sig = fmconst(128, 0.15)[0] + amgauss(128) * fmconst(128, 0.4)[0]
tfr = PseudoWignerVilleDistribution(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))
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.
"""

"""

from tftb.generators import amgauss, fmconst
import numpy as np
import matplotlib.pyplot as plt

z = amgauss(128, 50.0, 30.0) * fmconst(128, 0.05, 50)[0]
plt.plot(np.real(z))
plt.xlim(0, 128)
plt.grid()
plt.title('Constant Frequency Modulation')
plt.show()
Beispiel #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.
"""

"""

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

z = amgauss(128, 50.0, 30.0) * fmlin(128, 0.05, 0.3, 50)[0]
plt.plot(np.real(z))
plt.xlim(0, 128)
plt.grid()
plt.title('Linear Frequency Modulation')
plt.show()
Beispiel #11
0
 def setUp(self):
     x = fmlin(64, 0.2, 0.5)[0] * amgauss(64)
     y = fmlin(64, 0.3, 0)[0] * amgauss(64)
     self.signal = np.hstack((x, y))
     self.tfr, self.lag, self.doppler = ambiguity.narrow_band(self.signal)
Beispiel #12
0
 def setUp(self):
     x = fmlin(64, 0.2, 0.5)[0] * amgauss(64)
     y = fmlin(64, 0.3, 0)[0] * amgauss(64)
     self.signal = np.hstack((x, y))
     self.tfr, self.lag, self.doppler = ambiguity.narrow_band(self.signal)
Beispiel #13
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 amgauss
import matplotlib.pyplot as plt

x = amgauss(160, 90)
plt.plot(x)
plt.grid()
plt.title('Gaussian Amplitude Modulation')
plt.show()
Beispiel #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 amgauss
import matplotlib.pyplot as plt

x = amgauss(160)
plt.plot(x)
plt.grid()
plt.title('Gaussian Amplitude Modulation')
plt.show()
#
# 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)
Beispiel #16
0
    * time center
    * time duration
    * frequency center
    * frequency spreading

Example 2.1 from the tutorial.
"""

from tftb.generators import fmlin, amgauss
from tftb.processing import loctime, locfreq
import numpy as np
import matplotlib.pyplot as plt

# generate signal
signal = fmlin(256)[0] * amgauss(256)
plt.subplot(211), plt.plot(np.real(signal))
plt.xlim(0, 256)
plt.xlabel('Time')
plt.ylabel('Real part')
plt.title('Signal')
plt.grid()
fsig = np.fft.fftshift(np.abs(np.fft.fft(signal))**2)
plt.subplot(212), plt.plot(np.linspace(0, 0.5, 256), fsig)
plt.xlabel('Normalized frequency')
plt.ylabel('Squared modulus')
plt.title('Spectrum')
plt.grid()
plt.subplots_adjust(hspace=0.5)
plt.show()
Beispiel #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 numpy as np
import matplotlib.pyplot as plt
from tftb.generators import amgauss, fmlin
from tftb.processing import group_delay

x = amgauss(128, 64.0, 30) * fmlin(128, 0.1, 0.4)[0]
fnorm = np.arange(0.1, 0.38, step=0.04)
gd = group_delay(x, fnorm)
plt.plot(gd, fnorm)
plt.xlim(0, 128)
plt.grid()
plt.title('Group delay estimation of linear chirp')
plt.xlabel('Group delay')
plt.ylabel('Normalized frequency')
plt.show()
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
================================================
Time-frequency Resolution: Long Analysis Window
================================================

This example shows the effect of an analysis window which is long in time on
the time-frequency resolution. Specifically, longer windows have good frequency
resolutions but poor time resolutions.

"""

import numpy as np
from tftb.processing.linear import ShortTimeFourierTransform
from tftb.generators import fmlin, amgauss
import matplotlib.pyplot as plt

x = np.real(amgauss(128) * fmlin(128)[0])
window = np.ones((128,))
stft = ShortTimeFourierTransform(x, n_fbins=128, fwindow=window)
stft.run()
stft.plot(show_tf=True, cmap=plt.cm.gray)
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))

decomposer = EMD(x)
imf = decomposer.decompose()

n_freq_bins = 256
short_window_length = 127
beta = 3 * np.pi
window = kaiser(short_window_length, beta=beta)
# vim:fenc=utf-8
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.
"""
Example in section 2.2.2 of the tutorial.
"""

from tftb.generators import amgauss
from tftb.processing import loctime, locfreq
import numpy as np
import matplotlib.pyplot as plt

# generate signal
signal = amgauss(256)
plt.subplot(211), plt.plot(np.real(signal))
plt.xlim(0, 256)
plt.xlabel('Time')
plt.ylabel('Real part')
plt.title('Signal')
plt.grid()
fsig = np.fft.fftshift(np.abs(np.fft.fft(signal))**2)
plt.subplot(212), plt.plot(np.linspace(0, 0.5, 256), fsig)
plt.xlabel('Normalized frequency')
plt.ylabel('Squared modulus')
plt.title('Spectrum')
plt.grid()
plt.subplots_adjust(hspace=0.5)
plt.show()
Beispiel #21
0
#! /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.3 of the tutorial.
"""

from tftb.generators import fmlin, amgauss
from tftb.processing.ambiguity import narrow_band
import numpy as np
import matplotlib.pyplot as plt

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, x, y = narrow_band(sig)
plt.contour(2 * x, y, np.abs(tfr)**2, 16)
plt.title('Narrow Band ambiguity function')
plt.xlabel('Delay')
plt.ylabel('Doppler')
plt.grid(True)
plt.show()
Beispiel #22
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 amgauss
import matplotlib.pyplot as plt

x = amgauss(160, 90)
plt.plot(x)
plt.grid()
plt.title('Gaussian Amplitude Modulation')
plt.show()
from tftb.generators import fmlin, amgauss
import numpy as np
import matplotlib.pyplot as plt

y_nonstat, _ = fmlin(2048)  # Already analytic, no need of Hilbert transorm
y_nonstat *= amgauss(2048)
plt.plot(np.real(y_nonstat), np.imag(y_nonstat))
plt.xlabel("Real part")
plt.ylabel("Imaginary part")
plt.show()
Instantaneous frequency and group delay are very closely related. The former is
the frequency of a signal at a given instant, and the latter is the time delay
of frequency components. As this example shows, they coincide with each other
for a given signal when the time bandwidth product of the signal is
sufficiently high.

"""

import numpy as np
import matplotlib.pyplot as plt
from tftb.generators import amgauss, fmlin
from tftb.processing import loctime, locfreq, inst_freq, group_delay

time_instants = np.arange(2, 256)
sig1 = amgauss(256, 128, 90) * fmlin(256)[0]
tm, T1 = loctime(sig1)
fm, B1 = locfreq(sig1)
ifr1 = inst_freq(sig1, time_instants)[0]
f1 = np.linspace(0, 0.5 - 1.0 / 256, 256)
gd1 = group_delay(sig1, f1)

plt.subplot(211)
plt.plot(time_instants, ifr1, '*', label='inst_freq')
plt.plot(gd1, f1, '-', label='group delay')
plt.xlim(0, 256)
plt.grid(True)
plt.legend()
plt.title("Time-Bandwidth product: {0}".format(T1 * B1))
plt.xlabel('Time')
plt.ylabel('Normalized Frequency')
Beispiel #25
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 amgauss, fmconst
import numpy as np
import matplotlib.pyplot as plt

z = amgauss(128, 50.0, 30.0) * fmconst(128, 0.05, 50)[0]
plt.plot(np.real(z))
plt.xlim(0, 128)
plt.grid()
plt.title('Constant Frequency Modulation')
plt.show()
Beispiel #26
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 section 3.1.4 of the tutorial.
"""

import numpy as np
from tftb.processing.linear import ShortTimeFourierTransform
from tftb.generators import fmlin, amgauss
from matplotlib.pyplot import cm

x = np.real(amgauss(128) * fmlin(128)[0])
window = np.array([1])
stft = ShortTimeFourierTransform(x, n_fbins=128, fwindow=window)
tfr, _, _ = stft.run()

stft.plot(show_tf=True, cmap=cm.gray)
Beispiel #27
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 numpy as np
import matplotlib.pyplot as plt
from tftb.generators import amgauss, fmlin
from tftb.processing import group_delay

x = amgauss(128, 64.0, 30) * fmlin(128, 0.1, 0.4)[0]
fnorm = np.arange(0.1, 0.38, step=0.04)
gd = group_delay(x, fnorm)
plt.plot(gd, fnorm)
plt.xlim(0, 128)
plt.grid()
plt.title('Group delay estimation of linear chirp')
plt.xlabel('Group delay')
plt.ylabel('Normalized frequency')
plt.show()
#
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
Example in section 2.2.1 of the tutorial.
"""

from tftb.generators import fmlin, amgauss
from tftb.processing import loctime, locfreq
import numpy as np
import matplotlib.pyplot as plt

# generate signal
signal = fmlin(256)[0] * amgauss(256)
plt.subplot(211), plt.plot(np.real(signal))
plt.xlim(0, 256)
plt.xlabel('Time')
plt.ylabel('Real part')
plt.title('Signal')
plt.grid()
fsig = np.fft.fftshift(np.abs(np.fft.fft(signal)) ** 2)
plt.subplot(212), plt.plot(np.linspace(0, 0.5, 256), fsig)
plt.xlabel('Normalized frequency')
plt.ylabel('Squared modulus')
plt.title('Spectrum')
plt.grid()
plt.subplots_adjust(hspace=0.5)
plt.show()
Beispiel #29
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 amgauss
import matplotlib.pyplot as plt

x = amgauss(160)
plt.plot(x)
plt.grid()
plt.title('Gaussian Amplitude Modulation')
plt.show()