如何在Tensorflow中实现“ signal.spectrogram”

时间:2019-07-12 16:38:23

标签: python tensorflow scipy

嗨,我正在尝试在tensorflow中实现以下频谱图功能:

from scipy import signal
import matplotlib.pyplot as plt

fs = 10e3
N = 1e5
amp = 2 * np.sqrt(2)
noise_power = 0.01 * fs / 2
time = np.arange(N) / float(fs)
mod = 500*np.cos(2*np.pi*0.25*time)
carrier = amp * np.sin(2*np.pi*3e3*time + mod)
noise = np.random.normal(scale=np.sqrt(noise_power), size=time.shape)
noise *= np.exp(-time/5)
x = carrier + noise

f, t, Sxx = signal.spectrogram(x, fs)
plt.pcolormesh(t, f, Sxx)
plt.ylabel('Frequency [Hz]')
plt.xlabel('Time [sec]')
plt.show()

enter image description here

我知道tensorflow中的contrib软件包具有以下可用方法:

stfts = tf.contrib.signal.stft(X,
    frame_length=1024,
    frame_step=512,
    fft_length=1024)

但是我正在频谱函数中寻找以下参数:

signal.spectrogram(X, smpRate, axis=0, nperseg=nperseg, noverlap=noverlap                                                                   ,detrend=False, scaling='density', window='hanning', return_onesided=True,                                                                   mode='magnitude')

要在一个轴上进行操作,并进行上述其余操作,是否有人对如何执行此操作有任何建议?

谢谢。

0 个答案:

没有答案