- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
更新:我在 librosa 中重新实现了这个来进行比较,结果确实与 tensorflow 的结果有很大不同。 Librosa 给出了我期望的结果(但不是 tensorflow)。
我已将其发布为 issue在 tensorflow repo 上,但那里很安静,所以我在这里尝试。此外,我不确定这是不是 tensorflow 中的错误,还是代表我的用户错误。为了完整起见,我还将在此处包含完整的来源和结果。
A.) 当我使用汉恩窗口从具有 frame_length=1024
和 frame_step=256
的信号(即 25% 的跳跃大小,75% 的重叠)创建帧时(也尝试了汉明),然后我用 overlap_and_add
进行重构,我希望信号能够正确重构(因为 COLA 等)。但它恰好是振幅的两倍。我需要将生成的信号除以 2 才能正确。
B.) 如果我使用 STFT 创建一系列重叠的频谱图,然后使用逆 STFT 重建,再次使用 frame_length=1024
和 frame_step=256
,信号再次以双倍幅度重建。
我明白为什么会出现这种情况(汉恩在 50% 重叠时的单位增益,因此 75% 重叠将使信号加倍)。但是重构函数考虑到这个不是很正常吗?例如。 librosa istft 确实以正确的幅度返回信号,而 tensorflow 返回两倍。
C.)在任何其他 frame_step 中,都会进行严重的幅度调制。见下图。这似乎根本不对。
更新:如果我在 inverse_stft
中明确设置 window_fn=tf.contrib.signal.inverse_stft_window_fn(frame_step)
,则输出是正确的。所以似乎 inverse_stft
中的 frame_step
没有被传递到窗口函数中(这也是结果所暗示的)。
原始数据:
frames + overlap_and_add 的 tensorflow 输出:
stft+istft 的 tensorflow 输出:
stft+istft 的 librosa 输出:
tensorflow 代码:
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy.io.wavfile
import math
import random
import matplotlib.pyplot as plt
import tensorflow as tf
out_prefix = 'tensorflow'
def plot(data, title, do_save=True):
plt.figure(figsize=(20,5))
plt.plot(data[:3*frame_length])
plt.ylim([-1, 1])
plt.title(title)
plt.grid()
if do_save: plt.savefig(title + '.png')
plt.show()
def reconstruct_from_frames(x, frame_length, frame_step):
name = 'frame'
frames_T = tf.contrib.signal.frame(x, frame_length=frame_length, frame_step=frame_step)
windowed_frames_T = frames_T * tf.contrib.signal.hann_window(frame_length, periodic=True)
output_T = tf.contrib.signal.overlap_and_add(windowed_frames_T, frame_step=frame_step)
return name, output_T
def reconstruct_from_stft(x, frame_length, frame_step):
name = 'stft'
spectrograms_T = tf.contrib.signal.stft(x, frame_length, frame_step)
output_T = tf.contrib.signal.inverse_stft(spectrograms_T, frame_length, frame_step)
return name, output_T
def test(fn, input_data):
print('-'*80)
tf.reset_default_graph()
input_T = tf.placeholder(tf.float32, [None])
name, output_T = fn(input_T, frame_length, frame_step)
title = "{}.{}.{}.l{}.s{}".format(out_prefix, sample_rate, name, frame_length, frame_step)
print(title)
with tf.Session():
output_data = output_T.eval({input_T:input_data})
# output_data /= frame_length/frame_step/2 # tensorflow needs this to normalise amp
plot(output_data, title)
scipy.io.wavfile.write(title+'.wav', sample_rate, output_data)
def generate_data(duration_secs, sample_rate, num_sin, min_freq=10, max_freq=500, rnd_seed=0, max_val=0):
'''generate signal from multiple random sin waves'''
if rnd_seed>0: random.seed(rnd_seed)
data = np.zeros([duration_secs*sample_rate], np.float32)
for i in range(num_sin):
w = np.float32(np.sin(np.linspace(0, math.pi*2*random.randrange(min_freq, max_freq), num=duration_secs*sample_rate)))
data += random.random() * w
if max_val>0:
data *= max_val / np.max(np.abs(data))
return data
frame_length = 1024
sample_rate = 22050
input_data = generate_data(duration_secs=1, sample_rate=sample_rate, num_sin=1, rnd_seed=2, max_val=0.5)
title = "{}.orig".format(sample_rate)
plot(input_data, title)
scipy.io.wavfile.write(title+'.wav', sample_rate, input_data)
for frame_step in [256, 512, 768, 1024]:
test(reconstruct_from_frames, input_data)
test(reconstruct_from_stft, input_data)
print('done.')
librosa 代码:
from __future__ import print_function
from __future__ import division
import numpy as np
import scipy.io.wavfile
import math
import random
import matplotlib.pyplot as plt
import librosa.core as lc
out_prefix = 'librosa'
def plot(data, title, do_save=True):
plt.figure(figsize=(20,5))
plt.plot(data[:3*frame_length])
plt.ylim([-1, 1])
plt.title(title)
plt.grid()
if do_save: plt.savefig(title + '.png')
plt.show()
def reconstruct_from_stft(x, frame_length, frame_step):
name = 'stft'
stft = lc.stft(x, n_fft=frame_length, hop_length=frame_step)
istft = lc.istft(stft, frame_step)
return name, istft
def test(fn, input_data):
print('-'*80)
name, output_data = fn(input_data, frame_length, frame_step)
title = "{}.{}.{}.l{}.s{}".format(out_prefix, sample_rate, name, frame_length, frame_step)
print(title)
# output_data /= frame_length/frame_step/2 # tensorflow needs this to normalise amp
plot(output_data, title)
scipy.io.wavfile.write(title+'.wav', sample_rate, output_data)
def generate_data(duration_secs, sample_rate, num_sin, min_freq=10, max_freq=500, rnd_seed=0, max_val=0):
'''generate signal from multiple random sin waves'''
if rnd_seed>0: random.seed(rnd_seed)
data = np.zeros([duration_secs*sample_rate], np.float32)
for i in range(num_sin):
w = np.float32(np.sin(np.linspace(0, math.pi*2*random.randrange(min_freq, max_freq), num=duration_secs*sample_rate)))
data += random.random() * w
if max_val>0:
data *= max_val / np.max(np.abs(data))
return data
frame_length = 1024
sample_rate = 22050
input_data = generate_data(duration_secs=1, sample_rate=sample_rate, num_sin=1, rnd_seed=2, max_val=0.5)
title = "{}.orig".format(sample_rate)
plot(input_data, title)
scipy.io.wavfile.write(title+'.wav', sample_rate, input_data)
for frame_step in [256, 512, 768, 1024]:
test(reconstruct_from_stft, input_data)
print('done.')
(刚刚尝试使用 TF1.5、Cuda9.0、cuDNN 7.0.5,结果相同)。
最佳答案
你应该使用tf.signal.inverse_stft_window_fn
window_fn=tf.signal.inverse_stft_window_fn(frame_step)
tf_istfts=tf.signal.inverse_stft(tf_stfts, frame_length=frame_length, frame_step=frame_step, fft_length=fft_length, window_fn=window_fn)}
查看更多信息 inverse_stft_window_fn
关于python - 使用 tensorflow.contrib.signal 重建信号会导致放大或调制(帧、overlap_and_add、stft 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48510229/
如果我使用 alter index x rebuild 重建不可用的索引,是否会重新评估之前使用该索引的任何 SQL 的执行计划? 我知道在我使用的数据库版本 - Oracle 10.2.0.4.0
我正在研究 3d 重建。现在当我考虑一对图像时。我有一组对应点。我有我的相机详细信息。例如我有焦点细节,旋转和平移矩阵(4 * 4)。我想在 3D(三角剖分)中投影我的点。因此,据我所知,因子代数非常
从教程中:https://programtalk.com/vs2/?source=python/8176/opencv-python-blueprints/chapter4/scene3D.py 我不
我需要您的帮助和建议。这个问题包括以下几项:某房间的照片,该房间站在严格固定位置的房间内(一个房间围绕轴线旋转)。如何将所有这些图片组合在一起,从而产生一种效果,就像我们用眼睛看到的一样?从一点开始就
嘿那里,以下问题:我在工作中使用一个相当奇怪的 Linux 发行版(Centos 5),它似乎有一个较旧的内核(或者至少在内核中存在一些差异),并且您不能简单地更新它。我需要安装的程序需要一个函数 c
我读了一些关于受限玻尔兹曼机的文章。这些机器的重建能力经过了测试。我了解训练是如何进行的,但不了解重建是如何完成的。有人可以给我一些提示吗? 最佳答案 杰夫·辛顿 (Geoff Hinton) 的演讲
如果轻量级迁移失败,我将尝试重建核心数据数据堆栈,并将用户送回登录屏幕。我正在通过将一对多关系更改为一对一关系来对此进行测试。 起初,我在删除新的 persistentStoreCoordinator
以下所列示例中中 `table_name` 表示数据表名,`index_name` 表示索引名,column list 表示字段列表(如:`id`,`order_id`)。 1、创建索引 索引的
当您根据 ListView.builder 和 ListView.separated valueKey = key; return _messages
切换底部导航页面后,我有一个非常烦人的谷歌地图 flutter 重建问题。我已经坚持了最后一次缩放和相机位置,但是每次我进入 map 页面时,小部件都会自行重建。如何预防? 最佳答案 采用 Autom
我是 Python 的新手。我在重建一个错误的 Dataframe 时遇到了麻烦。我的数据框如下所示: df = pd.DataFrame({'col1': ['id 1', 'id 2', 'tes
我正在尝试从 2 个图像中实现 3d 重建。我遵循的步骤是, 1. Found corresponding points between 2 images using SURF. 2. Impleme
// Start with this JSON var initialJson = { "rows": [{ "ID": 123, "Data": 430910, "Ver
在有状态的小部件中,我有一个导航部分,用户可以在其中选择父项,并在子项下方显示。 当我选择父级也可以重建子部件时,但是当我导航抛出父项而不选择一个子部件时,父级也可以重建(这是正常的),但是子部件也可
我有一个网络摄像头,它可以围绕人的头部以给定的角度步长旋转,并为每一步获取一张图片。 我正在寻找一个免费的开源库,该库从获取的图像集开始,使我能够生成代表人头部的 3D 表面,或者至少是定义明确的 3
我想从一行中读取一个字符串,然后将其放入一个变量中,该变量随后用作文件名。该字符串位于 .csv 文件中的第二行末尾。由于不必要的标题,需要删除第一行。还有‘;’旧 .csv 文件中使用的内容需要替换
我正在使用file-embed如此封装: import qualified Data.ByteString as B import qualified Data.ByteString.Internal
我的 makefile 总是重建,不明白为什么.. 这里是: SRC = $(DIR)/my_getnbr.c \ $(DIR)/my_isneg.c \ $(DI
我有一个附带编辑器的 Eclipse 插件。 我添加了更改语法突出显示颜色的首选项,但这些更改仅在我手动重新启动编辑器后才适用。 我通过一个 DefaultDamagerRepairer 实现了语法高
我有一段 php 可以输出 div(取决于数组中有多少个)并为该 div 分配一个 id(即 div_1、div_2)等 我还设置了一个隐藏字段,其中包含输出了多少个 div 的计数(divcount
我是一名优秀的程序员,十分优秀!