Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. clear all
  2. %step 1: pitch of human is located between 50 Hz and 500 hz so filter all frequencies below 50 hz and above 600 hz
  3. %step 2: Find a vowel in the sentence because only vowel will contain the pitch
  4. %step 3: Vowel can be determined by its high energy
  5. %step 4: divide the sentence to segments of size 50 msec
  6. %step 5: calculate the energy for each segment from its spectral components
  7. %step 6: choose the segment with the highest energy
  8. %step 7: Find the FFT and count cepstrum of the vowel segment
  9. %step 8:
  10. [sigOrg, fs] = wavread('Aaron1.wav');
  11. [bl,al]=butter(4,[50 500]/(fs/2)); %creating the coefficients for a bandpass filter with low freq=50 and high freq = 600 Hz
  12. sig=filter(bl,al,sigOrg); %filtering out frequencies below 50 and above 600 Hz from the signal
  13. sigLngth= length(sig);
  14. WindSize = round((20/1000)*fs); %size of the window is 50 msec to look for the vowel
  15. NumSegm = floor(sigLngth/WindSize); %Number of segments in the entire sentence
  16. for i=1:NumSegm %This FOR loop will calculate the energy in every segment
  17. windStrt = (i-1)*WindSize+1;
  18. windEnd = windStrt+WindSize;
  19. EnrgySegm(i)=sum(abs(sig(windStrt:windEnd)));
  20. end
  21. [maxSpec, indx]=max(EnrgySegm); %segment with highest energy represent a vowel
  22. % WindSize=WindSize*3;
  23.  
  24. x = sig((indx-1)*WindSize:(indx+1)*WindSize);
  25. N = length(x);
  26. Frs = fs/N;
  27. x = x(:); % assure column vector
  28. plot(x);
  29. figure
  30. %To find the pitch in
  31. %the time domain you need to find the period T between
  32. %two consecutive peaks in the autocorrelation of the vowel segment and the pitch will be 1/T
  33. sigCorr = xcorr(x);
  34. plot(sigCorr)
  35.  
  36. %To find the pitch in the frequency domain you need to find the frequency F0 between
  37. %two consecutive peaks in the FFT of the vowel segment and the pitch will
  38. %be F0=(number of samples between consecutive peaks)*Frs
  39.  
  40.  
  41. window = hamming(N);
  42. % Find the fourier transform of a the vowel segment
  43. x = x(:).* window(:);
  44. y = fft(x, N);
  45. yabs = abs(y);
  46. L = length(yabs);
  47. ypos = yabs(1:round(500/Frs));
  48. figure
  49. plot(ypos)
  50.  
  51. % [A,K] = findpeaks(x);
  52. [A,K] = findpeaks(ypos);
  53. Umax = max(K);
  54. Umin = min(K);
  55. Sd = Umax - Umin;
  56. Fo = Frs*Sd/(length(K)-1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement