Script to check zero crossings to check if microphones phases are aligned I have 'n' microphones placed in square fashion and I want to make sure that all the channels must be aligned in time exactly the same if the signal is equidistant from all the 'n' microphones i.e. in the center of the square.

I have written this script to do the difference in zero crossing timings for only two signals (.wav file) and if the difference is above some precision then print that and bail out.

from scipy.io import wavfile
import numpy as np
import argparse

parser = argparse.ArgumentParser(description='diff the zero crossing of two files')
parser.add_argument('-f1', '--file_name_1', help='provide first file name')
parser.add_argument('-f2', '--file_name_2', help='provide second file name')
parser.add_argument('-p', '--precision', help='precision to compare against', type=float, default=0.0001)

args = parser.parse_args()
print(args)
files = []
files.append(args.file_name_1)
files.append(args.file_name_2)

sampling_rates = []
signals = []
for file in files:
  fs, signal = wavfile.read(file)
  signal = signal / max(abs(signal))                        # scale signal
  sampling_rates.append(fs)
  signals.append(signal)
  assert min(signal) &gt;= -1 and max(signal) &lt;= 1
  print 'fs           ==&gt; ', fs, 'Hz'                       # sampling rate
  print 'len(signal)  ==&gt; ', len(signal), 'samples'

sampsPerMilli = 0
#files should have same sampling rates and length
prev_rate = sampling_rates[0]
for rate in sampling_rates[1:]:
  cur_rate =  rate
  sampsPerMilli = int(rate / 1000)
  if prev_rate != cur_rate:
    print("rates doesn't match %d %d"% (prev_rate, cur_rate))
    exit(0)
  cur_rate = rate

#signal length also should be same
prev_length = len(signals[0])
for signal in signals[1:]:
  cur_length = len(signal)
  if prev_length != cur_length:
    print("length of signals doesn't match for %d %d"% (prev_length, cur_length))
    exit(0)
  cur_length = prev_length

zccs = []
for signal in signals:
  zcc = []
  DC = np.mean(signal)
  newSignal = signal - DC
  for i in range(1, int(len(newSignal))):
    if((newSignal[i] * newSignal[i-1]) &lt; 0):
      #print("crossing at %f seconds"% ((i/sampsPerMilli) * 0.001))
      zcc.append((i/sampsPerMilli) * 0.001)
  zccs.append(zcc)

for a, b in zip(zccs, zccs[1:]):
  if len(a) != len(b):
    print("length doesn't match %d %d"% (len(a), len(b)))
    for c, d in zip(a, b):
      if c-d &gt; args.precision:
        print("precision %f c %f d %f exceeded"% (args.precision, c, d))
        exit(0)


Is there any better approach or can this script be improved?
This is more of a usability thing than a code thing, but I'd suggest making the non-optional arguments positional so the user doesn't need to type the flags out.
A simple way to put two items into a list is files = [file1, file2].
You can also build sampling_rates and signals via list comprehension.
Since you're explicitly only ever handling two files, building a loop to handle the second thru last files is unnecessary and confusing.
Don't assign a value to a variable if you're going to overwrite it with something else before using it -- again, it's just adding lines of code that do nothing but make it harder to read the script (and use up an infinitesimal amount of processing power).  Combined with (4) above, you have two loops that take seven lines of code to do what's really a single simple equality comparison.
The rest of the script (everything starting at zccs) is hard to understand, but I attempted to condense some of the more magical logic into a function and use list comprehension instead of long loops; better variable names and/or type declarations (normally I'd add those as part of code review suggestions, but I'm not familiar with any of these libraries) would help someone who's not familiar with this particular domain be able to read the script and figure out what it's doing.  Here's what I ended up with after making the above edits:


from scipy.io import wavfile
import numpy as np
from argparse import ArgumentParser

parser = ArgumentParser(description='diff the zero crossing of two files')
parser.add_argument('files', nargs=2, metavar='file', 
                    help='one of the files to diff')
parser.add_argument('-p', '--precision', type=float, default=0.0001, 
                    help='precision to compare against')

args = parser.parse_args()

# Read data from wav files, scale signals by the max in each file.
sampling_rates, data = zip(*[wavfile.read(file) for file in args.files])
signals = [signal / max(abs(signal)) for signal in data]

# check we didn't somehow bungle the signal normalization math
assert all([min(signal) &gt;= -1 and max(signal) &lt;= 1 for signal in signals])

# files should have same sampling rates and signal length
assert sampling_rates[0] == sampling_rates[1], "rates don't match"
assert len(signals[0]) == len(signals[1]), "signal lengths don't match"

samples_per_ms = int(sampling_rates[1] / 1000)

def zcc(signal):
    """magic!!! (todo: write better docstring)"""
    norm_signal = signal - np.mean(signal)
    return [
      i * 0.001 / samples_per_ms  # is this right?  i is the index!
      if norm_signal[i] * norm_signal[i-1] &lt; 0 
      for i in range(1, len(norm_signal))
    ]

for a, b in zip(*[zcc(signal) for signal in signals]):
  if len(a) != len(b):
    print("length doesn't match %d %d"% (len(a), len(b)))
    for c, d in zip(a, b):
      if c - d &gt; args.precision:
        print("precision %f c %f d %f exceeded"% (args.precision, c, d))
        exit(0)