我实现了一个读取 wav 文件并对其进行分析的 matlab 代码。wav文件的大小约为(3-4 G)。当我运行该文件时,出现以下错误:
"Out of memory. Type HELP MEMORY for your options"
我试图增加虚拟内存,但没有奏效。以下是我正在使用的代码:
event=0;
[x, fs] = wavread('C:\946707752529.wav');
Ts=1/fs;% sampling period
N = length(x);% N is the number of samples
slength = N*Ts;%slength is the length of the sound file in seconds
% Reading the first 180 seconds and find the energy, then set a threshold value
calibration_samples = 180 * fs;
[x2, Fs] = wavread('C:\946707752529.wav', calibration_samples);
Tss=1/Fs;
[b,a]=butter(5,[200 800]/(Fs/2));
y2=filter(b,a,x2);
%This loop is to find the average energy of the samples for the first 180 seconds
startSample=1;
endSample=Fs;
energy=0;
for i=1:180
energy=energy+sum(y2(startSample:endSample).^2)*Tss;
startSample=endSample+1;
endSample=endSample+Fs;
end
mean_energy=energy/180;
Reference_Energy=mean_energy;% this is a reference energy level
Threshold=0.65*Reference_Energy;
% Now filtering the whole recorded file to be between [200-800] Hz
[b,a]=butter(5,[200 800]/(fs/2));
y=filter(b,a,x);
N = length(y);
N=N/fs; % how many iteration we need
startSample=1;
endSample=fs;
energy=0;
j=1;
while( j<=N)
counter=0;
energy=sum(y(startSample:endSample).^2)*Ts;
if (energy<=Threshold)
counter=counter+1;
for k=1:9
startSample=endSample+1;
endSample=endSample+fs;
energy=sum(y(startSample:endSample).^2)*Ts;
if (energy<=Threshold)
counter=counter+1;
else
break;
end %end inner if
end % end inner for
end % end outer IF
if(counter>=10)
event=event+1;
end
if(counter>0)
j=j+counter;
else
j=j+1;
end
startSample=endSample+1;
endSample=endSample+fs;
end % end outer For
系统:Windows 7 64 位
内存:8 GB
Matlab:2013