#
# Depends on python-scipy and python-matplotlib
#
+# This test analyzes the .wav file and uses FFT (Fast Fourier Transform)
+# to analyze the frequency range. Only left channel is analyzed. Samples
+# are normalized before FFT. Frequencies bellow 200Hz and above 6000Hz
+# are ommited. The utility compares the frequencies using 200Hz steps
+# with given or predefined FFT samples and the diff to the most-close FFT
+# sample is printed.
+#
import sys
import scipy
from scipy.fftpack import fft, fftfreq
from scipy.io import wavfile
-SAMPLES = {
+FFT_SAMPLES = {
'zero': (
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
return samplerate, data
def fft_test(args):
- global SAMPLES
+ global FFT_SAMPLES
graph = False
values = False
while 1:
continue
if args[0] == '-clean':
del args[0]
- a = SAMPLES['zero']
- SAMPLES = {}
- SAMPLES['zero'] = a
+ a = FFT_SAMPLES['zero']
+ FFT_SAMPLES = {}
+ FFT_SAMPLES['zero'] = a
continue
if args[0].startswith('-avg='):
avg = eval(args[0][5:])
if args[0].startswith('-name='):
name = args[0][6:]
del args[0]
- SAMPLES[name] = (avg, mex)
- print repr(SAMPLES[name])
+ FFT_SAMPLES[name] = (avg, mex)
+ print repr(FFT_SAMPLES[name])
break
filename = args[0]
else:
m = map(lambda x: 0, l)
check = {}
- for s in SAMPLES:
- x, y = SAMPLES[s]
+ for s in FFT_SAMPLES:
+ x, y = FFT_SAMPLES[s]
diffa = diffm = idx = 0
for idx in range(len(r)):
diffa += abs(r[idx] - x[idx])