Amplitude of signal and PSD peak height So, suppose you have a superposition of cosines of the same magnitude:
$\sum_{i}\cos[\omega_i t]$

When you take the Fourier transform, theoretically you'd expect to find $\delta$-like peaks of the same magnitude. But in practice, what I find is this:



How would you explain this variation in the magnitude? Given such variation, would it be possible to recover the amplitudes of each frequency component in a superposition $\sum_{i}A_i\cos[\omega_i t]$

EDIT: I suspect it has to do with the relationship between the sampling frequency and the frequencies of the components. The fact that the theoretical $\delta$ response exists is a consequence of the orthogonality of the FT kernel. So, I suppose that in the discrete case, the frequencies of the DFT lines don't exactly "match" the sampled frequencies of the signal. I don't know how to articulate this properly or if it's even correct though.

For reference, here's the MATLAB code I used to generate this

Fs = 100;
Sp = 1/Fs;
L = 2000;
t = (0:L-1)*Sp;   

y2 = cos(5.*t)+cos(25.*t)+cos(10.*t)+cos(1.*t)+cos(100.*t)+cos(200.*t)+cos(300.*t);

Y = fft(y2);
P2 = abs(Y/L).^2;
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;    

figure
plot(f,P1,'-k','Linewidth',1);
This question is well-addressed in other posts; I would refer you elsewhere, but since you probably want the answer, here it is. 

A couple of notes:


There are three knobs you need to play around with to get the right FFT. The first knob is sampling enough (so the 1/700 parameter); in particular, if you don't do it at least twice the maximum frequency, you run into problems of aliasing (by far the best and easiest to understand resource is here: https://blogs.mathworks.com/steve/category/fourier-transforms/). The second knob is that you need to sample long enough (the 50 number below) - you could do 1/1000 sampling but if you do up to 10 - 1/1000 and do the FFT, you will notice the amplitude of the smallest frequency (1/(2 * pi)) is always a little too high. 
The linked blog explains VERY well why this third knob is important, which is the zero-padding, which allows you to get a better DFT with the same data. 
Finally, yes I am plotting the two-sided FFT, so usually people will take half the amplitude I am using: $$\text{plot}(\text{fshift},\text{abs}(\text{yshift})/\text{length}(x))$$ instead of $$\text{plot}(\text{fshift},2 * \text{abs}(\text{yshift})/\text{length}(x))$$. 


But this recreates the right amplitudes. The idea is you need to normalize by the number of data points you are using (I didn't come up with this code myself; I stole it from here: https://www.mathworks.com/matlabcentral/answers/162846-amplitude-of-signal-after-fft-operation).

Without further ado, here's the code you want:

\begin{equation}
t = 0:1/700:50-1/700; \\
x = cos(5.*t)+cos(25.*t)+cos(10.*t)+cos(1.*t)+cos(100.*t)+cos(200.*t)+cos(300.*t); \\
y = \text{fft}(x, 2^{\text{nextpow2}(\text{length}(t))+2)}); \\
n = \text{length}(y);    \\                     
\text{fshift} = (-n/2:n/2-1)*(700/n); \\
\text{yshift} = \text{fftshift}(y); \\
\text{figure}; \text{plot}(\text{fshift},2 * \text{abs}(\text{yshift})/\text{length}(x)) \\
\end{equation}