From: <jd...@us...> - 2007-12-08 16:35:27
|
Revision: 4675 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4675&view=rev Author: jdh2358 Date: 2007-12-08 08:35:17 -0800 (Sat, 08 Dec 2007) Log Message: ----------- added filter examples Modified Paths: -------------- trunk/py4science/examples/butter_filter.py Added Paths: ----------- trunk/py4science/examples/skel/butter_filter_skel.py Modified: trunk/py4science/examples/butter_filter.py =================================================================== --- trunk/py4science/examples/butter_filter.py 2007-12-08 16:23:40 UTC (rev 4674) +++ trunk/py4science/examples/butter_filter.py 2007-12-08 16:35:17 UTC (rev 4675) @@ -9,26 +9,38 @@ # sine corrupted wih gaussian white noise sn = s + 0.1*n.random.randn(len(s)) # noisy sine -# the nyquist frequency 1/(2dt) +# the nyquist frequency 1/(2dt) is the maximum frequency in a sampled +# signal Nyq = 0.5/dt +#the corner frequency represents a boundary in the system response at +#which energy entering the system begins to be attenuate, and the stop +#frequency is the frequency at which the signal is (practically) +#completely attenuated cornerfreq = 2. # the corner frequency stopfreq = 5. # the stop frequency -# the corner and stop freqs as fractions of the nyquist +# the scipy.signal routines accept corner an stop frequencies as a +# *fraction* of the nyquist ws = cornerfreq/Nyq wp = stopfreq/Nyq -# the order and butterworth natural frequency for use with butter +# call scipy.buttord to compute the order and natural frequency of the +# butterorth filter. See the help for signal.buttord. You will pass +# in ws and wp, as well as the attenuation in the pass and stop bands N, wn = signal.buttord(wp, ws, 3, 16) -# return the butterworth filter coeffs for the given order and frequency +# scipy.butter will take the output from buttord and return the +# lfilter coeefs for that filter b, a = signal.butter(N, wn) -# filter the data +# Now lfilter will filter the noisy sine with the filter parameters +# from butter sf = signal.lfilter(b, a, sn) +# plot the original, noisy and filtered sine, all on the same axes in +# pylab, and make a legend fig = figure() ax = fig.add_subplot(111) ax.plot(t, s, label='original signal') Added: trunk/py4science/examples/skel/butter_filter_skel.py =================================================================== --- trunk/py4science/examples/skel/butter_filter_skel.py (rev 0) +++ trunk/py4science/examples/skel/butter_filter_skel.py 2007-12-08 16:35:17 UTC (rev 4675) @@ -0,0 +1,46 @@ +import numpy as n +import scipy.signal as signal +from pylab import figure, show + +XXX = 0. # just so he XXX blanks will not crash +dt = 0.01 +t = n.arange(0, 2, dt) +s = XXX # a 1 Hz sine wave over t + +# sine corrupted wih gaussian white noise the sine wave s corrupted +# with gaussian white noise with sigma=0.1. See numpy.random.randn + +sn = XXX +# the nyquist frequency 1/(2dt) is the maximum frequency in a sampled +# signal +Nyq = XXX + +#the corner frequency represents a boundary in the system response at +#which energy entering the system begins to be attenuate, and the stop +#frequency is the frequency at which the signal is (practically) +#completely attenuated +cornerfreq = 2. # the corner frequency +stopfreq = 5. # the stop frequency + +# the scipy.signal routines accept corner an stop frequencies as a +# *fraction* of the nyquist +ws = XXX +wp = XXX + + +# call scipy.buttord to compute the order and natural frequency of the +# butterorth filter. See the help for signal.buttord. You will pass +# in ws and wp, as well as the attenuation in the pass and stop bands +N, wn = XXX, XXX # the output of signal.buttord + +# scipy.butter will take the output from buttord and return the +# lfilter coeefs for that filter. See help signal.butter +b, a = XXX, XXX # the output of signal.butter + +# Now lfilter will filter the noisy sine with the filter parameters +# from butter. See help signal.lfilter +sf = XXX # the filtered signal returned from lfi,ter + +# plot the original, noisy and filtered sine, all on the same axes in +# pylab, and make a legend +XXX This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |