前几天群里有人提出一个问题:MATLAB里,同样频率的信号写入/读取,为什么频率感觉不同?
测试code:
fs = 2000; f0 = 20; t = 0:1/fs:1; subplot 211 signal = sin(2*pi*t*f0); plot(t,signal);hold on; wavwrite(signal,fs,‘test.wav‘); data = wavread(‘test.wav‘); plot(t,data,‘r--‘); subplot 212 signal = 3*sin(2*pi*t*f0); plot(t,signal);hold on; wavwrite(signal,fs,‘test.wav‘); data = wavread(‘test.wav‘); plot(t,data,‘r--‘);
结果:
幅度放大之后,信号失真,也难怪频率听起来不同了。看一看wavwrite特性:
为了让信号不失真,可以采取两个办法:1)信号归一化;2)利用NBITs=32设置:
修改:
wavwrite(signal,fs,32,‘test.wav‘);
时间: 2024-10-13 11:08:06