# Basic question about chirp signal

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.show()
plt.plot(fs * np.linspace(0, 0.5, 257),mag)
plt.show()


And the phase plot is: Magnitude plot is: 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?

• 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? – endolith Feb 24 '15 at 1:23
• it should look a little chirpy in the frequency domain. – robert bristow-johnson Feb 24 '15 at 5:00
• This might help, although the code is written for matlab dsp.stackexchange.com/questions/19191/… – Rhei Feb 24 '15 at 6:24

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.