title: Find Pitch in speech frame
body: <p>I have a speech frame. when I compute the LP residual, I could not estimate the pitch truly.
  I need to find pitch period for each frame. However, When I use frequency domain and time domain, none of them work well. Could anyone help me? 
  I need it for <a href="https://stackoverflow.com/questions/21952495/find-pitch-synchronous-windowing-based-on-pitch-tracking">find Pitch-synchronous windowing based on pitch tracking</a></p>
  
  <p>The result for my code is like <img src="https://i.stack.imgur.com/mBIrc.jpg" alt="enter image description here">
  Thanks </p>
  
  <p>The MATLAB code are as following:</p>
  
  <pre><code>    frame_length=0.03*fs;
   frame=wave1((i-1)*frame_length+1:i*frame_length);   
  N=256;
  Y1 = fft(frame,N);
  f = 0 : fs / N : fs - 1 / N;
  N1 = length(Y1); 
  %Y1(1) = []; 
  power1 = abs(Y1(1:floor(N1))).^2;
  nyquist = 1/2;
  freq1 = (1:floor(N1/2))/floor(N1/2)*nyquist;
  [val loc]=max(power1);
  pitch_priod = round(fs*(1./f(loc)));
  </code></pre>
  
  <p>or</p>
  
  <pre><code>frame=wave1((i-1)*frame_length+1:i*frame_length);   
  min_pitch=floor(fs/600); % Pitch for men 50 to 300 Hz and for women 100 till 600 Hz
  max_pitch=floor(fs/50);
  y1=xcorr(frame);
  y1=y1./(abs(max(y1)));
  y2=y1(min_pitch:max_pitch);
  [val loc]=max(y2);
  pitch_priod=loc+min_pitch;
  </code></pre>