MATLAB - 混合不同采样频率的 wav 文件
基本上我有一个学校项目,我必须从给定的波形文件创建一个新的波形文件。这个新波必须在 Matlab 中创建,唯一的区别是正弦波将与给定的 wav 文件混合(不是连接到末尾......)。正弦波为500hz。
到目前为止,我的代码是:
clear;
filename = 'C:\Documents and Settings\cmh0007\My Documents\rofl.wav';
[y, Fs, nbits, readinfo] = wavread(filename);
duration = numel(y) / Fs;
sinefs = 0:0.002:duration;
sinwave = 0.5*sin(2*pi*sinefs);
disp(size(y));
disp(size(sinwave));
newsignal = y + sinwave;
subplot(2,2,1), plot(y), title('Entire waveform');
subplot(2,2,3), plot(sinwave), title('sine waveform');
subplot(2,2,2), plot(newsignal), title('added waveform');
但是,此代码无法创建 newsignal 变量。问题在于,由于两个波之间的采样率不同,两个矩阵的大小不同。
大小调用的输出如下:
797696 2
1 18089
由于这些文件的大小相差约 44 倍,我想我可以简单地对给定波形文件的每个样本使用 44 次正弦波中的相同样本。然而,因为差异不完全是 44,所以我不知道这是否是一个选项。
有人对如何混合这两个文件有什么建议吗?
Basically I have a school project where I must create a new wave file from a given wave file. This new wave must be created in Matlab and the only difference is that a sine wave is to be mixed with the given wav file (not concatenated onto the end..). The sine wave is to be of 500hz.
My code so far is:
clear;
filename = 'C:\Documents and Settings\cmh0007\My Documents\rofl.wav';
[y, Fs, nbits, readinfo] = wavread(filename);
duration = numel(y) / Fs;
sinefs = 0:0.002:duration;
sinwave = 0.5*sin(2*pi*sinefs);
disp(size(y));
disp(size(sinwave));
newsignal = y + sinwave;
subplot(2,2,1), plot(y), title('Entire waveform');
subplot(2,2,3), plot(sinwave), title('sine waveform');
subplot(2,2,2), plot(newsignal), title('added waveform');
however, this code fails on creating the newsignal variable. The issue is that the two matrices are of different sizes due to the sampling rates differing between the two waves.
The output of the size calls are as follows:
797696 2
1 18089
Seeing as these files differ in sizes by a factor of ~44 I figured I could simply use the same sample from the sin wave 44 times over for each sample of the given wave file. However, because the difference is not exactly 44 I don't know if this is even an option.
Does anyone have any suggestions on how to go about mixing these two files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 0.002 更改为 1/Fs。这样你就会有相同的采样率。您还应该为 y 仅选择一个立体声通道并进行适当的转置。
您还可以考虑将名称 sinefs 更改为 sinet 或其他名称,因为它代表时间参数而不是采样频率。
Try changing 0.002 to 1/Fs. That way you'll have the same sampling rate. You should also choose only one of the stereo channels for y and do an appropriate transpose.
You might also consider changing the name sinefs to sinet or something as it represents the time parameter and not the sampling frequency.