示例#1
0
# Distributed under terms of the MIT license.
"""
Morlet Scalograms of Lipschitz singularities.

Figure 5.7 from the tutorial
"""

from tftb.processing import scalogram
from tftb.generators import anasing
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt

sig = anasing(64)

tfr, t, f, _ = scalogram(sig, waveparams=4, fmin=0.01, fmax=0.5, n_voices=256)

t, f = np.meshgrid(t, f)

fig, axContour = plt.subplots()
axContour.contour(t, f, tfr, 10)
axContour.grid(True)
axContour.set_title("Morlet Scalogram of Lipschitz singularity")
axContour.set_ylabel('Frequency')
axContour.set_xlabel('Time')

divider = make_axes_locatable(axContour)
axTime = divider.append_axes("top", 1.2, pad=0.5)
axFreq = divider.append_axes("left", 1.2, pad=0.5)
axTime.plot(np.real(sig))
axTime.set_xlim(0, 64)
"""
Morlet Scalograms of Lipschitz singularities.

Figure 5.7 from the tutorial
"""

from tftb.processing import scalogram
from tftb.generators import anasing
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt


sig = anasing(64)

tfr, t, f, _ = scalogram(sig, waveparams=4, fmin=0.01, fmax=0.5, n_voices=256)

t, f = np.meshgrid(t, f)

fig, axContour = plt.subplots()
axContour.contour(t, f, tfr, 10)
axContour.grid(True)
axContour.set_title("Morlet Scalogram of Lipschitz singularity")
axContour.set_ylabel('Frequency')
axContour.set_xlabel('Time')

divider = make_axes_locatable(axContour)
axTime = divider.append_axes("top", 1.2, pad=0.5)
axFreq = divider.append_axes("left", 1.2, pad=0.5)
axTime.plot(np.real(sig))
axTime.set_xlim(0, 64)
#
# Distributed under terms of the MIT license.
"""
Example showing a Morlet scalogram of two atoms.
"""

from tftb.processing import scalogram
from tftb.generators import atoms
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt

# FIXME: squared modulus of scalograms doesn't seem to be necessary.

sig = atoms(128, np.array([[38, 0.1, 32, 1], [96, 0.35, 32, 1]]))
tfr, t, f, _ = scalogram(sig)
t, f = np.meshgrid(t, f)

fig, axContour = plt.subplots()
axContour.contour(t, f, tfr)
axContour.grid(True)
axContour.set_title("Morlet scalogram of complex sinusoids")
axContour.set_ylabel('Frequency')
axContour.yaxis.set_label_position('right')
axContour.set_xlabel('Time')

divider = make_axes_locatable(axContour)
axTime = divider.append_axes("top", 1.2, pad=0.5)
axFreq = divider.append_axes("left", 1.2, pad=0.5)
axTime.plot(np.real(sig))
axTime.set_xticklabels([])
示例#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.

"""
Example showing Morlet scalogram of a Dirac impulse.
"""

from tftb.generators import anapulse
from tftb.processing import scalogram
import numpy as np
import matplotlib.pyplot as plt

sig1 = anapulse(128)
tfr, t, f, _ = scalogram(sig1, waveparams=6, fmin=0.05, fmax=0.45, n_voices=128)
tfr = np.abs(tfr) ** 2
threshold = np.amax(tfr) * 0.05
tfr[tfr <= threshold] = 0.0
t, f = np.meshgrid(t, f)
plt.contour(t, f, tfr, 20)
plt.grid()
plt.title('Morlet Scalogram of a Dirac Impluse')
plt.xlabel('Time')
plt.ylabel('Normalized Frequency')
plt.show()
This example demonstrates the visualization of the Morlet scalogram of a signal
containing two complex sinusoids. In a scalogram, the frequency resolution
varies on the scale of the signal. Here, the frequency resolution decreases at
higher frequencies (lower scale).

"""

from tftb.processing import scalogram
from tftb.generators import fmconst
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt

sig2 = fmconst(128, 0.15)[0] + fmconst(128, 0.35)[0]
tfr, t, f, _ = scalogram(sig2, time_instants=np.arange(1, 129), waveparams=6, fmin=0.05, fmax=0.45, n_voices=128)
tfr = np.abs(tfr) ** 2
threshold = np.amax(tfr) * 0.05
tfr[tfr <= threshold] = 0.0
t, f = np.meshgrid(t, f)

fig, axContour = plt.subplots(figsize=(10, 8))
axContour.contour(t, f, tfr)
axContour.grid(True)
axContour.set_title("Morlet scalogram")
axContour.set_ylabel("Frequency")
axContour.yaxis.set_label_position("right")
axContour.set_xlabel("Time")

divider = make_axes_locatable(axContour)
axTime = divider.append_axes("top", 1.2, pad=0.5)
# Distributed under terms of the MIT license.

"""
Example showing a Morlet scalogram of two atoms.
"""

from tftb.processing import scalogram
from tftb.generators import atoms
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt

# FIXME: squared modulus of scalograms doesn't seem to be necessary.

sig = atoms(128, np.array([[38, 0.1, 32, 1], [96, 0.35, 32, 1]]))
tfr, t, f, _ = scalogram(sig)
t, f = np.meshgrid(t, f)

fig, axContour = plt.subplots()
axContour.contour(t, f, tfr)
axContour.grid(True)
axContour.set_title("Morlet scalogram of complex sinusoids")
axContour.set_ylabel('Frequency')
axContour.yaxis.set_label_position('right')
axContour.set_xlabel('Time')

divider = make_axes_locatable(axContour)
axTime = divider.append_axes("top", 1.2, pad=0.5)
axFreq = divider.append_axes("left", 1.2, pad=0.5)
axTime.plot(np.real(sig))
axTime.set_xticklabels([])
# Copyright © 2015 jaidev <jaidev@newton>
#
# Distributed under terms of the MIT license.

"""
Example showing a Morlet scalogram of of two simultaneous complex sinusoids.
"""

from tftb.processing import scalogram
from tftb.generators import fmconst
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt

sig2 = fmconst(128, .15)[0] + fmconst(128, .35)[0]
tfr, t, f, _ = scalogram(sig2, time_instants=np.arange(1, 129), waveparams=6,
                         fmin=0.05, fmax=0.45, n_voices=128)
tfr = np.abs(tfr) ** 2
threshold = np.amax(tfr) * 0.05
tfr[tfr <= threshold] = 0.0
t, f = np.meshgrid(t, f)

fig, axContour = plt.subplots(figsize=(10, 8))
axContour.contour(t, f, tfr)
axContour.grid(True)
axContour.set_title("Morlet scalogram")
axContour.set_ylabel('Frequency')
axContour.yaxis.set_label_position('right')
axContour.set_xlabel('Time')

divider = make_axes_locatable(axContour)
axTime = divider.append_axes("top", 1.2, pad=0.5)