Package wiat :: Package TM :: Module Functions
[hide private]
[frames] | no frames]

Source Code for Module wiat.TM.Functions

 1  # Copyright 2008 Antoine Lefebvre 
 2  # 
 3  # This file is part of "The Wind Instrument Acoustic Toolkit". 
 4  # 
 5  # "The Wind Instrument Acoustic Toolkit" is free software: 
 6  # you can redistribute it and/or modify it under the terms of 
 7  # the GNU General Public License as published by the 
 8  # Free Software Foundation, either version 3 of the License, or 
 9  # (at your option) any later version. 
10  # 
11  # "The Wind Instrument Acoustic Toolkit" is distributed in the hope 
12  # that it will be useful, but WITHOUT ANY WARRANTY; without even 
13  # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
14  # See the GNU General Public License for more details. 
15  # 
16  # You should have received a copy of the GNU General Public License 
17  # along with "The Wind Instrument Acoustic Toolkit". 
18  # If not, see <http://www.gnu.org/licenses/>. 
19  # 
20  # All rights reserved. 
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   
32 -def CompareMaxima(ml1,ml2):
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
48 -def calculate_impulse_response(I,T,N,fs):
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