"""

from tftb.generators import fmconst, amgauss
from tftb.processing import smoothed_pseudo_wigner_ville
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from scipy.signal import kaiser, hamming

twindow = kaiser(13, 3 * np.pi)
fwindow = kaiser(33, 3 * np.pi)
twindow = hamming(13)
fwindow = hamming(33)

sig = fmconst(128, 0.15)[0] + amgauss(128) * fmconst(128, 0.4)[0]
tfr = smoothed_pseudo_wigner_ville(sig, twindow=twindow, fwindow=fwindow,
                                   freq_bins=128)
threshold = np.abs(tfr) * 0.05
tfr[np.abs(tfr) <= threshold] = 0.0

fig, axImage = plt.subplots()
axImage.contour(np.abs(tfr), extent=[0, 128, 0, 0.5], levels=list(range(5)))
axImage.grid(True)
axImage.set_title("Wigner Ville distribution")
axImage.set_ylabel('Frequency')
axImage.set_xlabel('Time')

divider = make_axes_locatable(axImage)
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, 128)
Example #2
0
def noise_gate_PWVD(data, spread=1000):
	
	# TODO something smoothed_pseudo_wigner_ville
	
	data_volume = wave2vol(data, spread=spread)
	
	# ------- PWVD ---------------------------- #
	fwindow = signal.hamming(1)
	twindow = signal.hamming(1)
	
	de_dup_vol = data_volume[0::spread]
	
	spec = tftb.smoothed_pseudo_wigner_ville(de_dup_vol, fwindow=fwindow, twindow=twindow)
	m = np.max(spec, axis=0)
	
	ada_volume = m * np.max(de_dup_vol)
	
	ada_volume = np.repeat(ada_volume, spread)
	
	ada_volume = ada_volume[0:len(volume)]
	# -----------------------------------------#
	
	volume_scale = ada_volume / data_volume
	
	new_data = np.copy(data)
	new_data = new_data * volume_scale
	
	return new_data
plt.ylabel('Normalized Frequencies')

tfr = WignerVilleDistribution(sig).run()[0]
threshold = np.amax(np.abs(tfr)**2) * 0.05
tfr[np.abs(tfr)**2 <= threshold] = 0.0
plt.subplot(222)
plt.imshow(np.abs(tfr)**2,
           extent=[0, 128, 0, 0.5],
           aspect='auto',
           origin='lower')
plt.grid(True)
plt.title("WV distro")
plt.gca().set_xticklabels([])
plt.gca().set_yticklabels([])

tfr = smoothed_pseudo_wigner_ville(sig)
threshold = np.amax(np.abs(tfr)**2) * 0.05
tfr[np.abs(tfr)**2 <= threshold] = 0.0
plt.subplot(223)
plt.imshow(np.abs(tfr)**2,
           extent=[0, 128, 0, 0.5],
           aspect='auto',
           origin='lower')
plt.grid(True)
plt.title("Smoothed Pseudo WV distro")
plt.xlabel('Time')
plt.ylabel('Normalized Frequencies')

_, rtfr, _ = reassigned_smoothed_pseudo_wigner_ville(sig)
threshold = np.amax(np.abs(rtfr)**2) * 0.05
rtfr[np.abs(rtfr)**2 <= threshold] = 0.0
plt.gca().set_xticklabels([])
plt.grid(True)
plt.title("Ideal instantaneous frequencies")
plt.ylabel('Normalized Frequencies')

tfr = WignerVilleDistribution(sig).run()[0]
threshold = np.amax(np.abs(tfr) ** 2) * 0.05
tfr[np.abs(tfr) ** 2 <= threshold] = 0.0
plt.subplot(222)
plt.imshow(np.abs(tfr) ** 2, extent=[0, 128, 0, 0.5], aspect='auto', origin='bottomleft')
plt.grid(True)
plt.title("WV distro")
plt.gca().set_xticklabels([])
plt.gca().set_yticklabels([])

tfr = smoothed_pseudo_wigner_ville(sig)
threshold = np.amax(np.abs(tfr) ** 2) * 0.05
tfr[np.abs(tfr) ** 2 <= threshold] = 0.0
plt.subplot(223)
plt.imshow(np.abs(tfr) ** 2, extent=[0, 128, 0, 0.5], aspect='auto', origin='bottomleft')
plt.grid(True)
plt.title("Smoothed Pseudo WV distro")
plt.xlabel('Time')
plt.ylabel('Normalized Frequencies')

_, rtfr, _ = reassigned_smoothed_pseudo_wigner_ville(sig)
threshold = np.amax(np.abs(rtfr) ** 2) * 0.05
rtfr[np.abs(rtfr) ** 2 <= threshold] = 0.0
plt.subplot(224)
plt.imshow(np.abs(rtfr) ** 2, extent=[0, 128, 0, 0.5], aspect='auto', origin='bottomleft')
plt.grid(True)
from tftb.generators import fmconst, amgauss
from tftb.processing import smoothed_pseudo_wigner_ville
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from scipy.signal import kaiser, hamming

twindow = kaiser(13, 3 * np.pi)
fwindow = kaiser(33, 3 * np.pi)
twindow = hamming(13)
fwindow = hamming(33)

sig = fmconst(128, 0.15)[0] + amgauss(128) * fmconst(128, 0.4)[0]
tfr = smoothed_pseudo_wigner_ville(sig,
                                   twindow=twindow,
                                   fwindow=fwindow,
                                   freq_bins=128)
threshold = np.abs(tfr) * 0.05
tfr[np.abs(tfr) <= threshold] = 0.0

fig, axImage = plt.subplots()
axImage.contour(np.abs(tfr), extent=[0, 128, 0, 0.5], levels=list(range(5)))
axImage.grid(True)
axImage.set_title("Wigner Ville distribution")
axImage.set_ylabel('Frequency')
axImage.set_xlabel('Time')

divider = make_axes_locatable(axImage)
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))