我想问如何通过我的手对声波中的每一帧做自相关函数,而不是内置函数,我做了一个代码,我不知道它是对还是错,所以请帮助我也想得到音高周期
[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')发布于 2012-04-10 22:01:05
基于方程here。自相关方程看起来很好。但是我被frames搞糊涂了。您将其定义为2-D矩阵,然后对其进行线性索引(frames(i))。
此外,for循环for k=0:frameSize_samples没有做任何事情;您在每次迭代中都分配了相同的变量autocorrelation(i, :),因此它将被覆盖。
https://stackoverflow.com/questions/10090184
复制相似问题