Why does changing the frequency of a single component change total sum of amplitudes in my FFT? I have the following code which generates a single simple sine wave with amplitude $1$ and then calculates the Fourier transform, normalises it, and finally takes the sum of all the components. 

However I've observed something strange, if I generate a $10\textrm{ Hz}$ wave and a $100\textrm{ Hz}$ wave. The amplitudes are pretty damn similar as expected and they are  0.9999483519908307 and 0.9997854546246567 respectively. 

However the total sum of all the components after normalisation are 1.01723486798 and 1.17263231047 respectively, which is approximately a $15\%$ difference! Why is this occurring? 

Below are the plots of the spectrums and the python code below.





mport matplotlib.pyplot as plt
import numpy as np
from decimal import Decimal

#number of samples
iNumSamples=10000

#period of samples (i.e. sampling at 10Khz)
Ts=1/iNumSamples

#time axis used to sample 10,000 times for a second
t = np.linspace(0, 1, iNumSamples)

#10Hz Signal
signal1=np.sin(t*20*np.pi)

#100Hz Signal
signal2=np.sin(t*200*np.pi)


#creates a new figure object 
freqFig=plt.figure(2)
#change title
freqFig.canvas.set_window_title('Frequency domain') 

#fast fourier transform of 10Hz signal
absoluteValues1=abs(np.fft.rfft(signal1)) 

#fast fourier transform of 100Hz
absoluteValues2=abs(np.fft.rfft(signal2)) 

#find the frequencies of the rtansform
frequencies=np.fft.rfftfreq(iNumSamples, d=Ts)


##Normalises (rescales) the fft in a sensible way so that the corresponding freq component of a sine wave is 1 if the sine wave amplitude is 1
##non zero freq amplitudes (even when using rfft) are halfed as there are negative and positive components, hence first multiple by 2

#first create empty array of correct size
normalisedValues1=np.zeros(absoluteValues1.size, dtype=Decimal)
normalisedValues2=np.zeros(absoluteValues2.size, dtype=Decimal)

#normalise 0 component
normalisedValues1[0]=absoluteValues1[0]/iNumSamples 
normalisedValues2[0]=absoluteValues2[0]/iNumSamples 
#normalise non zero components
normalisedValues1[1:]=absoluteValues1[1:]*(2/iNumSamples)
normalisedValues2[1:]=absoluteValues2[1:]*(2/iNumSamples)

print("peak value signal 1:")
print(np.amax(normalisedValues1))
print("peak value signal 2:")
print(np.amax(normalisedValues2))

print("total sum of all componenets in spectrum of 10 Hz")
print(np.sum(normalisedValues1))

print("total sum of all componenets in spectrum of 100 Hz")
print(np.sum(normalisedValues2))

#creates a new figure object 
freqFig=plt.figure(1)
#change title
freqFig.canvas.set_window_title('Frequency domain') 
plt.plot(frequencies,normalisedValues1)

#creates a new figure object 
freqFig=plt.figure(2)
#change title
freqFig.canvas.set_window_title('Frequency domain') 
plt.plot(frequencies,normalisedValues2)

plt.show()
That's a subtle sampling issues and you will get your desired result by replacing this line: 

t = np.linspace(0, 1, iNumSamples)


with the following:

t = np.linspace(0, 1-Ts, iNumSamples)


That being said, it's really a virtual sucess and you would never rely on such perfectly matching numbers in practice...