PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pitchRefine.m 535B

3 years ago
1234567891011121314151617
  1. % Talkie library
  2. % Copyright 2011 Peter Knight
  3. % This code is released under GPLv2 license.
  4. %
  5. % Home in on best fit pitch
  6. function [pitch,score] = pitchRefine(w,pitchGuess,pitchRange,sampleRate)
  7. score = 0;
  8. phase = (1:length(w))*2*pi/sampleRate;
  9. for (newGuess = pitchGuess-pitchRange:pitchRange/10:pitchGuess+pitchRange)
  10. signal = exp(i*(newGuess*phase))';
  11. pitchScore = abs(mean(w .* signal));
  12. if (pitchScore > score)
  13. score = pitchScore;
  14. pitch = newGuess;
  15. end
  16. end