Suppose I generate chirp signal with the following python code:

 t = np.linspace(0, 10, 512)
 f0 = 2
 f1 = 5
 fs = 2*f1
 w = chirp(t, f0=f0, f1=f1, t1=10, method='linear')
 result  = rfft(w)
 phase = np.zeros(257)
 mag = np.zeros(257)
 for binnum in range(len(result)):
   mag[binnum] = abs(result[binnum])
   phase[binnum] = np.arctan2(result[binnum].imag, result[binnum].real)
 plt.plot(fs * np.linspace(0, 0.5, 257),np.unwrap(phase))
 plt.plot(fs * np.linspace(0, 0.5, 257),mag)

And the phase plot is:enter image description here

Magnitude plot is: enter image description here

But it is very different from what is described here.

Well, looking at the phase graph I can see parabola from 0 to 0.8. The magnitude is definitly not a constant.

What I'm doing wrong or misunderstood?

Thanks in advance.

  • 1
    $\begingroup$ 1. Sampling frequency is not 2*f1, even if you say it is. It's actually 512/10, determined by the linspace parameters. 2. phase = np.angle(result) and mag = np.abs(result) are easier than your for loop. 3. What did you expect the spectrum of a chirp to look like? $\endgroup$
    – endolith
    Feb 24, 2015 at 1:23
  • 1
    $\begingroup$ it should look a little chirpy in the frequency domain. $\endgroup$ Feb 24, 2015 at 5:00
  • 1
    $\begingroup$ This might help, although the code is written for matlab dsp.stackexchange.com/questions/19191/… $\endgroup$
    – Rhei
    Feb 24, 2015 at 6:24

1 Answer 1


I dont understand the definition of the chirp in the link you provided (perhaps chirp in frequency domain?), but maybe the following explanation could help.

In general, a linear chirp with a varying frequency given by $$f(t) = \alpha + \beta t$$ is defined by $$ x_1(t) = e^{2\pi j (\alpha t + 0.5\beta t^2)} $$

In that case, the phase of $x_1(t)$, the signal in time-domain, is indeed parabolic and the magnitude is constant and equals to 1.
Now, I am not familiar with python, but the chirp function in matlab produces a real signal rather than complex one. That is $$ x_2(t) = \sin(2\pi (\alpha t + 0.5\beta t^2)) $$ In that case, you will get different results. However, you can use the Hilbert transform (I guess this is in python) which, given $x_1(t)$ will produce $x_2(t)$ using fft.

  • $\begingroup$ Thank you very much! I was confused by the frequency-domain response description... It seems that it was time-domain description. $\endgroup$
    – Sharov
    Feb 24, 2015 at 22:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.