0

我有将声音文件分解为 1 秒块的代码,计算块的 RMS,然后绘制所有块。在我对其进行编辑以使其一次读取文件夹而不是一个用户加载的文件之前,它工作正常。现在它打印 fs 的每个值(全部为 32k),这显然大大减慢了脚本的速度。这是新脚本:

DirIn = 'D:\Trial'
eval(['filelist=dir(''' DirIn '/*.wav'')']) 


for i = 1:length(filelist)
[y,fs] = audioread(strcat(DirIn,'/',filelist(i).name))
npts = length(y);
chunkDur = 1; % length of chunk to analyze in seconds

systemCal = 0; % this should be whatever dB corresponds to an amplitude of 1 in wav file


chunkPts = fs * chunkDur;
rms = [];

for i = 1:chunkPts:npts-chunkPts
    chunkRMS = 20 * log10(std(y(i: i + chunkPts))) + systemCal; % rms of chunk in dB
    rms = [rms; chunkRMS];
end

t = [0: length(rms) - 1] * chunkDur; % time scale
plot(t, rms)
xlabel('Time (s)');
ylabel('RMS dB');
end

作为参考,这是有效的原件:

npts = length(data);
chunkDur = 1; % length of chunk to analyze in seconds

systemCal = 0; % this should be whatever dB corresponds to an amplitude of 1 in wav file


chunkPts = fs * chunkDur;
rms = [];

for i = 1:chunkPts:npts-chunkPts
    chunkRMS = 20 * log10(std(data(i: i + chunkPts))) + systemCal; % rms of chunk in dB
    rms = [rms; chunkRMS];
end

t = [0: length(rms) - 1] * chunkDur; % time scale
plot(t, rms)
xlabel('Time (s)');
ylabel('RMS dB');
4

1 回答 1

1

;您错过了行尾的分号[y,fs] = audioread(strcat(DirIn,'/',filelist(i).name))。它表示一行的结束并抑制代码行的输出。这里有一个不错的博客条目

于 2020-11-14T09:06:07.297 回答