Created
April 7, 2017 02:54
-
-
Save avegancafe/c69dd74dbe0f6fe0a296fa8b54463946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/python2 | |
| # Name: Kyle Holzinger | |
| import readWave as rd | |
| from math import atan, floor | |
| from matplotlib import pyplot as plt | |
| def pitch(name, start): | |
| # Skips first 2 seconds of file | |
| indata, params = rd.readwav(name) | |
| time = 0.05 | |
| len_indata = len(indata) | |
| samples = int(time * params[2]) | |
| W = 2205 | |
| difference = [] | |
| S = 88200 + start | |
| indata = indata[S:] | |
| # Difference function | |
| for lag in xrange(0,samples): | |
| total = 0 | |
| for i in xrange(1, W): | |
| total += (indata[i] - indata[i+lag]) ** 2 | |
| difference.append(total) | |
| dtp = [1] | |
| for lag in range(1, samples): | |
| denom = float(sum([difference[j] for j in xrange(1, lag+1)])) / lag | |
| dtp.append(difference[lag]/denom) | |
| dtp = [-el for el in dtp] | |
| # Valley Picking Algorithm | |
| for i in range(1,len(dtp)-1): | |
| if dtp[i] < dtp[i-1] and dtp[i] < dtp[i+1]: | |
| first_min = dtp.index(dtp[i]) | |
| # print("First min at: %d"%first_min) | |
| break | |
| for i in range(first_min, len(dtp)-1): | |
| if dtp[i] > dtp[i-1] and dtp[i] > dtp[i+1]: | |
| max_x = dtp.index(dtp[i]) + 0.0 | |
| # print("First max at: %d"%max_x) | |
| break | |
| return 1/(max_x / params[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment