【问题标题】:auto-correlation in matlabmatlab中的自相关
【发布时间】:2012-04-10 13:55:48
【问题描述】:

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

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

【问题讨论】:

    标签: matlab


    【解决方案1】:

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

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

    【讨论】:

    • 我了解自相关函数的作用,但我不能在 matlab 上真正做到所有我想要的自相关矩阵每行代表一帧的自相关将帧乘以其移位版本乘以帧的长度,所以我认为矩阵将是自相关 = zeros(nframes, frameSize_samples);
    猜你喜欢
    • 2018-12-25
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    相关资源
    最近更新 更多