1

wav ファイルを読み取り、それを分析する matlab コードを実装しました。wavファイルのサイズは(3~4G)程度です。ファイルを実行すると、次のエラーが表示されます。

"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 ビット
RAM: 8 GB
Matlab: 2013

4

2 に答える 2

2

wavread は、実際には wave ファイルのすべてのデータをシステム メモリに格納していると思います。さらに、追加情報を追加する場合があります。

この関数を 2 回呼び出して、結果を異なる行列に格納しているようです。ファイルが 3 ~ 4G であるため、少なくとも 6 ~ 8G のメモリが必要です。ただし、OS、Matlab、およびおそらく他のプログラムもメモリを必要とするため、このメモリ不足エラーが発生します。

解決策の 1 つは、WAV ファイルを複数のファイルに分割して、別々に読み取ることです。もう 1 つの解決策は、wavread を 1 回だけ呼び出し、ロードされたデータを必要な場所で使用することですが、そのために新しいメモリを再割り当てすることはありません。

于 2013-02-22T10:33:44.793 に答える
1

あなたのコードから判断すると、これはうまくいくかもしれません:

  • ファイルを読み込んだ後、最初の 180 秒を除くすべてを削除します
  • しきい値を決定する
  • 最初のデータを除くすべてのメモリをクリアする
  • データの一部を分析して結果を保存する
  • 次のデータ以外のすべてのメモリを消去します...

これは、アルゴリズムが正しく効率的であることを前提としています。

また、アルゴリズムに問題がある場合もあります。これを検出するには、コードを実行し、dbstop if errorエラーが発生したときにすべての変数のサイズを確認してください。次に、それらのいずれかが大きすぎるかどうかを確認してください。間違いを見つけた可能性があります。

于 2013-02-22T10:39:57.670 に答える