Scipy.signal noise with rfft compared to fft I'm trying to get the fourier transform of a signal with real values, however the results I get with rfft are noiser than those with fft.

I wrote the following code:

import numpy as np
from scipy.fftpack import rfft, fft
import matplotlib.pyplot as plt
# Number of sample points

N = 600
# sample spacing
T = 1.0 / 800.0
x = np.linspace(0.0, N*T, N)
f1 = 50
f2 = 80
y = np.sin( f1* 2.0*np.pi*x) + 0.5*np.sin(f2 * 2.0*np.pi*x)
yf = fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N/2)
plt.plot(xf, 2.0/N * np.abs(yf)[0:N/2])
#plt.savefig('sin.png')
plt.show()


yf2 = rfft(y)
xf2 = np.linspace(0.0, 1.0/(2.0*T), N)
plt.plot(xf2, 2.0/N * np.abs(yf2))
plt.savefig('sin2.png')
plt.show()



and I get the following results:

 



I thought that for real values I would get the same result with fft and rfft, do you know why there are some differences ?
The DFT of a real sequence is complex-valued. The array output by scipy.fftpack.rfft consists of the real part of the 0th entry, followed by the imaginary part of the 0th entry, followed by the real part of thre 1st entry, followed by the imaginary part of the 1st entry,...


Convert the output of rfft into the appropriate complex array and plot the absolute values of that array, and you will have what you seek:


yf3 = yf2[0:-2:2] + 1j*yf2[1:-1:2];
plt.plot(np.abs(yf3));
plt.show()