- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在将 Python 代码转换为 MATLAB。 Python 代码,使用以下命令:
stft_ch = librosa.core.stft(audio_input[:, ch_cnt], n_fft=self._nfft,
hop_length=self._hop_len, win_length=self._win_len,
window='hann')
其中 audio_input.shape=(2880000, 4)
、self._nfft=2048
、self._hop_len=960
和 self._win_len=1920
。
在转换为 MATLAB 时我使用了:
stft_ch = spectrogram(audio_input(:, ch_cnt), hann(win_len), win_len-hop_len, nfft);
我在其中验证了 size(audio_input)=2880000, 4
、win_len=1920
、win_len-hop_len=960
和 nfft =2048
。
我从 MATLAB 获得了 size(stft_ch)=1025, 2999
的输出,其中 Python 显示 stft_ch.shape=(1025, 3001)
。 MATLAB 输出中的大小 2999
很清楚并且超过了 documentation其中 k = ⌊(Nx – noverlap)/(length(window) – noverlap)⌋
如果 window 是一个向量。
但是,我在 Python documentation 中找不到t
的长度是如何设置的。
为什么尺寸之间存在差异?我的转换好吗?
是否有一个 Python 函数可以产生更类似于 MATLAB 的 spectrogram()
的输出,以便我可以获得具有相同大小的复数输出?
最佳答案
我自己找到了答案。
MATLAB 函数 spectrogram()
输出一个时间向量,它对应于每个窗口的中间,同时省略最后一个窗口。例如,具有 3 个样本窗口和 1 个样本重叠的 10 个样本长度信号将产生以下 4 个窗口:
1:3
, 3:5
, 5:7
, 7:9
, 其中m:n
表示一个窗口,其中包含来自 m
的样本至 n
包括 n
第个样本。
因此, window 的中心将是:2,4,6,8
.请注意,第 10 个样本不包括在内。
似乎 MATLAB 需要最大 number_of_windows
隶属于(number_of_windows-1)*hop_length+window_size<=number_of_samples
.
关于python版本liberosa.core.stft()
另一方面,t 是每个帧的第一个样本的时间,帧覆盖的范围比输入信号多。例如,具有 3 个样本窗口和 2 个样本跳跃(跳跃且不重叠)的 10 个样本长度信号将产生以下 4 个窗口:
1:3
, 3:5
, 5:7
, 7:9
, 9:11
, 其中m:n
表示一个窗口,其中包含来自 m
的样本至 n
包括 n
第个样本。
因此,窗口的开头是:1,3,5,7,9
.请注意,包括第 11 个不存在的样本。
似乎 liberosa 需要最少的 number_of_windows
隶属于number_of_windows*hop_length>number_of_samples
.
以我为例:
(2999-1)960+1920=2880000<=2880000 对于 MATLAB。3001960=2880960>2880000 而 30000*960=2880000 !> 2880000 在 python 中。
请注意,可以通过设置 center=True
在 Python 中将时间居中旗帜。
这是我能找到的最好的解释。
关于python - python librosa.core.stft() 和 matlab spectrogram(x) 的输出之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55474581/
以下是否相同? 读取音频文件,然后将其裁剪为特定的帧长,并在摘录中执行短时傅立叶变换 代码:stft(cropAudio(readAudio(wav))) 读取音频文件,然后对整个音频文件执行短时傅立
我使用scipy.signal.stft来获取音频的stft。没问题,我正在得到结果。但我不明白的是,当使用采样率为fs=44100 Hz的169600个样本的音频来计算stft时,我得到 3 个返回
作为一个简单的实验,我想计算 stft音频文件: sample_rate, samples = wav.read(file) f, t, Zxx = stft(samples, sample_rate
所以这里的想法是:您可以使用短时傅里叶变换 (stft) 从音频文件生成频谱图。然后有些人生成了一种称为“二进制掩码”的东西,以从反向 stft 生成不同的音频(即,去除背景噪声等)。 以下是我的理解
我目前正在使用 matplotlib 计算频谱图。我指定 NFFT=512,但生成的图像高度为 257。然后,我尝试执行 STFT(短时傅里叶变换),它给出了 512 维向量(如预期)。如果我绘制 S
我正在使用 this检测音高的算法 this音频文件。正如您所听到的,这是在吉他上弹奏的 E2 音符,背景中有一点噪音。 我使用 STFT 生成了这个频谱图: 我正在像这样使用上面链接的算法: y,
我正在尝试实现 FFT,我对代码等没问题,但事情的一般顺序让我感到困惑。 我认为这是正确的事情顺序吗? 输入 -> 重叠输入 -> 窗口化 -> FFT -> 相位计算/重叠补偿 -> 输出 我得到的
我通过相关了解了 DFT 的工作原理,并将其用作理解 FFT 结果的基础。如果我有一个以 44.1kHz 采样的离散信号,那么这意味着如果我要获取 1 秒的数据,我将有 44,100 个样本。为了对其
我想对我的数据执行短时傅里叶变换,并为每个段指定特定的样本长度。我想使用信号子模块中的 SciPy 函数 stft。但是,当我通过以下方式创建长度 10e5 的音频数组时: fs = 10e3 # S
我最近接手了一个项目,我需要对传入的麦克风数据执行实时滑动 FFT 分析。我选择执行此操作的环境是 OpenGL 和 Cinder,并使用 C++。 这是我第一次接触音频编程,我有点困惑。 这就是我试
使用时librosa.stft()要计算频谱图,如何取回相关的频率值?我对生成图像不感兴趣,如 librosa.display.specshow ,而是我想要掌握这些值。 y, sr = libros
这是我运行的一段代码: import tensorflow as tf sess = tf.InteractiveSession() filename = 'song.mp3' # 30 second
根据文档,有一个 scipy.signal.stft 但是当尝试访问该函数时,我从标题中收到错误。该函数记录在 here . 此外,scip.signal.istft 也不存在。有什么建议吗? 最佳答
所以,我想知道如何实现 STFT在 Julia 中,可能使用汉明窗。我在互联网上找不到任何东西。 最好的方法是什么?我宁愿不使用 Python 库,但如果可能的话,我宁愿使用纯原生的 Julia。也许
函数 spicy.signal.spectrogram:https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.spectr
我正在尝试从声音文件(.wav)中获取特征; 我尝试过 stft 来获取 2D 特征(x 是时间,y 是频率) 我尝试过 pywt,但得到的是一维数组。如果我输入一个 1D (1000,) wav 数
我正在将 Python 代码转换为 MATLAB。 Python 代码,使用以下命令: stft_ch = librosa.core.stft(audio_input[:, ch_cnt], n_ff
更新:我在 librosa 中重新实现了这个来进行比较,结果确实与 tensorflow 的结果有很大不同。 Librosa 给出了我期望的结果(但不是 tensorflow)。 我已将其发布为 is
我正在尝试在没有 gpu 的基于 arm 的设备上为 ASR 运行我的 PyTorch 模型。据我所知,arm 不支持 ATen 使用的 MKL。自然地,当我尝试进行推理时会收到以下错误: Runti
我是一名优秀的程序员,十分优秀!