title: auto-correlation in matlab
body: <p>i want to ask about how to do auto-correlation function to every frame in  a sound wave by my hand not built in function i do a code and i don't know if it right or wrong so please help
  also i want to get the pitch period </p>
  
  <pre><code>[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')
  </code></pre>