Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'skip:[ 20': 0.03; 'elif': 0.04; '"""': 0.05; 'mrab': 0.05; 'that?': 0.05; 'data:': 0.07; 'f.close()': 0.07; "'w')": 0.09; '[1,': 0.09; 'filename)': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; 'value.': 0.15; "'.txt',": 0.16; "'\\\\'": 0.16; '2],': 0.16; '[2,': 0.16; 'dashes.': 0.16; 'decoding': 0.16; 'dots': 0.16; 'filename):': 0.16; 'numpy': 0.16; 'pylab': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'code.': 0.20; 'import': 0.21; 'cc:2**0': 0.23; 'monday,': 0.23; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'looks': 0.26; 'received:209.85.212': 0.28; 'array': 0.29; 'convert': 0.29; 'probably': 0.29; "i'm": 0.29; 'window': 0.30; 'code': 0.31; 'file': 0.32; 'anyone': 0.33; 'received:google.com': 0.34; 'data,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'should': 0.36; 'received:209': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'think': 0.40; 'maximum': 0.63; 'skip:n 10': 0.63; 'show': 0.63; 'here': 0.65; 'results': 0.65; 'sum': 0.66; 'skip:n 30': 0.69; 'wave': 0.71; 'average.': 0.84; 'stereo': 0.84; 'window,': 0.84; 'received:209.85.212.56': 0.91 Newsgroups: comp.lang.python Date: Mon, 10 Sep 2012 13:15:54 -0700 (PDT) In-Reply-To: <0d091492-39e0-42b3-a383-9853af33136f@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=65.205.52.2; posting-account=_dIAQQoAAAB7Yieol6fmkK_HviJUbJt3 References: <0d091492-39e0-42b3-a383-9853af33136f@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 65.205.52.2 MIME-Version: 1.0 Subject: Re: Numpy combine channels From: Wanderer To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 156 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347308157 news.xs4all.nl 6849 [2001:888:2000:d::a6]:40931 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28853 On Monday, September 10, 2012 4:14:18 PM UTC-4, Wanderer wrote: > On Monday, September 10, 2012 4:12:40 PM UTC-4, MRAB wrote: > > > On 10/09/2012 20:39, Wanderer wrote: > > > > > > > I have an array generated by audiolab of left and right stereo > > > > > > > channels. It looks like [[1,1],[1,2],[2,3]]. I would like to combine > > > > > > > the left and right channels to get an array [2,3,5]. Is there a numpy > > > > > > > command to do that? > > > > > > > > > > > > > >>> import numpy > > > > > > >>> numpy.array([[1,1],[1,2],[2,3]], dtype="i") > > > > > > array([[1, 1], > > > > > > [1, 2], > > > > > > [2, 3]]) > > > > > > >>> a[:, 0] > > > > > > array([1, 1, 2]) > > > > > > >>> a[:, 1] > > > > > > array([1, 2, 3]) > > > > > > >>> a[:, 0] + a[:, 1] > > > > > > array([2, 3, 5]) > > > > > > > > > > > > But should they be added together to make mono? > > > > > > > > > > > > Suppose, for example, that both channels have a maximum value. Their > > > > > > sum would be _twice_ the maximum. > > > > > > > > > > > > Therefore, I think that it should probably be the average. > > > > > > > > > > > > >>> (a[:, 0] + a[:, 1]) / 2 > > > > > > array([1, 1, 2]) > > > > I'm decoding morse code. So it's CV dots and dashes. In case anyone is interested, here is the full code. # morsecode.py import numpy as np from scikits.audiolab import wavread from scipy.signal import decimate from pylab import plot from pylab import show import os def movingaverage(interval, window_size): window = np.ones(int(window_size)) / float(window_size) return np.convolve(interval, window, 'same') def wav2morse(resultDir, filename): """ Convert a wave file to morse code resultDir: directory for wave file and results filename: wave file name """ data, _fs, _enc = wavread(resultDir + '\\' + filename) data = np.sum(data, axis=1) data = np.fabs(data) data = movingaverage(data, 100) data = decimate(data, 2) highcount = 0 lowcount = 0 fileBase, _fileExt = os.path.splitext(filename) f = open(resultDir + '\\' + fileBase + '.txt', 'w') for d in data: if d > 0.3: if lowcount > 3000: f.write(' ') lowcount = 0 highcount += 1 else: if highcount > 3000: f.write('-') elif highcount > 1000: f.write('.') highcount = 0 lowcount += 1 f.close()