@@ -47,7 +47,7 @@ def upsample(s, factor):
4747
4848 s = util .colmat (s )
4949
50- sup = s .repeat (factor ).reshape ((- 1 , s .shape [1 ]), order = 'F' )
50+ sup = s .repeat (factor ).reshape ((- 1 , s .shape [1 ]), order = "F" )
5151
5252 if flattenOut :
5353 sup = sup .ravel ()
@@ -65,7 +65,7 @@ def decimate(s, factor, lowpassFrac=0.625, **kwargs):
6565
6666 return downsample (sFiltered , factor )
6767
68- def interpolate (s , factor , order = 8 , filtType = ' lanczos' ):
68+ def interpolate (s , factor , order = 8 , filtType = " lanczos" ):
6969 """Interpolate (upsample) a discrete signal by a given factor using a
7070 Finite Impulse Response (FIR) filter.
7171
@@ -107,8 +107,8 @@ def interpolate(s, factor, order=8, filtType='lanczos'):
107107 New observations (length 4*2=8): |**|**|**|**
108108 """
109109 if order % 2 != 0 :
110- raise RuntimeError (' Invalid order: ' + str (order ) +
111- ' Must be an even integer.' )
110+ raise RuntimeError (" Invalid order: " + str (order ) +
111+ " Must be an even integer." )
112112
113113 # ensure we have a numpy array
114114 s = np .asarray (s )
@@ -136,19 +136,19 @@ def interpolate(s, factor, order=8, filtType='lanczos'):
136136 taps = np .linspace (- radius , radius , newOrder + 1 ).astype (s .dtype , copy = False )
137137
138138 # generate FIR filter
139- if filtType == ' lanczos' :
139+ if filtType == " lanczos" :
140140 impulseResponse = np .sinc (taps ) * windows .lanczos (newOrder + 1 ).astype (s .dtype , copy = False )
141- elif filtType == ' sinc-blackman' :
141+ elif filtType == " sinc-blackman" :
142142 impulseResponse = np .sinc (taps ) * windows .blackman (newOrder + 1 ).astype (s .dtype , copy = False )
143143 else :
144- raise RuntimeError (' Invalid filtType: ' + str (filtType ))
144+ raise RuntimeError (" Invalid filtType: " + str (filtType ))
145145
146146 # convolve with FIR filter to smooth across zero padding
147147 # NOTE: there is potential for performance improvement here since
148148 # zeros could be excluded from the computation XXX - idfah
149149 # spsig.fftconvolve might also be faster for long signals XXX - idfah
150150 return np .apply_along_axis (lambda v :
151- np .convolve (v , impulseResponse , mode = ' same' ),
151+ np .convolve (v , impulseResponse , mode = " same" ),
152152 axis = 0 , arr = sl )
153153
154154def resample (s , factorDown , factorUp = 1 , interpKwargs = None , ** decimKwargs ):
@@ -207,11 +207,11 @@ def demoInterpolate():
207207 sLanczos8 = interpolate (s , factor , order = 8 )
208208 sLanczos16 = interpolate (s , factor , order = 16 )
209209
210- plt .plot (t , s , marker = 'o' , color = ' lightgrey' , linewidth = 3 , label = ' Original' )
211- plt .plot (tInterp , sLanczos4 , color = ' blue' , label = ' Lanczos4' )
212- plt .plot (tInterp , sLanczos8 , color = ' red' , label = ' Lanczos8' )
213- plt .plot (tInterp , sLanczos16 , color = ' green' , label = ' Lanczos16' )
214- plt .title (' Interpolation of a Random Walk' )
210+ plt .plot (t , s , marker = "o" , color = " lightgrey" , linewidth = 3 , label = " Original" )
211+ plt .plot (tInterp , sLanczos4 , color = " blue" , label = " Lanczos4" )
212+ plt .plot (tInterp , sLanczos8 , color = " red" , label = " Lanczos8" )
213+ plt .plot (tInterp , sLanczos16 , color = " green" , label = " Lanczos16" )
214+ plt .title (" Interpolation of a Random Walk" )
215215 plt .legend ()
216216 plt .tight_layout ()
217217
@@ -229,69 +229,69 @@ def demoResample():
229229 fig = plt .figure ()
230230
231231 ##axChirp = fig.add_subplot(4, 1, 1)
232- ##axChirp.plot(f, chirp, color=' black' )
233- ##axChirp.set_title(' Chirp' )
234- ##axChirp.set_xlabel(' Frequency (Hz)' )
235- ##axChirp.set_ylabel(' Signal' )
232+ ##axChirp.plot(f, chirp, color=" black" )
233+ ##axChirp.set_title(" Chirp" )
234+ ##axChirp.set_xlabel(" Frequency (Hz)" )
235+ ##axChirp.set_ylabel(" Signal" )
236236 ##axChirp.autoscale(tight=True)
237237
238238 #axChirpTwiny = axChirp.twiny()
239239 #axChirpTwiny.plot(t, chirp, alpha=0.0)
240- #axChirpTwiny.set_xlabel(' Time (s)' )
240+ #axChirpTwiny.set_xlabel(" Time (s)" )
241241
242242 fDown = downsample (f , factor )
243243 chirpDown = downsample (chirp , factor )
244244
245245 axDown = fig .add_subplot (2 , 2 , 1 )
246- axDown .plot (f , chirp , color = ' lightgrey' , linewidth = 2 )
247- axDown .plot (fDown , chirpDown , color = ' red' )
246+ axDown .plot (f , chirp , color = " lightgrey" , linewidth = 2 )
247+ axDown .plot (fDown , chirpDown , color = " red" )
248248 axDown .vlines (nyquist / factor , - 1.0 , 1.0 , linewidth = 2 ,
249- linestyle = '--' , color = ' green' , label = ' New Nyquist' )
250- axDown .set_title (' Downsample factor %d' % factor )
251- axDown .set_xlabel (' Frequency (Hz)' )
252- axDown .set_ylabel (' Signal' )
249+ linestyle = "--" , color = " green" , label = " New Nyquist" )
250+ axDown .set_title (" Downsample factor %d" % factor )
251+ axDown .set_xlabel (" Frequency (Hz)" )
252+ axDown .set_ylabel (" Signal" )
253253 axDown .autoscale (tight = True )
254254
255255 chirpDeci = decimate (chirp , factor )
256256 axDeci = fig .add_subplot (2 , 2 , 3 )
257- axDeci .plot (f , chirp , color = ' lightgrey' , linewidth = 2 )
258- axDeci .plot (fDown , chirpDeci , color = ' red' )
257+ axDeci .plot (f , chirp , color = " lightgrey" , linewidth = 2 )
258+ axDeci .plot (fDown , chirpDeci , color = " red" )
259259 axDeci .vlines (nyquist / factor , - 1.0 , 1.0 , linewidth = 2 ,
260- linestyle = '--' , color = ' green' , label = ' New Nyquist' )
261- axDeci .set_title (' Decimation factor %d' % factor )
262- axDeci .set_xlabel (' Frequency (Hz)' )
263- axDeci .set_ylabel (' Signal' )
260+ linestyle = "--" , color = " green" , label = " New Nyquist" )
261+ axDeci .set_title (" Decimation factor %d" % factor )
262+ axDeci .set_xlabel (" Frequency (Hz)" )
263+ axDeci .set_ylabel (" Signal" )
264264 axDeci .autoscale (tight = True )
265265
266266 fInterp = np .linspace (0.0 , nyquist , 2.0 * sampRate * factor , endpoint = False )
267267 chirpInterp = interpolate (chirp , factor )
268268
269269 axInterp = fig .add_subplot (2 , 2 , 2 )
270- axInterp .plot (f , chirp , color = ' lightgrey' , linewidth = 2 )
271- axInterp .plot (fInterp , chirpInterp , color = ' red' )
270+ axInterp .plot (f , chirp , color = " lightgrey" , linewidth = 2 )
271+ axInterp .plot (fInterp , chirpInterp , color = " red" )
272272 #axInterp.vlines(nyquist*factor, -1.0, 1.0, linewidth=2,
273- # linestyle='--' , color=' green' , label=' New Nyquist' )
274- axInterp .set_title (' Interpolation factor %d' % factor )
275- axInterp .set_xlabel (' Frequency (Hz)' )
276- axInterp .set_ylabel (' Signal' )
273+ # linestyle="--" , color=" green" , label=" New Nyquist" )
274+ axInterp .set_title (" Interpolation factor %d" % factor )
275+ axInterp .set_xlabel (" Frequency (Hz)" )
276+ axInterp .set_ylabel (" Signal" )
277277 axInterp .autoscale (tight = True )
278278
279279 fResamp = np .linspace (0.0 , nyquist , 2.0 * sampRate * (2.0 / factor ), endpoint = False )
280280 chirpResamp = resample (chirp , factorUp = 2 , factorDown = factor )
281281
282282 axResamp = fig .add_subplot (2 , 2 , 4 )
283- axResamp .plot (f , chirp , color = ' lightgrey' , linewidth = 2 )
284- axResamp .plot (fResamp , chirpResamp , color = ' red' )
283+ axResamp .plot (f , chirp , color = " lightgrey" , linewidth = 2 )
284+ axResamp .plot (fResamp , chirpResamp , color = " red" )
285285 axResamp .vlines ((2.0 / factor )* nyquist , - 1.0 , 1.0 , linewidth = 2 ,
286- linestyle = '--' , color = ' green' , label = ' New Nyquist' )
287- axResamp .set_title (' Resample factor 2/%d' % factor )
288- axResamp .set_xlabel (' Frequency (Hz)' )
289- axResamp .set_ylabel (' Signal' )
286+ linestyle = "--" , color = " green" , label = " New Nyquist" )
287+ axResamp .set_title (" Resample factor 2/%d" % factor )
288+ axResamp .set_xlabel (" Frequency (Hz)" )
289+ axResamp .set_ylabel (" Signal" )
290290 axResamp .autoscale (tight = True )
291291
292292 fig .tight_layout ()
293293
294- if __name__ == ' __main__' :
294+ if __name__ == " __main__" :
295295 demoInterpolate ()
296296 demoResample ()
297297 plt .show ()
0 commit comments