5
5
# Rewrote much of chirp()
9
8
from numpy import asarray, zeros, place, nan, mod, pi, extract, log, sqrt, \
10
exp, cos, sin, polyval, polyint, size, log10
9
exp, cos, sin, polyval, polyint
12
def sawtooth(t,width=1):
11
def sawtooth(t, width=1):
14
13
Return a periodic sawtooth waveform.
121
120
place(y,mask3,-1)
124
def gausspulse(t,fc=1000,bw=0.5,bwr=-6,tpr=-60,retquad=0,retenv=0):
123
def gausspulse(t, fc=1000, bw=0.5, bwr=-6, tpr=-60, retquad=False, retenv=False):
126
Return a gaussian modulated sinusoid: exp(-a t^2) exp(1j*2*pi*fc).
125
Return a gaussian modulated sinusoid: exp(-a t^2) exp(1j*2*pi*fc*t).
128
If `retquad` is non-zero, then return the real and imaginary parts
129
(in-phase and quadrature)
130
If `retenv` is non-zero, then return the envelope (unmodulated signal).
127
If `retquad` is True, then return the real and imaginary parts
128
(in-phase and quadrature).
129
If `retenv` is True, then return the envelope (unmodulated signal).
131
130
Otherwise, return the real part of the modulated sinusoid.
134
t : ndarray, or the string 'cutoff'
137
136
fc : int, optional
138
Center frequency (Hz).
137
Center frequency (Hz). Default is 1000.
139
138
bw : float, optional
140
139
Fractional bandwidth in frequency domain of pulse (Hz).
141
141
bwr: float, optional
142
142
Reference level at which fractional bandwidth is calculated (dB).
143
144
tpr : float, optional
144
145
If `t` is 'cutoff', then the function returns the cutoff
145
146
time for when the pulse amplitude falls below `tpr` (in dB).
146
retquad : int, optional
147
Return the quadrature (imaginary) as well as the real part
149
retenv : int, optional
150
Return the envelope of the signal.
148
retquad : bool, optional
149
If True, return the quadrature (imaginary) as well as the real part
150
of the signal. Default is False.
151
retenv : bool, optional
152
If True, return the envelope of the signal. Default is False.
154
raise ValueError, "Center frequency (fc=%.2f) must be >=0." % fc
156
raise ValueError("Center frequency (fc=%.2f) must be >=0." % fc)
156
raise ValueError, "Fractional bandwidth (bw=%.2f) must be > 0." % bw
158
raise ValueError("Fractional bandwidth (bw=%.2f) must be > 0." % bw)
158
raise ValueError, "Reference level for bandwidth (bwr=%.2f) must " \
160
raise ValueError("Reference level for bandwidth (bwr=%.2f) must "
161
163
# exp(-a t^2) <-> sqrt(pi/a) exp(-pi^2/a * f^2) = g(f)
187
189
return yI, yQ, yenv
190
# This is chirp from scipy 0.7:
192
def old_chirp(t, f0=0, t1=1, f1=100, method='linear', phi=0, qshape=None):
193
"""Frequency-swept cosine generator.
198
Times at which to evaluate the waveform.
199
f0 : float or ndarray, optional
200
Frequency (in Hz) of the waveform at time 0. If `f0` is an
201
ndarray, it specifies the frequency change as a polynomial in
202
`t` (see Notes below).
204
Time at which `f1` is specified.
206
Frequency (in Hz) of the waveform at time `t1`.
207
method : {'linear', 'quadratic', 'logarithmic'}, optional
208
Kind of frequency sweep.
210
Phase offset, in degrees.
211
qshape : {'convex', 'concave'}
212
If method is 'quadratic', `qshape` specifies its shape.
216
If `f0` is an array, it forms the coefficients of a polynomial in
217
`t` (see `numpy.polval`). The polynomial determines the waveform
218
frequency change in time. In this case, the values of `f1`, `t1`,
219
`method`, and `qshape` are ignored.
221
This function is deprecated. It will be removed in SciPy version 0.9.0.
222
It exists so that during in version 0.8.0, the new chirp function can
223
call this function to preserve the old behavior of the quadratic chirp.
225
warnings.warn("The function old_chirp is deprecated, and will be removed in "
226
"SciPy 0.9", DeprecationWarning)
227
# Convert to radians.
230
# We were given a polynomial.
231
return cos(2*pi*polyval(polyint(f0),t)+phi)
232
if method in ['linear','lin','li']:
234
phase_angle = 2*pi * (f0*t + 0.5*beta*t*t)
235
elif method in ['quadratic','quad','q']:
236
if qshape == 'concave':
240
elif qshape == 'convex':
245
raise ValueError("qshape must be either 'concave' or 'convex' but "
246
"a value of %r was given." % qshape)
248
phase_angle = 2*pi * (f0*t + beta*t*t*t/3)
249
elif method in ['logarithmic','log','lo']:
252
"For a logarithmic sweep, f1=%f must be larger than f0=%f."
254
beta = log10(f1-f0)/t1
255
phase_angle = 2*pi * (f0*t + (pow(10,beta*t)-1)/(beta*log(10)))
257
raise ValueError("method must be 'linear', 'quadratic', or "
258
"'logarithmic' but a value of %r was given." % method)
260
return cos(phase_angle + phi)
263
def chirp(t, f0, t1, f1, method='linear', phi=0, vertex_zero=True,
192
def chirp(t, f0, t1, f1, method='linear', phi=0, vertex_zero=True):
265
193
"""Frequency-swept cosine generator.
267
195
In the following, 'Hz' should be interpreted as 'cycles per time unit';
351
275
f1 must be positive, and f0 must be greater than f1.
355
# Preserve old behavior for one release cycle; this can be
356
# removed in scipy 0.9.
357
warnings.warn("Passing a list of polynomial coefficients in f0 to the "
358
"function chirp is deprecated. Use scipy.signal.sweep_poly.",
360
return old_chirp(t, f0, t1, f1, method, phi, qshape)
362
if method in ['quadratic', 'quad', 'q'] and qshape is not None:
363
# We must use the old version of the quadratic chirp. Fortunately,
364
# the old API *required* that qshape be either 'convex' or 'concave'
365
# if the quadratic method was selected--`None` would raise an error.
366
# So if the code reaches this point, we should use the old version.
367
warnings.warn("The qshape keyword argument is deprecated. "
368
"Use vertex_zero.", DeprecationWarning)
369
waveform = old_chirp(t, f0, t1, f1, method, phi, qshape)
372
279
# 'phase' is computed in _chirp_phase, to make testing easier.
373
280
phase = _chirp_phase(t, f0, t1, f1, method, vertex_zero)