0

我想问一下如何通过我的手对声波中的每一帧进行自相关函数没有内置函数我做了一个代码我不知道它是对是错所以请帮助我也想得到音高周期

[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')
4

1 回答 1

0

基于这里的等式。自相关方程看起来不错。但我很困惑frames。您将其定义为二维矩阵,然后对其进行线性索引 ( frames(i))。

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

于 2012-04-10T14:01:05.383 回答