0
我想問一下如何在聲波中的每一幀做自動相關函數,我的手並沒有內置函數,我做了一個代碼,我不知道它是對還是錯請幫助 也是我想要得到的基音週期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')
我明白什麼是自相關函數,但我不能真的在matlab上做所有我想要的每一行都有自相關矩陣表示一幀的自相關乘以幀的自相關所以我認爲矩陣將是自相關=零(nframes,frameSize_samples); – marmar 2012-04-10 14:23:43