1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """ Functions.py - Definition of various useful functions
23
24 """
25
26 import numpy
27 from wiat.util import calculate_interval_in_cents, calculate_ratio_in_db
28 from wiat.TM import CalculateImpedance
29
30 __all__ = ['CompareMaxima','calculate_impulse_response']
31
33 " Compare two list of maxima data. "
34 l1 = len(ml1)
35 l2 = len(ml2)
36 comp = []
37 for i in range(min([l1,l2])):
38 (f1,A1) = ml1[i]
39 (f2,A2) = ml2[i]
40 if i == 0:
41 fund1 = f1
42 fund2 = f2
43 cents = calculate_interval_in_cents(f1,f2)
44 dB = calculate_ratio_in_db(A1,A2)
45 comp.append((f1, f2, cents, A1, A2, dB, f1/fund1, f2/fund2))
46 return comp
47
49 """ Calculate the impulse response of an instrument from its impedance.
50
51 I: Instrument instance
52 T: temperature
53 N: size of the fft
54 fs: sampling frequency
55 """
56 f = numpy.abs(numpy.fft.fftfreq(N)[1:N/2+1])*fs
57 Z = CalculateImpedance(I,f,T)
58 H = numpy.concatenate(([numpy.complex(0.)], Z, numpy.conj((Z[0:-1]))))
59 h = numpy.real(numpy.fft.ifft(H))
60 return h
61