1

Just the second day met with Python and with troubles...
I've got a lot of CD-standard (16 bit, 44100 Hz) stereo wave files and need to find their average (arithmetic mean) FIR. The algorithm is easy to say... - the sum of amplitudes for each freq. divides on the amount of files. Then the achieved FIR is being plotted and written down to the text file as the table.
I rolled over some similar posts like this exciting Python Scipy FFT wav files but there are still too many things, even alphabet, I lose touch in and compiler mistkes follow every time I try to repeat the examples.
I would appreciate any help that can move mу from the dead-end. So, these are my shy paces...

As the number of files may vary it is probably useful to have a list of files at the elbow:

    import os
    a = os.path.expanduser(u"~")  # absolute user path var.
    b = "integrator\\files"       # base folder to use with files in it
    c = os.path.join(a, b)
    flist = os.listdir(c)
    images = filter(lambda x: x.endswith('.wav'), flist)  # filter non-wavs
    for i in range(len(flist)):
        print(flist[i])
    print()

And it works fine for me! But I still cannot catch how to organize the multiple files reading, and calculating their mean FIR massive As I keeked I need something like "global package":

    import glob
    import mainfile
    files = glob.glob('./*.wav')
    for ele in files:
    f(ele)
    quit()

Wherу the mainfile.py looks somethng like that:

    import matplotlib.pyplot as plt
    from scipy.io import wavfile # get the api
    from scipy.fftpack import fft
    from pylab import *
    def f(filename):
    fs, data = wavfile.read(filename)  # load the data
    a = data.T[0]                      # this is a two channel soundtrack, I get the first track
    b=[(ele/2**16.)*2-1 for ele in a]  # this is 16-bit track, now normalized on [-1,1)
    c = fft(b)                         # create a list of complex number
    d = len(c)/2                       # you only need half of the fft list

And here I just don;t know what should I better do with 'd's - summing in cycle or... Then this code example operated just 1 channel for plotting - I need the output FIR as seqence of pairs for each channel. Yet still it's not clear how to tweak FFT window to Hanning with at least 65536 FFT-size (oh yes, I know thу)calculations are slow as hell).

In the end we can plot and save the graph:

     plt.plot(abs(c[:(d-1)]),'r')
     savefig(filename+'.png',bbox_inches='tight')  

... and somehow write average FIR to the txt table file

I'd be happy enough if this script worked as the console application (though at first I dreamt of kinda minimalistic GUI with ability choose any folder containing files with certian overview button and with progress bar to make sure that app is still breathing... though hard covering ten or twenty five wavs with FFT slow "scythe".

Got C:\Anaconda2 (with numpy, scipy and matplotlib properly installed) on Windows 7 x86 PC

Thank you in advance! With regards, Me.

Community
  • 1
  • 1
Noilladar
  • 11
  • 3

0 Answers0