所以我只需要将adjusted_fft_frames = mag_frames * np.exp(1j * 2 * np.pi * pitch_freqs_smoothed[:, np.newaxis] * freqs[np.newaxis, :])这段代码替换成pitch_freqs_smoothed = pitch_freqs_smoothed[:, np.newaxis]pitch_freqs_smoothed = np.tile(pitch_freqs_smoothed, (1, mag_frames.shape[1]))adjusted_fft_frames = mag_frames * np.exp(1j * 2 * np.pi * pitch_freqs_smoothed * freqs[np.newaxis, :])就行了吗
时间: 2024-02-12 18:08:05 浏览: 119
是的,你可以将原来的代码替换为新的代码,但是需要注意一下 `freqs` 数组的长度是否正确,以确保可以正确进行广播操作。同时,也需要确保 `pitch_freqs_smoothed` 被正确地转换为 `(198, 882)` 的形状。
完整的代码修改如下:
```
freqs = np.fft.rfftfreq(n_fft, d=1.0/sr)
pitch_freqs_smoothed = pitch_freqs_smoothed[:, np.newaxis]
pitch_freqs_smoothed = np.tile(pitch_freqs_smoothed, (1, mag_frames.shape[1]))
adjusted_fft_frames = mag_frames * np.exp(1j * 2 * np.pi * pitch_freqs_smoothed * freqs[np.newaxis, :])
```
这个修改后的代码会将 `pitch_freqs_smoothed` 转换为一个形状为 `(198, 882)` 的数组,然后使用广播机制将其与 `freqs` 相乘,得到一个形状为 `(198, 882)` 的新的振幅谱矩阵 `adjusted_fft_frames`。
相关问题
结合之前几段代码,解释adjusted_fft_frames = mag_frames * np.exp(1j * 2 * np.pi * pitch_freqs_smoothed[:, np.newaxis]* freqs[np.newaxis, :])
在这段代码中,首先使用了之前处理得到的pitch_freqs_smoothed数组,这个数组包含了每一帧的基频对应的频率,然后使用了numpy的广播机制,将其转化为一个二维数组,其中每一行都是pitch_freqs_smoothed数组。另外,使用了freqs数组,这个数组包含了每一个FFT bin的分辨率,即每个bin对应的频率值,它是一个一维数组。
接下来,对于每一帧,在每个FFT bin的位置上,乘以一个复数值,这个复数值的实部是1,虚部是2π乘以相应的频率值,这个频率值是pitch_freqs_smoothed数组中对应帧的值。这个复数可以看作是一个旋转因子,它的幅度为1,相位随着频率的变化而变化,这个过程可以看作是在对FFT frame做频率变换。最后,将经过变换的FFT frame乘以mag_frames,这个mag_frames是之前计算得到的原始FFT frame的幅度信息,这样可以得到经过调整的FFT frame,其中包含了音高的信息。
RI = [***.***.***.***.***.***.***.**]; % 平均随机一致性指标RI
### 平均随机一致性指标RI的定义
平均随机一致性指标(RI),也称为Rand Index,在聚类分析中用于衡量两个数据集划分的一致性。该指数考虑了所有样本对,并计算这些样本对在同一簇内或不同簇中的匹配程度。具体来说,对于给定的数据集合 \( S \) 和两种不同的聚类结果 \( A \) 和 \( B \),RI通过下述公式来量化两者之间的相似度:
\[ RI = \frac{a + d}{\binom{n}{2}} \]
其中,
- \( a \) 表示在A和B中都处于同一簇内的对象对数量;
- \( d \) 是指那些既不在A也不在B同一个簇里的对象对数目;
- \( n \) 代表总的对象数。
为了调整偶然因素的影响,通常会引入Adjusted Rand Index(ARI)[^1],它修正了由于随机分配而导致的高分情况。
### 使用MATLAB实现RI计算
下面是一个简单的MATLAB函数用来计算两个标签向量间的RI值:
```matlab
function ri = rand_index(labels_true, labels_pred)
% 计算Rand Index
N = length(labels_true);
agree_same_cluster = sum(arrayfun(@(i,j)(labels_true(i)==labels_true(j))==(labels_pred(i)==labels_pred(j)), ...
repmat((1:N)',N,1),repmat(1:N,N,1)));
total_pairs = combnk(N,2); % 总共可能的对象对
ri = agree_same_cluster / total_pairs;
end
```
此代码片段接受真实的类别标签 `labels_true` 和预测得到的类别标签 `labels_pred`作为输入参数,并返回它们之间的一致性得分ri。注意这里使用了组合数(combnk)来表示总的成对比较次数。
阅读全文
相关推荐
















