# [Scipy-tickets] [SciPy] #547: chirp - logarithmic cosine sweep - bad initial value and incorrect waveform

SciPy scipy-tickets@scipy....
Tue Nov 27 16:26:29 CST 2007

```#547: chirp - logarithmic cosine sweep  - bad initial value and incorrect
waveform
--------------------------+-------------------------------------------------
Reporter:  knorthover    |       Owner:  somebody
Type:  defect        |      Status:  new
Priority:  normal        |   Milestone:  0.7
Component:  scipy.signal  |     Version:
Severity:  major         |    Keywords:
--------------------------+-------------------------------------------------
In Lib/signal/waveforms.py, in chirp():

The initial value for the cosine logarithmic sweep for t[0] = 0 is not
1.0.
This is easily seen by evaluating the phase_angle expression on line 180
for t=0:

{{{
phase_angle = 2*pi * (f0*t + pow(10,beta*t)/(beta*log(10)))
}}}

pow(10, beta*t) = 1.0 when t = zero so the phase angle cannot be zero.

I think line 180 is intended to read:

{{{
phase_angle = 2*pi * (f0 + pow(10,beta*t)/(beta*log(10))) * t
}}}

However I also think the setup of beta is incorrect.  For a logarithmic
sweep the coefficient in the exponent of the frequency term should be
determined by the ratio of the frequencies, not their difference.

In the notation for chirp line 179-180 should read:

{{{
beta = log( f1 / f0) / t1
phase_angle = 2*pi * (f0 * exp(beta * t)) * t
}}}

(or use log10 and pow, but this is simpler)

here is a simple generator for a logarithmic sweep:

{{{
def log_sine(fs, fe, rate, sweeplen):
"""Generate a logarithmically swept sine wave.
rate - sample rate in samples / second
sweeplen - length of sweep in seconds.
"""
t = -1
tmax = float(rate) * sweeplen
k = log(float(fe) / fs) / tmax
while t < tmax:
t = t + 1
f = fs * exp(k * t)
yield sin(2 * pi * f * t / rate)
}}}

Kevin

--
Ticket URL: <http://scipy.org/scipy/scipy/ticket/547>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.
```