matlab中的自相关

时间:2012-04-10 13:55:49

标签: matlab

我想问一下如何对声波中的每一帧做自动相关功能我的手没有内置功能我做了一个代码,我不知道它是对还是错所以请帮忙 我也希望得到音高期

[sound,  Fs]= wavread('aa.wav');

subplot(5,1,1);plot (sound);title('The Orignal Wave')
frameSize= 10/10^3;
overlapSize= 5/10^3;

frameSize_samples = round(Fs*frameSize);
overlapSize_samples= round(overlapSize* Fs);

shift = frameSize_samples-overlapSize_samples;

nframes=ceil((length(sound)-frameSize_samples)/shift);

frames = zeros(nframes, frameSize_samples);
for i=1:nframes
      frames(i,:) = sound( ((i-1)*shift+ 1):((i-1)*shift+ frameSize_samples) )';
end

subplot(5,1,2);plot (frames(:));title(' Wave after framing')


w = rectwin(frameSize_samples)';

frames1 = zeros(nframes, frameSize_samples);

 for i=1:nframes
     frames1(i,:)=(frames(i,:).*w);
 end

 %/////////////////////////////////////////////////////////

 % calc energy
 numSamples = length(sound);
 energy = zeros(1,nframes);  
 for frame = 1:nframes   
     energy(frame) = sum(frames1(frame).^2);             %# Calculate frame energy
 end
 subplot(5,1,3);plot (energy(:));title(' Energy')


 % calc autocorrelation


 autocorrelation = zeros(1,nframes);
 for i=1:nframes
     for k = 0:frameSize_samples
         autocorrelation(i,:)= sum(frames(i)*frames(i+k));
     end
 end


 subplot(5,1,4);plot (autocorrelation(:));title(' autocorrelation')

1 个答案:

答案 0 :(得分:0)

基于等式here。自相关方程看起来很好。但我对frames感到困惑。您将其定义为二维矩阵,然后线性索引(frames(i))。

此外,for循环for k=0:frameSize_samples没有做任何事情;您在每次迭代中分配相同的变量autocorrelation(i, :),因此它将被覆盖。