Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45572
| From | Terry Jan Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Harmonic distortion of a input signal |
| Date | 2013-05-19 19:19 -0400 |
| References | <eb271b5d-ee83-4f0e-b8ea-5b129c7cb771@googlegroups.com> <mailman.1846.1368977695.3114.python-list@python.org> <c841061c-2bae-4e41-bac2-f9cd9606c783@googlegroups.com> <CAHVvXxQURRKyxAV12YeqmpkkWj7sPC1Eczma6SJidLSjU6w-=g@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1851.1369005609.3114.python-list@python.org> (permalink) |
On 5/19/2013 6:49 PM, Oscar Benjamin wrote: >>>> import numpy as np > > Create a square wave signal: > >>>> x = np.zeros(50) >>>> x[:25] = -1 >>>> x[25:] = +1 >>>> x > array([-1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., > -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., 1., > 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., > 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]) > > Compute the magnitude spectrum: > >>>> spect = abs(np.fft.fft(x)[:25]) >>>> spect > array([ 0. , 31.85194222, 0. , 10.67342282, > 0. , 6.47213595, 0. , 4.69726931, > 0. , 3.73254943, 0. , 3.13762901, > 0. , 2.7436023 , 0. , 2.47213595, > 0. , 2.28230601, 0. , 2.15105461, > 0. , 2.06487174, 0. , 2.01589594, 0. ]) > > Find the index of the maximum element: > >>>> np.argmax(spect) > 1 > > So the peak is the lowest non-zero frequency component of the DFT. In > Hz this corresponds to a frequency of 1/T where T is the duration of > the signal. While you were answering a specific question, I think the above is a nice tutorial example, because it is more meaningful than arbitrary operations applied to random data.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Harmonic distortion of a input signal Anti Log <antilogeffects@gmail.com> - 2013-05-19 03:52 -0700
Re: Harmonic distortion of a input signal Chris Angelico <rosuav@gmail.com> - 2013-05-20 01:34 +1000
Re: Harmonic distortion of a input signal killybeard91@gmail.com - 2013-05-19 15:25 -0700
Re: Harmonic distortion of a input signal Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-05-19 23:49 +0100
Re: Harmonic distortion of a input signal Terry Jan Reedy <tjreedy@udel.edu> - 2013-05-19 19:19 -0400
Re: Harmonic distortion of a input signal killybeard91@gmail.com - 2013-05-19 15:59 -0700
Re: Harmonic distortion of a input signal killybeard91@gmail.com - 2013-05-19 16:03 -0700
Re: Harmonic distortion of a input signal killybeard91@gmail.com - 2013-05-19 16:36 -0700
Re: Harmonic distortion of a input signal Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-05-20 13:09 +1200
Re: Harmonic distortion of a input signal Dave Angel <davea@davea.name> - 2013-05-19 21:11 -0400
Re: Harmonic distortion of a input signal jmfauth <wxjmfauth@gmail.com> - 2013-05-20 10:23 -0700
Re: Harmonic distortion of a input signal Christian Gollwitzer <auriocus@gmx.de> - 2013-05-20 19:50 +0200
Re: Harmonic distortion of a input signal Christian Gollwitzer <auriocus@gmx.de> - 2013-05-20 19:56 +0200
Re: Harmonic distortion of a input signal jmfauth <wxjmfauth@gmail.com> - 2013-05-23 04:44 -0700
Re: Harmonic distortion of a input signal Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-05-21 15:58 +0100
csiph-web